1
16
17 package tests
18
19 import (
20 "context"
21 "testing"
22 "time"
23
24 "github.com/stretchr/testify/require"
25 "k8s.io/apimachinery/pkg/types"
26 "sigs.k8s.io/controller-runtime/pkg/client"
27
28 v1 "sigs.k8s.io/gateway-api/apis/v1"
29 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
30 "sigs.k8s.io/gateway-api/conformance/utils/suite"
31 )
32
33 func init() {
34 ConformanceTests = append(ConformanceTests, GatewayObservedGenerationBump)
35 }
36
37 var GatewayObservedGenerationBump = suite.ConformanceTest{
38 ShortName: "GatewayObservedGenerationBump",
39 Description: "A Gateway in the gateway-conformance-infra namespace should update the observedGeneration in all of its Status.Conditions after an update to the spec",
40 Features: []suite.SupportedFeature{
41 suite.SupportGateway,
42 suite.SupportGatewayPort8080,
43 },
44 Manifests: []string{"tests/gateway-observed-generation-bump.yaml"},
45 Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
46 gwNN := types.NamespacedName{Name: "gateway-observed-generation-bump", Namespace: "gateway-conformance-infra"}
47
48 t.Run("observedGeneration should increment", func(t *testing.T) {
49 ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
50 defer cancel()
51
52 namespaces := []string{"gateway-conformance-infra"}
53 kubernetes.NamespacesMustBeReady(t, s.Client, s.TimeoutConfig, namespaces)
54
55
56 kubernetes.GatewayMustHaveLatestConditions(t, s.Client, s.TimeoutConfig, gwNN)
57
58 original := &v1.Gateway{}
59 err := s.Client.Get(ctx, gwNN, original)
60 require.NoErrorf(t, err, "error getting Gateway: %v", err)
61
62 all := v1.NamespacesFromAll
63
64 mutate := original.DeepCopy()
65
66
67 mutate.Spec.Listeners = append(mutate.Spec.Listeners, v1.Listener{
68 Name: "alternate",
69 Port: 8080,
70 Protocol: v1.HTTPProtocolType,
71 AllowedRoutes: &v1.AllowedRoutes{
72 Namespaces: &v1.RouteNamespaces{From: &all},
73 },
74 })
75
76 err = s.Client.Patch(ctx, mutate, client.MergeFrom(original))
77 require.NoErrorf(t, err, "error patching the Gateway: %v", err)
78
79
80 kubernetes.NamespacesMustBeReady(t, s.Client, s.TimeoutConfig, namespaces)
81
82
83 kubernetes.GatewayMustHaveLatestConditions(t, s.Client, s.TimeoutConfig, gwNN)
84
85 updated := &v1.Gateway{}
86 err = s.Client.Get(ctx, gwNN, updated)
87 require.NoErrorf(t, err, "error getting Gateway: %v", err)
88
89 require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update")
90 })
91 },
92 }
93
View as plain text