-
Notifications
You must be signed in to change notification settings - Fork 785
test(conformance): preserve Route status entries owned by other controllers #5138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lexfrei
wants to merge
1
commit into
kubernetes-sigs:main
Choose a base branch
from
lexfrei:conformance/preserve-foreign-status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+431
−6
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,162 @@ | ||
| /* | ||
| Copyright 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 ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/util/retry" | ||
|
|
||
| gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" | ||
| "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
| confsuite "sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
| "sigs.k8s.io/gateway-api/pkg/features" | ||
| ) | ||
|
|
||
| var errForeignStatusNotStored = errors.New("the seeded status entry is missing from the update response") | ||
|
|
||
| func init() { | ||
| ConformanceTests = append(ConformanceTests, HTTPRoutePreserveForeignStatus) | ||
| } | ||
|
|
||
| var HTTPRoutePreserveForeignStatus = confsuite.ConformanceTest{ | ||
| ShortName: "HTTPRoutePreserveForeignStatus", | ||
| Description: "An implementation must not remove or modify HTTPRoute status.parents entries " + | ||
| "whose controllerName belongs to another implementation.", | ||
| Features: []features.FeatureName{ | ||
| features.SupportGateway, | ||
| features.SupportHTTPRoute, | ||
| }, | ||
| Manifests: []string{"tests/httproute-preserve-foreign-status.yaml"}, | ||
| Provisional: true, | ||
| Test: func(t *testing.T, suite *confsuite.ConformanceTestSuite) { | ||
| ns := confsuite.InfrastructureNamespace | ||
| routeNN := types.NamespacedName{Name: "preserve-foreign-status", Namespace: ns} | ||
| gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} | ||
|
|
||
| kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) | ||
|
|
||
| var seeded gatewayv1.RouteParentStatus | ||
| err := retry.RetryOnConflict(retry.DefaultRetry, func() error { | ||
| route := &gatewayv1.HTTPRoute{} | ||
| if err := suite.Client.Get(t.Context(), routeNN, route); err != nil { | ||
| return err | ||
| } | ||
| route.Status.Parents = append(route.Status.Parents, gatewayv1.RouteParentStatus{ | ||
| ParentRef: gatewayv1.ParentReference{ | ||
| Group: new(gatewayv1.Group(gatewayv1.GroupVersion.Group)), | ||
| Kind: new(gatewayv1.Kind("Gateway")), | ||
| Name: "unmanaged-gateway", | ||
| Namespace: new(gatewayv1.Namespace(ns)), | ||
| }, | ||
| ControllerName: kubernetes.StaleControllerName, | ||
| Conditions: []metav1.Condition{{ | ||
| Type: string(gatewayv1.RouteConditionAccepted), | ||
| Status: metav1.ConditionTrue, | ||
| Reason: string(gatewayv1.RouteReasonAccepted), | ||
| ObservedGeneration: route.Generation, | ||
| LastTransitionTime: metav1.Now(), | ||
| }}, | ||
| }) | ||
| if err := suite.Client.Status().Update(t.Context(), route); err != nil { | ||
| return err | ||
| } | ||
| // Read the entry back off the update response rather than reusing | ||
| // the value written above: the API server truncates | ||
| // lastTransitionTime to second precision. | ||
| stored := foreignParentStatus(route.Status.Parents) | ||
| if stored == nil { | ||
| return errForeignStatusNotStored | ||
| } | ||
| seeded = *stored | ||
| return nil | ||
| }) | ||
| require.NoError(t, err, "error seeding a foreign controller's status entry on HTTPRoute %s", routeNN) | ||
|
|
||
| // Bump the generation so the implementation has to run a full | ||
| // read-modify-write cycle on a status that already holds the seeded entry. | ||
| err = retry.RetryOnConflict(retry.DefaultRetry, func() error { | ||
| route := &gatewayv1.HTTPRoute{} | ||
| if getErr := suite.Client.Get(t.Context(), routeNN, route); getErr != nil { | ||
| return getErr | ||
| } | ||
| route.Spec.Rules[0].Matches[0].Path.Value = new("/preserve-foreign-status-updated") | ||
| return suite.Client.Update(t.Context(), route) | ||
| }) | ||
| require.NoError(t, err, "error updating HTTPRoute %s", routeNN) | ||
|
|
||
| // The implementation's own entry catching up to the bumped generation is | ||
| // what proves it wrote status while the seeded entry was there. | ||
| kubernetes.HTTPRouteMustHaveParents(t, suite.Client, suite.TimeoutConfig, routeNN, | ||
| []gatewayv1.RouteParentStatus{ | ||
| { | ||
| ParentRef: gatewayv1.ParentReference{ | ||
| Group: new(gatewayv1.Group(gatewayv1.GroupVersion.Group)), | ||
| Kind: new(gatewayv1.Kind("Gateway")), | ||
| Name: gatewayv1.ObjectName(gwNN.Name), | ||
| Namespace: new(gatewayv1.Namespace(ns)), | ||
| }, | ||
| ControllerName: gatewayv1.GatewayController(suite.ControllerName), | ||
| Conditions: []metav1.Condition{ | ||
| { | ||
| Type: string(gatewayv1.RouteConditionAccepted), | ||
| Status: metav1.ConditionTrue, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| ParentRef: seeded.ParentRef, | ||
| ControllerName: kubernetes.StaleControllerName, | ||
| Conditions: []metav1.Condition{ | ||
| { | ||
| Type: string(gatewayv1.RouteConditionAccepted), | ||
| Status: metav1.ConditionTrue, | ||
| Reason: string(gatewayv1.RouteReasonAccepted), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| // The Route and the Gateway share a namespace, so an implementation | ||
| // that leaves parentRef.namespace unset still matches. | ||
| false, | ||
| ) | ||
|
|
||
| route := &gatewayv1.HTTPRoute{} | ||
| require.NoError(t, suite.Client.Get(t.Context(), routeNN, route), "error fetching HTTPRoute %s", routeNN) | ||
|
|
||
| // HTTPRouteMustHaveParents compares conditions by type, status and reason, | ||
| // so it cannot see a rewrite that keeps the entry Accepted but restamps | ||
| // observedGeneration or lastTransitionTime. | ||
| stored := foreignParentStatus(route.Status.Parents) | ||
| require.NotNilf(t, stored, "HTTPRoute %s: status entry owned by %s was removed", routeNN, kubernetes.StaleControllerName) | ||
| require.Equalf(t, seeded, *stored, "HTTPRoute %s: status entry owned by %s was modified", routeNN, kubernetes.StaleControllerName) | ||
| }, | ||
| } | ||
|
|
||
| func foreignParentStatus(parents []gatewayv1.RouteParentStatus) *gatewayv1.RouteParentStatus { | ||
| for i := range parents { | ||
| if parents[i].ControllerName == kubernetes.StaleControllerName { | ||
| return &parents[i] | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or 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,19 @@ | ||
| apiVersion: gateway.networking.k8s.io/v1 | ||
| kind: HTTPRoute | ||
| metadata: | ||
| name: preserve-foreign-status | ||
| namespace: gateway-conformance-infra | ||
| spec: | ||
| parentRefs: | ||
| - name: same-namespace | ||
| # No Gateway by this name exists; the test seeds a status entry for it under a | ||
| # stale controllerName and checks that the implementation leaves it alone. | ||
| - name: unmanaged-gateway | ||
| rules: | ||
| - matches: | ||
| - path: | ||
| type: PathPrefix | ||
| value: /preserve-foreign-status | ||
| backendRefs: | ||
| - name: infra-backend-v1 | ||
| port: 8080 |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lexfrei is there a reason the stale controller status isn't also asserted using
HTTPRouteMustHaveParents?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason, added it.
Kept the comparison below because
findConditionInListonly looks at type, status and reason, andRouteMustHaveParentsskips observedGeneration for the sentinel. An implementation that rewrites the entry with its own observedGeneration and lastTransitionTime, still Accepted=True, passes the helper. So the helper catches removal and the comparison catches a rewrite.