Skip to content

Commit 6ffa015

Browse files
committed
Add e2e tests for xRoute/xPolicy status cleanup
Signed-off-by: y-rabie <[email protected]>
1 parent 18d05c8 commit 6ffa015

15 files changed

+549
-42
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: gateway.envoyproxy.io/v1alpha1
2+
kind: BackendTrafficPolicy
3+
metadata:
4+
name: backendtrafficpolicy-multiple-ancestors-same-gwc
5+
namespace: gateway-conformance-infra
6+
spec:
7+
targetRefs:
8+
- group: gateway.networking.k8s.io
9+
kind: Gateway
10+
name: same-namespace
11+
# This gateway (and its gatewayclass) is created through `status-cleanup-gateway-different-gwc.yaml` manifest.
12+
- group: gateway.networking.k8s.io
13+
kind: Gateway
14+
name: gateway-2
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: gateway.envoyproxy.io/v1alpha1
2+
kind: BackendTrafficPolicy
3+
metadata:
4+
name: backendtrafficpolicy-multiple-ancestors-same-gwc
5+
namespace: gateway-conformance-infra
6+
spec:
7+
targetRefs:
8+
- group: gateway.networking.k8s.io
9+
kind: Gateway
10+
name: same-namespace
11+
- group: gateway.networking.k8s.io
12+
kind: Gateway
13+
name: all-namespaces
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: gateway.envoyproxy.io/v1alpha1
2+
kind: BackendTrafficPolicy
3+
metadata:
4+
name: backendtrafficpolicy-multiple-ancestors-same-gwc
5+
namespace: gateway-conformance-infra
6+
spec:
7+
targetRefs:
8+
- group: gateway.networking.k8s.io
9+
kind: Gateway
10+
name: other-controller-ancestor
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: gateway.envoyproxy.io/v1alpha1
2+
kind: BackendTrafficPolicy
3+
metadata:
4+
name: backendtrafficpolicy-multiple-ancestors-same-gwc
5+
namespace: gateway-conformance-infra
6+
spec:
7+
targetRefs:
8+
- group: gateway.networking.k8s.io
9+
kind: Gateway
10+
name: same-namespace
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: gateway.networking.k8s.io/v1beta1
2+
kind: Gateway
3+
metadata:
4+
name: gateway-1
5+
namespace: gateway-conformance-infra
6+
spec:
7+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
8+
listeners:
9+
- name: foo
10+
protocol: TCP
11+
port: 8080
12+
allowedRoutes:
13+
kinds:
14+
- kind: TCPRoute
15+
---
16+
apiVersion: gateway.networking.k8s.io/v1alpha2
17+
kind: TCPRoute
18+
metadata:
19+
name: tcp-route-status-cleanup
20+
namespace: gateway-conformance-infra
21+
spec:
22+
parentRefs:
23+
- name: gateway-1
24+
sectionName: foo
25+
# This gateway (and its gatewayclass) is created through `status-cleanup-gateway-different-gwc.yaml` manifest.
26+
- name: gateway-2
27+
sectionName: foo
28+
rules:
29+
- backendRefs:
30+
- name: infra-backend-v1
31+
port: 8080
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apiVersion: gateway.networking.k8s.io/v1beta1
2+
kind: Gateway
3+
metadata:
4+
name: gateway-1
5+
namespace: gateway-conformance-infra
6+
spec:
7+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
8+
listeners:
9+
- name: foo
10+
protocol: TCP
11+
port: 8080
12+
allowedRoutes:
13+
kinds:
14+
- kind: TCPRoute
15+
---
16+
apiVersion: gateway.networking.k8s.io/v1beta1
17+
kind: Gateway
18+
metadata:
19+
name: gateway-2
20+
namespace: gateway-conformance-infra
21+
spec:
22+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
23+
listeners:
24+
- name: foo
25+
protocol: TCP
26+
port: 8080
27+
allowedRoutes:
28+
kinds:
29+
- kind: TCPRoute
30+
---
31+
apiVersion: gateway.networking.k8s.io/v1alpha2
32+
kind: TCPRoute
33+
metadata:
34+
name: tcp-route-status-cleanup
35+
namespace: gateway-conformance-infra
36+
spec:
37+
parentRefs:
38+
- name: gateway-1
39+
sectionName: foo
40+
- name: gateway-2
41+
sectionName: foo
42+
rules:
43+
- backendRefs:
44+
- name: infra-backend-v1
45+
port: 8080
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: gateway.networking.k8s.io/v1alpha2
2+
kind: TCPRoute
3+
metadata:
4+
name: tcp-route-status-cleanup
5+
namespace: gateway-conformance-infra
6+
spec:
7+
parentRefs:
8+
- name: gateway-1
9+
sectionName: foo
10+
rules:
11+
- backendRefs:
12+
- name: infra-backend-v1
13+
port: 8080
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: GatewayClass
3+
metadata:
4+
name: status-cleanup
5+
spec:
6+
controllerName: gateway.envoyproxy.io/gatewayclass-controller
7+
---
8+
apiVersion: gateway.networking.k8s.io/v1beta1
9+
kind: Gateway
10+
metadata:
11+
name: gateway-2
12+
namespace: gateway-conformance-infra
13+
spec:
14+
gatewayClassName: status-cleanup
15+
listeners:
16+
- name: foo
17+
protocol: TCP
18+
port: 8080
19+
allowedRoutes:
20+
kinds:
21+
- kind: TCPRoute
22+
infrastructure:
23+
parametersRef:
24+
group: gateway.envoyproxy.io
25+
kind: EnvoyProxy
26+
name: status-cleanup
27+
---
28+
apiVersion: gateway.envoyproxy.io/v1alpha1
29+
kind: EnvoyProxy
30+
metadata:
31+
name: status-cleanup
32+
namespace: gateway-conformance-infra
33+
spec:
34+
ipFamily: IPv4
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Copyright Envoy Gateway Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
// The full text of the Apache license is available in the LICENSE file at
4+
// the root of the repo.
5+
6+
//go:build e2e
7+
8+
package tests
9+
10+
import (
11+
"context"
12+
"testing"
13+
"time"
14+
15+
"github.com/stretchr/testify/require"
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
"k8s.io/apimachinery/pkg/types"
18+
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
19+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
20+
21+
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
22+
"github.com/envoyproxy/gateway/internal/gatewayapi"
23+
"github.com/envoyproxy/gateway/internal/gatewayapi/resource"
24+
)
25+
26+
func init() {
27+
ConformanceTests = append(ConformanceTests, PolicyStatusCleanupSameGatewayClass, PolicyStatusCleanupMultipleGatewayClasses)
28+
}
29+
30+
var PolicyStatusCleanupSameGatewayClass = suite.ConformanceTest{
31+
ShortName: "PolicyStatusCleanupSameGatewayClass",
32+
Description: "Testing Policy Status Cleanup With Ancestors of The Same GatewayClass",
33+
Manifests: []string{"testdata/policy-status-cleanup-multiple-ancestors-same-gwc.yaml"},
34+
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
35+
t.Run("PolicyStatusCleanup", func(t *testing.T) {
36+
ns := "gateway-conformance-infra"
37+
gw1NN, gw2NN := types.NamespacedName{Name: "same-namespace", Namespace: ns}, types.NamespacedName{Name: "all-namespaces", Namespace: ns}
38+
39+
policyNamespacedName := types.NamespacedName{Name: "backendtrafficpolicy-multiple-ancestors-same-gwc", Namespace: ns}
40+
41+
// Check the policy has two ancestors in its status.
42+
BackendTrafficPolicyMustBeAcceptedByAllAncestors(t,
43+
suite.Client,
44+
policyNamespacedName,
45+
suite.ControllerName,
46+
gwapiv1.ParentReference{
47+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
48+
Kind: gatewayapi.KindPtr(resource.KindGateway),
49+
Namespace: gatewayapi.NamespacePtr(gw1NN.Namespace),
50+
Name: gwapiv1.ObjectName(gw1NN.Name),
51+
},
52+
gwapiv1.ParentReference{
53+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
54+
Kind: gatewayapi.KindPtr(resource.KindGateway),
55+
Namespace: gatewayapi.NamespacePtr(gw2NN.Namespace),
56+
Name: gwapiv1.ObjectName(gw2NN.Name),
57+
},
58+
)
59+
60+
// Change the policy to have a single ancestor, and check its status.
61+
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/policy-status-cleanup-single-ancestor.yaml", false)
62+
BackendTrafficPolicyMustBeAcceptedByAllAncestors(t,
63+
suite.Client,
64+
policyNamespacedName,
65+
suite.ControllerName,
66+
gwapiv1.ParentReference{
67+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
68+
Kind: gatewayapi.KindPtr(resource.KindGateway),
69+
Namespace: gatewayapi.NamespacePtr(gw1NN.Namespace),
70+
Name: gwapiv1.ObjectName(gw1NN.Name),
71+
},
72+
)
73+
74+
// Update the policy status to include a status ancestor of another controller.
75+
policy := &egv1a1.BackendTrafficPolicy{}
76+
err := suite.Client.Get(context.Background(), policyNamespacedName, policy)
77+
require.NoErrorf(t, err, "error getting BackendTrafficPolicy %s", policyNamespacedName.String())
78+
otherControllerAncestor := gwapiv1.PolicyAncestorStatus{
79+
AncestorRef: gwapiv1.ParentReference{
80+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
81+
Kind: gatewayapi.KindPtr(resource.KindGateway),
82+
Name: "other-controller-ancestor",
83+
Namespace: gatewayapi.NamespacePtr(policy.Namespace),
84+
},
85+
ControllerName: "gateway.envoyproxy.io/other-gatewayclass-controller",
86+
Conditions: []metav1.Condition{
87+
{
88+
Type: string(gwapiv1.PolicyConditionAccepted),
89+
Status: metav1.ConditionTrue,
90+
LastTransitionTime: metav1.NewTime(time.Now()),
91+
Reason: string(gwapiv1.PolicyConditionAccepted),
92+
},
93+
},
94+
}
95+
policy.Status.Ancestors = append(policy.Status.Ancestors, otherControllerAncestor)
96+
err = suite.Client.Status().Update(context.Background(), policy)
97+
require.NoErrorf(t, err, "error updating BackendTrafficPolicy status %s", policyNamespacedName.String())
98+
99+
// Change the policy spec to have a corresponding ancestor and trigger reconciliation.
100+
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/policy-status-cleanup-no-ancestor.yaml", false)
101+
102+
// Check its status to only have the ancestor from the other controller.
103+
BackendTrafficPolicyMustBeAcceptedByAllAncestors(t,
104+
suite.Client,
105+
policyNamespacedName,
106+
"gateway.envoyproxy.io/other-gatewayclass-controller",
107+
[]gwapiv1.ParentReference{
108+
{
109+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
110+
Kind: gatewayapi.KindPtr(resource.KindGateway),
111+
Name: "other-controller-ancestor",
112+
Namespace: gatewayapi.NamespacePtr(policy.Namespace),
113+
},
114+
}...,
115+
)
116+
})
117+
},
118+
}
119+
120+
var PolicyStatusCleanupMultipleGatewayClasses = suite.ConformanceTest{
121+
ShortName: "PolicyStatusCleanupMultipleGatewayClasses",
122+
Description: "Testing Policy Status Cleanup With Ancestors of Multiple GatewayClasses",
123+
Manifests: []string{"testdata/policy-status-cleanup-multiple-ancestors-multiple-gwcs.yaml"},
124+
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
125+
t.Run("PolicyStatusCleanup", func(t *testing.T) {
126+
// Create the second gateway of a different gatewayclass, which the backendtrafficpolicy is already attached to.
127+
prevGwc := suite.Applier.GatewayClass
128+
suite.Applier.GatewayClass = "status-cleanup"
129+
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/status-cleanup-gateway-different-gwc.yaml", true)
130+
suite.Applier.GatewayClass = prevGwc
131+
132+
ns := "gateway-conformance-infra"
133+
gw1NN, gw2NN := types.NamespacedName{Name: "same-namespace", Namespace: ns}, types.NamespacedName{Name: "gateway-2", Namespace: ns}
134+
135+
// Check the policy has two ancestors in its status.
136+
BackendTrafficPolicyMustBeAcceptedByAllAncestors(t,
137+
suite.Client,
138+
types.NamespacedName{Name: "backendtrafficpolicy-multiple-ancestors-same-gwc", Namespace: ns},
139+
suite.ControllerName,
140+
gwapiv1.ParentReference{
141+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
142+
Kind: gatewayapi.KindPtr(resource.KindGateway),
143+
Namespace: gatewayapi.NamespacePtr(gw1NN.Namespace),
144+
Name: gwapiv1.ObjectName(gw1NN.Name),
145+
},
146+
gwapiv1.ParentReference{
147+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
148+
Kind: gatewayapi.KindPtr(resource.KindGateway),
149+
Namespace: gatewayapi.NamespacePtr(gw2NN.Namespace),
150+
Name: gwapiv1.ObjectName(gw2NN.Name),
151+
},
152+
)
153+
154+
// Change the policy to have a single ancestor, and check its status.
155+
suite.Applier.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/policy-status-cleanup-single-ancestor.yaml", false)
156+
BackendTrafficPolicyMustBeAcceptedByAllAncestors(t,
157+
suite.Client,
158+
types.NamespacedName{Name: "backendtrafficpolicy-multiple-ancestors-same-gwc", Namespace: ns},
159+
suite.ControllerName,
160+
gwapiv1.ParentReference{
161+
Group: gatewayapi.GroupPtr(gwapiv1.GroupName),
162+
Kind: gatewayapi.KindPtr(resource.KindGateway),
163+
Namespace: gatewayapi.NamespacePtr(gw1NN.Namespace),
164+
Name: gwapiv1.ObjectName(gw1NN.Name),
165+
},
166+
)
167+
})
168+
},
169+
}

0 commit comments

Comments
 (0)