-
Notifications
You must be signed in to change notification settings - Fork 93
OADP-7943: Fix DPA annotation changes not triggering reconciliation #2205
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
kaovilai
wants to merge
1
commit into
openshift:oadp-dev
Choose a base branch
from
kaovilai:OADP-7943-fix-annotation-reconcile
base: oadp-dev
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.
+273
−5
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
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,217 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/event" | ||
|
|
||
| oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1" | ||
| "github.com/openshift/oadp-operator/pkg/common" | ||
| ) | ||
|
|
||
| func TestHasRelevantAnnotationChange(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| oldAnnotations map[string]string | ||
| newAnnotations map[string]string | ||
| want bool | ||
| }{ | ||
| { | ||
| name: "no annotations on either object", | ||
| oldAnnotations: nil, | ||
| newAnnotations: nil, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "velero server args annotation added", | ||
| oldAnnotations: nil, | ||
| newAnnotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "my-configmap", | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "velero server args annotation removed", | ||
| oldAnnotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "my-configmap", | ||
| }, | ||
| newAnnotations: nil, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "velero server args annotation value changed", | ||
| oldAnnotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "old-configmap", | ||
| }, | ||
| newAnnotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "new-configmap", | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "node agent server args annotation added", | ||
| oldAnnotations: nil, | ||
| newAnnotations: map[string]string{ | ||
| common.UnsupportedNodeAgentServerArgsAnnotation: "my-configmap", | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "node agent server args annotation removed", | ||
| oldAnnotations: map[string]string{ | ||
| common.UnsupportedNodeAgentServerArgsAnnotation: "my-configmap", | ||
| }, | ||
| newAnnotations: nil, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "irrelevant annotation changed", | ||
| oldAnnotations: map[string]string{ | ||
| "some-other-annotation": "old-value", | ||
| }, | ||
| newAnnotations: map[string]string{ | ||
| "some-other-annotation": "new-value", | ||
| }, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "relevant annotation unchanged, irrelevant changed", | ||
| oldAnnotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "same-configmap", | ||
| "some-other-annotation": "old-value", | ||
| }, | ||
| newAnnotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "same-configmap", | ||
| "some-other-annotation": "new-value", | ||
| }, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "both relevant annotations changed", | ||
| oldAnnotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "old-velero-cm", | ||
| common.UnsupportedNodeAgentServerArgsAnnotation: "old-nodeagent-cm", | ||
| }, | ||
| newAnnotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "new-velero-cm", | ||
| common.UnsupportedNodeAgentServerArgsAnnotation: "new-nodeagent-cm", | ||
| }, | ||
| want: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| oldObj := &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Annotations: tt.oldAnnotations, | ||
| }, | ||
| } | ||
| newObj := &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Annotations: tt.newAnnotations, | ||
| }, | ||
| } | ||
| got := hasRelevantAnnotationChange(oldObj, newObj) | ||
| if got != tt.want { | ||
| t.Errorf("hasRelevantAnnotationChange() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestVeleroPredicateUpdateFunc_AnnotationChange(t *testing.T) { | ||
| scheme := runtime.NewScheme() | ||
| _ = oadpv1alpha1.AddToScheme(scheme) | ||
|
|
||
| pred := veleroPredicate(scheme) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| old *oadpv1alpha1.DataProtectionApplication | ||
| new *oadpv1alpha1.DataProtectionApplication | ||
| want bool | ||
| }{ | ||
| { | ||
| name: "generation changed - should reconcile", | ||
| old: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{Generation: 1}, | ||
| }, | ||
| new: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{Generation: 2}, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "generation same, no annotation change - should NOT reconcile", | ||
| old: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{Generation: 1}, | ||
| }, | ||
| new: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{Generation: 1}, | ||
| }, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "generation same, velero annotation added - should reconcile", | ||
| old: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{Generation: 1}, | ||
| }, | ||
| new: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Generation: 1, | ||
| Annotations: map[string]string{ | ||
| common.UnsupportedVeleroServerArgsAnnotation: "my-cm", | ||
| }, | ||
| }, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "generation same, node agent annotation removed - should reconcile", | ||
| old: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Generation: 1, | ||
| Annotations: map[string]string{ | ||
| common.UnsupportedNodeAgentServerArgsAnnotation: "my-cm", | ||
| }, | ||
| }, | ||
| }, | ||
| new: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{Generation: 1}, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "generation same, irrelevant annotation changed - should NOT reconcile", | ||
| old: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Generation: 1, | ||
| Annotations: map[string]string{"kubectl.kubernetes.io/last-applied": "old"}, | ||
| }, | ||
| }, | ||
| new: &oadpv1alpha1.DataProtectionApplication{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Generation: 1, | ||
| Annotations: map[string]string{"kubectl.kubernetes.io/last-applied": "new"}, | ||
| }, | ||
| }, | ||
| want: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| e := event.UpdateEvent{ | ||
| ObjectOld: tt.old, | ||
| ObjectNew: tt.new, | ||
| } | ||
| got := pred.Update(e) | ||
| if got != tt.want { | ||
| t.Errorf("veleroPredicate.Update() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
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.
Fail fast when scheme registration fails.
At Line 127, ignoring
AddToSchemeerrors can hide test setup issues and make failures less actionable.Suggested fix
func TestVeleroPredicateUpdateFunc_AnnotationChange(t *testing.T) { scheme := runtime.NewScheme() - _ = oadpv1alpha1.AddToScheme(scheme) + if err := oadpv1alpha1.AddToScheme(scheme); err != nil { + t.Fatalf("failed to add OADP API to scheme: %v", err) + }📝 Committable suggestion
🤖 Prompt for AI Agents