sigs.k8s.io/gateway-api@v1.0.0/conformance/tests/gatewayclass-observed-generation-bump.go (about) 1 /* 2 Copyright 2022 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 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, GatewayClassObservedGenerationBump) 35 } 36 37 var GatewayClassObservedGenerationBump = suite.ConformanceTest{ 38 ShortName: "GatewayClassObservedGenerationBump", 39 Features: []suite.SupportedFeature{ 40 suite.SupportGateway, 41 }, 42 Description: "A GatewayClass should update the observedGeneration in all of it's Status.Conditions after an update to the spec", 43 Manifests: []string{"tests/gatewayclass-observed-generation-bump.yaml"}, 44 Test: func(t *testing.T, s *suite.ConformanceTestSuite) { 45 gwc := types.NamespacedName{Name: "gatewayclass-observed-generation-bump"} 46 47 t.Run("observedGeneration should increment", func(t *testing.T) { 48 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 49 defer cancel() 50 51 kubernetes.GWCMustHaveAcceptedConditionAny(t, s.Client, s.TimeoutConfig, gwc.Name) 52 53 original := &v1.GatewayClass{} 54 err := s.Client.Get(ctx, gwc, original) 55 require.NoErrorf(t, err, "error getting GatewayClass: %v", err) 56 57 // Sanity check 58 kubernetes.GatewayClassMustHaveLatestConditions(t, original) 59 60 mutate := original.DeepCopy() 61 desc := "new" 62 mutate.Spec.Description = &desc 63 64 err = s.Client.Patch(ctx, mutate, client.MergeFrom(original)) 65 require.NoErrorf(t, err, "error patching the GatewayClass: %v", err) 66 67 // Ensure the generation and observedGeneration sync up 68 kubernetes.GWCMustHaveAcceptedConditionAny(t, s.Client, s.TimeoutConfig, gwc.Name) 69 70 updated := &v1.GatewayClass{} 71 err = s.Client.Get(ctx, gwc, updated) 72 require.NoErrorf(t, err, "error getting GatewayClass: %v", err) 73 74 // Sanity check 75 kubernetes.GatewayClassMustHaveLatestConditions(t, updated) 76 77 require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update") 78 }) 79 }, 80 }