-
Notifications
You must be signed in to change notification settings - Fork 312
OCPBUGS-64582: Drop strategy.rollingUpdate and switch strategy.type to Recreate via pre-patch in frr-k8s-statuscleaner deployments on SNO #3121
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
Merged
openshift-merge-bot
merged 2 commits into
openshift:master
from
andreaskaris:test-rolling-update-null
Aug 20, 2026
Merged
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
Some comments aren't visible on the classic Files Changed page.
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
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
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,131 @@ | ||
| package apply | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/openshift/cluster-network-operator/pkg/client/fake" | ||
| "github.com/openshift/cluster-network-operator/pkg/names" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| fakedynamic "k8s.io/client-go/dynamic/fake" | ||
| clienttesting "k8s.io/client-go/testing" | ||
| ) | ||
|
|
||
| const prePatchValue = `{"spec":{"strategy":{"type":"Recreate","rollingUpdate":null}}}` | ||
|
|
||
| func newTestDeployment(annotations map[string]string) *unstructured.Unstructured { | ||
| obj := &unstructured.Unstructured{} | ||
| obj.SetGroupVersionKind(schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}) | ||
| obj.SetName("test-deployment") | ||
| obj.SetNamespace("test-ns") | ||
| obj.SetAnnotations(annotations) | ||
| return obj | ||
| } | ||
|
|
||
| func patchRecorder(patchTypes *[]types.PatchType, prePatchBody *string, prePatchErr error) func(action clienttesting.Action) (bool, runtime.Object, error) { | ||
| return func(action clienttesting.Action) (bool, runtime.Object, error) { | ||
| patchAction := action.(clienttesting.PatchAction) | ||
| *patchTypes = append(*patchTypes, patchAction.GetPatchType()) | ||
| if patchAction.GetPatchType() == types.StrategicMergePatchType { | ||
| *prePatchBody = string(patchAction.GetPatch()) | ||
| if prePatchErr != nil { | ||
| return true, nil, prePatchErr | ||
| } | ||
| } | ||
| return true, newTestDeployment(nil), nil | ||
| } | ||
| } | ||
|
|
||
| func TestApplyObjectPrePatchRunsBeforeSSA(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| client := fake.NewFakeClient() | ||
|
|
||
| var patchTypes []types.PatchType | ||
| var prePatchBody string | ||
| pr := patchRecorder(&patchTypes, &prePatchBody, nil) | ||
| client.Default().Dynamic().(*fakedynamic.FakeDynamicClient).PrependReactor("patch", "deployments", pr) | ||
|
|
||
| obj := newTestDeployment(map[string]string{ | ||
| names.PrePatchAnnotation: prePatchValue, | ||
| }) | ||
|
|
||
| err := ApplyObject(context.Background(), client, obj, "test-controller") | ||
| g.Expect(err).To(Succeed()) | ||
| g.Expect(patchTypes).To(HaveLen(2)) | ||
| g.Expect(patchTypes[0]).To(Equal(types.StrategicMergePatchType), "pre-patch should be strategic-merge-patch") | ||
| g.Expect(patchTypes[1]).To(Equal(types.ApplyPatchType), "second patch should be SSA apply") | ||
| g.Expect(prePatchBody).To(Equal(prePatchValue), "pre-patch body should match annotation value") | ||
| } | ||
|
|
||
| func TestApplyObjectPrePatchNotFoundAllowsSSA(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| client := fake.NewFakeClient() | ||
|
|
||
| var patchTypes []types.PatchType | ||
| var prePatchBody string | ||
| pr := patchRecorder(&patchTypes, &prePatchBody, apierrors.NewNotFound( | ||
| schema.GroupResource{Group: "apps", Resource: "deployments"}, "test-deployment")) | ||
| client.Default().Dynamic().(*fakedynamic.FakeDynamicClient).PrependReactor("patch", "deployments", pr) | ||
|
|
||
| obj := newTestDeployment(map[string]string{ | ||
| names.PrePatchAnnotation: prePatchValue, | ||
| }) | ||
|
|
||
| err := ApplyObject(context.Background(), client, obj, "test-controller") | ||
| g.Expect(err).To(Succeed()) | ||
| g.Expect(patchTypes).To(HaveLen(2)) | ||
| g.Expect(patchTypes[0]).To(Equal(types.StrategicMergePatchType), "pre-patch was attempted") | ||
| g.Expect(patchTypes[1]).To(Equal(types.ApplyPatchType), "SSA apply still proceeded") | ||
| g.Expect(prePatchBody).To(Equal(prePatchValue), "pre-patch body should match annotation value") | ||
| } | ||
|
|
||
| func TestApplyObjectPrePatchErrorStopsReconciliation(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| client := fake.NewFakeClient() | ||
|
|
||
| var patchTypes []types.PatchType | ||
| var prePatchBody string | ||
| pr := patchRecorder(&patchTypes, &prePatchBody, fmt.Errorf("API server error")) | ||
| client.Default().Dynamic().(*fakedynamic.FakeDynamicClient).PrependReactor("patch", "deployments", pr) | ||
|
|
||
| obj := newTestDeployment(map[string]string{ | ||
| names.PrePatchAnnotation: prePatchValue, | ||
| }) | ||
|
|
||
| err := ApplyObject(context.Background(), client, obj, "test-controller") | ||
| g.Expect(err).To(HaveOccurred()) | ||
| g.Expect(err.Error()).To(ContainSubstring("failed to pre-patch")) | ||
| g.Expect(patchTypes).To(HaveLen(1), "SSA apply should not have been reached") | ||
| g.Expect(patchTypes[0]).To(Equal(types.StrategicMergePatchType), "pre-patch should be strategic-merge-patch") | ||
| g.Expect(prePatchBody).To(Equal(prePatchValue), "pre-patch body should match annotation value") | ||
| } | ||
|
|
||
| func TestApplyObjectNoPrePatchAnnotationSkipsPrePatch(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| client := fake.NewFakeClient() | ||
|
|
||
| var patchTypes []types.PatchType | ||
| var prePatchBody string | ||
| pr := patchRecorder(&patchTypes, &prePatchBody, nil) | ||
| client.Default().Dynamic().(*fakedynamic.FakeDynamicClient).PrependReactor("patch", "deployments", pr) | ||
|
|
||
| obj := newTestDeployment(nil) | ||
|
|
||
| err := ApplyObject(context.Background(), client, obj, "test-controller") | ||
| g.Expect(err).To(Succeed()) | ||
| g.Expect(patchTypes).To(HaveLen(1)) | ||
| g.Expect(patchTypes[0]).To(Equal(types.ApplyPatchType), "only SSA apply should have run") | ||
| g.Expect(prePatchBody).To(BeEmpty(), "no pre-patch should have been sent") | ||
| } |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.