generated from kubernetes/kubernetes-template-project
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assert observedGeneration is incremented in Status.Conditions. (#1586)
* Update helpers so they check conditions when they are up to date Prior when asserting against conditions the helpers didn't check their observedGeneration. This means the assertions could occur with a stale status. * When updating Gateway status conditions should increment their observedGeneration * allow injection of controllerNames * When updating GatewayClass the status conditions should increment their observedGeneration * fix casing of t.Error/Fatal messages * removed pasted link * refactor some helpers to assert observedGeneration is bumped * add HTTPRoute observed generation tests * use a unique port when adding a new listener * increase test timeout to a minute * use real backends * fail test is an unexpected parent ref appears * Provide better error messages for failed assertions * fix fixture name * fix stale count logging * create a deep copy prior to mutation and updating * drop redundant assertions *MustHaveLatestConditions will ensure the observedGeneration has changed * address linting * use assertion helper * log only the parent ref name * update godoc * put the gateway class observed gen bump behind a support flag
- Loading branch information
Showing
10 changed files
with
463 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, GatewayObservedGenerationBump) | ||
} | ||
|
||
var GatewayObservedGenerationBump = suite.ConformanceTest{ | ||
ShortName: "GatewayObservedGenerationBump", | ||
Description: "A Gateway in the gateway-conformance-infra namespace should update the observedGeneration in all of it's Status.Conditions after an update to the spec", | ||
Manifests: []string{"tests/gateway-observed-generation-bump.yaml"}, | ||
Test: func(t *testing.T, s *suite.ConformanceTestSuite) { | ||
|
||
gwNN := types.NamespacedName{Name: "gateway-observed-generation-bump", Namespace: "gateway-conformance-infra"} | ||
|
||
t.Run("observedGeneration should increment", func(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
namespaces := []string{"gateway-conformance-infra"} | ||
kubernetes.NamespacesMustBeAccepted(t, s.Client, s.TimeoutConfig, namespaces) | ||
|
||
original := &v1beta1.Gateway{} | ||
err := s.Client.Get(ctx, gwNN, original) | ||
require.NoErrorf(t, err, "error getting Gateway: %v", err) | ||
|
||
// Sanity check | ||
kubernetes.GatewayMustHaveLatestConditions(t, original) | ||
|
||
all := v1beta1.NamespacesFromAll | ||
|
||
mutate := original.DeepCopy() | ||
|
||
// mutate the Gateway Spec | ||
mutate.Spec.Listeners = append(mutate.Spec.Listeners, v1beta1.Listener{ | ||
Name: "alternate", | ||
Port: 8080, | ||
Protocol: v1beta1.HTTPProtocolType, | ||
AllowedRoutes: &v1beta1.AllowedRoutes{ | ||
Namespaces: &v1beta1.RouteNamespaces{From: &all}, | ||
}, | ||
}) | ||
|
||
err = s.Client.Update(ctx, mutate) | ||
require.NoErrorf(t, err, "error updating the Gateway: %v", err) | ||
|
||
// Ensure the generation and observedGeneration sync up | ||
kubernetes.NamespacesMustBeAccepted(t, s.Client, s.TimeoutConfig, namespaces) | ||
|
||
updated := &v1beta1.Gateway{} | ||
err = s.Client.Get(ctx, gwNN, updated) | ||
require.NoErrorf(t, err, "error getting Gateway: %v", err) | ||
|
||
// Sanity check | ||
kubernetes.GatewayMustHaveLatestConditions(t, updated) | ||
|
||
require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update") | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
name: gateway-observed-generation-bump | ||
namespace: gateway-conformance-infra | ||
spec: | ||
gatewayClassName: "{GATEWAY_CLASS_NAME}" | ||
listeners: | ||
- name: http | ||
port: 80 | ||
protocol: HTTP | ||
allowedRoutes: | ||
namespaces: | ||
from: All |
77 changes: 77 additions & 0 deletions
77
conformance/tests/gatewayclass-observed-generation-bump.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, GatewayClassObservedGenerationBump) | ||
} | ||
|
||
var GatewayClassObservedGenerationBump = suite.ConformanceTest{ | ||
ShortName: "GatewayClassObservedGenerationBump", | ||
Features: []suite.SupportedFeature{suite.SupportGatewayClassObservedGenerationBump}, | ||
Description: "A GatewayClass should update the observedGeneration in all of it's Status.Conditions after an update to the spec", | ||
Manifests: []string{"tests/gatewayclass-observed-generation-bump.yaml"}, | ||
Test: func(t *testing.T, s *suite.ConformanceTestSuite) { | ||
gwc := types.NamespacedName{Name: "gatewayclass-observed-generation-bump"} | ||
|
||
t.Run("observedGeneration should increment", func(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
kubernetes.GWCMustBeAccepted(t, s.Client, s.TimeoutConfig, gwc.Name) | ||
|
||
original := &v1beta1.GatewayClass{} | ||
err := s.Client.Get(ctx, gwc, original) | ||
require.NoErrorf(t, err, "error getting GatewayClass: %v", err) | ||
|
||
// Sanity check | ||
kubernetes.GatewayClassMustHaveLatestConditions(t, original) | ||
|
||
mutate := original.DeepCopy() | ||
desc := "new" | ||
mutate.Spec.Description = &desc | ||
|
||
err = s.Client.Update(ctx, mutate) | ||
require.NoErrorf(t, err, "error updating the GatewayClass: %v", err) | ||
|
||
// Ensure the generation and observedGeneration sync up | ||
kubernetes.GWCMustBeAccepted(t, s.Client, s.TimeoutConfig, gwc.Name) | ||
|
||
updated := &v1beta1.GatewayClass{} | ||
err = s.Client.Get(ctx, gwc, updated) | ||
require.NoErrorf(t, err, "error getting GatewayClass: %v", err) | ||
|
||
// Sanity check | ||
kubernetes.GatewayClassMustHaveLatestConditions(t, updated) | ||
|
||
require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update") | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: GatewayClass | ||
metadata: | ||
name: gatewayclass-observed-generation-bump | ||
spec: | ||
controllerName: "{GATEWAY_CONTROLLER_NAME}" | ||
description: "old" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, HTTPRouteObservedGenerationBump) | ||
} | ||
|
||
var HTTPRouteObservedGenerationBump = suite.ConformanceTest{ | ||
ShortName: "HTTPRouteObservedGenerationBump", | ||
Description: "A HTTPRoute in the gateway-conformance-infra namespace should update the observedGeneration in all of it's Status.Conditions after an update to the spec", | ||
Manifests: []string{"tests/httproute-observed-generation-bump.yaml"}, | ||
Test: func(t *testing.T, s *suite.ConformanceTestSuite) { | ||
|
||
routeNN := types.NamespacedName{Name: "observed-generation-bump", Namespace: "gateway-conformance-infra"} | ||
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: "gateway-conformance-infra"} | ||
|
||
acceptedCondition := metav1.Condition{ | ||
Type: string(v1beta1.RouteConditionAccepted), | ||
Status: metav1.ConditionTrue, | ||
Reason: "", // any reason | ||
} | ||
|
||
t.Run("observedGeneration should increment", func(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
defer cancel() | ||
|
||
namespaces := []string{"gateway-conformance-infra"} | ||
kubernetes.NamespacesMustBeAccepted(t, s.Client, s.TimeoutConfig, namespaces) | ||
|
||
original := &v1beta1.HTTPRoute{} | ||
err := s.Client.Get(ctx, routeNN, original) | ||
require.NoErrorf(t, err, "error getting HTTPRoute: %v", err) | ||
|
||
// Sanity check | ||
kubernetes.HTTPRouteMustHaveLatestConditions(t, original) | ||
|
||
mutate := original.DeepCopy() | ||
mutate.Spec.Rules[0].BackendRefs[0].Name = "infra-backend-v2" | ||
err = s.Client.Update(ctx, mutate) | ||
require.NoErrorf(t, err, "error updating the HTTPRoute: %v", err) | ||
|
||
kubernetes.HTTPRouteMustHaveCondition(t, s.Client, s.TimeoutConfig, routeNN, gwNN, acceptedCondition) | ||
|
||
updated := &v1beta1.HTTPRoute{} | ||
err = s.Client.Get(ctx, routeNN, updated) | ||
require.NoErrorf(t, err, "error getting Gateway: %v", err) | ||
|
||
// Sanity check | ||
kubernetes.HTTPRouteMustHaveLatestConditions(t, updated) | ||
|
||
require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update") | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: observed-generation-bump | ||
namespace: gateway-conformance-infra | ||
spec: | ||
parentRefs: | ||
- name: same-namespace | ||
rules: | ||
- backendRefs: | ||
- name: infra-backend-v1 | ||
port: 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.