Skip to content

Commit 28516d7

Browse files
committed
Fix MultiextensionManagers tests
Signed-off-by: Marc Navarro Sonnenfeld <marcnavarro@tetrate.io>
1 parent bf3bea0 commit 28516d7

4 files changed

Lines changed: 79 additions & 7 deletions

File tree

examples/extension-server/charts/extension-server/crds/generated/example.extensions.io_listenercontextexamples.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.19.0
6+
controller-gen.kubebuilder.io/version: v0.20.1
77
name: listenercontextexamples.example.extensions.io
88
spec:
99
group: example.extensions.io

examples/simple-extension-server/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ func (s *Server) PostVirtualHostModify(_ context.Context, req *pb.PostVirtualHos
152152

153153
s.log.Info("PostVirtualHostModify sending response")
154154
if len(req.VirtualHost.Domains) > 0 {
155-
req.VirtualHost.Domains = append(req.VirtualHost.Domains, fmt.Sprintf("%s.%s", req.VirtualHost.Domains[0], s.suffix))
155+
lastDomain := len(req.VirtualHost.Domains) - 1
156+
newDomain := fmt.Sprintf("%s.%s", req.VirtualHost.Domains[lastDomain], s.suffix)
157+
s.log.Info("PostVirtualHostModify appending suffix to last domain",
158+
slog.String("originalDomain", req.VirtualHost.Domains[lastDomain]),
159+
slog.String("newDomain", newDomain))
160+
161+
req.VirtualHost.Domains = append(req.VirtualHost.Domains, newDomain)
156162
}
157163
return &pb.PostVirtualHostModifyResponse{
158164
VirtualHost: req.VirtualHost,

test/resilience/testdata/extension_crds.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,32 @@ spec:
4747
properties:
4848
value:
4949
type: string
50+
---
51+
# Grant envoy-gateway permission to list/watch the extension CRDs it declares
52+
# under extensionManagers[].resources. Without this, controller-runtime's
53+
# informers fail with "forbidden: cannot list resource ..." and the provider
54+
# never finishes cache sync.
55+
apiVersion: rbac.authorization.k8s.io/v1
56+
kind: ClusterRole
57+
metadata:
58+
name: envoy-gateway-resilience-ext-resources
59+
rules:
60+
- apiGroups: ["ext-a.example.io"]
61+
resources: ["foofilters"]
62+
verbs: ["get", "list", "watch"]
63+
- apiGroups: ["ext-b.example.io"]
64+
resources: ["barfilters"]
65+
verbs: ["get", "list", "watch"]
66+
---
67+
apiVersion: rbac.authorization.k8s.io/v1
68+
kind: ClusterRoleBinding
69+
metadata:
70+
name: envoy-gateway-resilience-ext-resources
71+
roleRef:
72+
apiGroup: rbac.authorization.k8s.io
73+
kind: ClusterRole
74+
name: envoy-gateway-resilience-ext-resources
75+
subjects:
76+
- kind: ServiceAccount
77+
name: envoy-gateway
78+
namespace: envoy-gateway-system

test/resilience/tests/multiple_extension_managers.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
package tests
99

1010
import (
11+
"context"
1112
"testing"
1213
"time"
1314

1415
"github.com/stretchr/testify/require"
16+
corev1 "k8s.io/api/core/v1"
1517
"k8s.io/apimachinery/pkg/types"
18+
"sigs.k8s.io/controller-runtime/pkg/client"
1619
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
1720
"sigs.k8s.io/gateway-api/conformance/utils/http"
1821
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
@@ -35,8 +38,43 @@ var MultipleExtManagers = suite.ResilienceTest{
3538
ControllerName: "gateway.envoyproxy.io/gatewayclass-controller",
3639
}
3740

38-
// Apply the multi-manager ConfigMap and restart the control plane to pick it up.
39-
ap.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/config_multiple_ext_managers.yaml", true)
41+
// Install the extension CRDs before the control plane restarts so its provider
42+
// can establish watches on ext-a/ext-b resources; otherwise controller-runtime
43+
// times out on cache sync and the pod enters CrashLoopBackOff.
44+
ap.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/extension_crds.yaml", true)
45+
46+
// Capture the original envoy-gateway-config data so we can restore it on cleanup.
47+
// The conformance Applier's cleanup deletes resources it Updated, which would
48+
// remove the helm-owned ConfigMap and wedge the cluster for subsequent test runs.
49+
cmKey := client.ObjectKey{Name: "envoy-gateway-config", Namespace: namespace}
50+
originalCM := &corev1.ConfigMap{}
51+
require.NoError(t, suite.Client.Get(ctx, cmKey, originalCM), "Failed to read original envoy-gateway-config")
52+
originalData := originalCM.Data
53+
t.Cleanup(func() {
54+
restoreCtx, cancel := context.WithTimeout(context.Background(), time.Minute)
55+
defer cancel()
56+
cm := &corev1.ConfigMap{}
57+
if err := suite.Client.Get(restoreCtx, cmKey, cm); err != nil {
58+
t.Logf("could not fetch envoy-gateway-config for restore: %v", err)
59+
return
60+
}
61+
cm.Data = originalData
62+
if err := suite.Client.Update(restoreCtx, cm); err != nil {
63+
t.Logf("failed to restore envoy-gateway-config: %v", err)
64+
return
65+
}
66+
if err := suite.Kube().ScaleDeploymentAndWait(restoreCtx, envoygateway, namespace, 0, time.Minute, false); err != nil {
67+
t.Logf("failed to scale down envoy-gateway during restore: %v", err)
68+
}
69+
if err := suite.Kube().ScaleDeploymentAndWait(restoreCtx, envoygateway, namespace, 1, time.Minute, false); err != nil {
70+
t.Logf("failed to scale up envoy-gateway during restore: %v", err)
71+
}
72+
})
73+
74+
// Apply the multi-manager ConfigMap (cleanup=false so the Applier does not Delete
75+
// the pre-existing helm-owned resource; the restore Cleanup above handles teardown)
76+
// and restart the control plane to pick it up.
77+
ap.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/config_multiple_ext_managers.yaml", false)
4078
err := suite.Kube().ScaleDeploymentAndWait(ctx, envoygateway, namespace, 0, time.Minute, false)
4179
require.NoError(t, err, "Failed to scale down envoy-gateway")
4280
err = suite.Kube().ScaleDeploymentAndWait(ctx, envoygateway, namespace, 1, time.Minute, false)
@@ -48,7 +86,7 @@ var MultipleExtManagers = suite.ResilienceTest{
4886
localTimeout.RequiredConsecutiveSuccesses = 2
4987
localTimeout.MaxTimeToConsistency = time.Minute
5088

51-
t.Run("chaining applies both VirtualHost mutations in order", func(t *testing.T) {
89+
t.Run("Chaining applies both VirtualHost mutations in order", func(t *testing.T) {
5290
ns := "gateway-resilience"
5391
routeNN := types.NamespacedName{Name: "chaining-route", Namespace: ns}
5492
gwNN := types.NamespacedName{Name: "all-namespaces", Namespace: ns}
@@ -81,12 +119,11 @@ var MultipleExtManagers = suite.ResilienceTest{
81119
})
82120
})
83121

84-
t.Run("resource isolation: only owning extension receives resources", func(t *testing.T) {
122+
t.Run("Resource isolation: only owning extension receives resources", func(t *testing.T) {
85123
ns := "gateway-resilience"
86124
routeNN := types.NamespacedName{Name: "isolation-route", Namespace: ns}
87125
gwNN := types.NamespacedName{Name: "all-namespaces", Namespace: ns}
88126

89-
ap.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/extension_crds.yaml", true)
90127
ap.MustApplyWithCleanup(t, suite.Client, suite.TimeoutConfig, "testdata/route_for_resource_isolation.yaml", true)
91128
gwAddr := kubernetes.GatewayAndRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), &gwapiv1.HTTPRoute{}, false, routeNN)
92129

0 commit comments

Comments
 (0)