@@ -37,6 +37,7 @@ import (
3737 "sigs.k8s.io/controller-runtime/pkg/controller"
3838 "sigs.k8s.io/controller-runtime/pkg/reconcile"
3939
40+ "github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/controller/customresource"
4041 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/state"
4142)
4243
@@ -304,6 +305,20 @@ func TestReconcile(t *testing.T) {
304305 return Result {NextState : "Initial" }, nil
305306 },
306307 },
308+ {
309+ name : "should skip reconcile request" ,
310+ existingObj : baseObj .WithSkipReconciliationAnnotation (),
311+ handleState : func (ctx context.Context , do * dummyObject ) (Result , error ) {
312+ return Result {Result : reconcile.Result {}}, nil
313+ },
314+ },
315+ {
316+ name : "should skip reconcile request on deleted object" ,
317+ existingObj : baseObj .WithSkipReconciliationAnnotation ().WithDeletedStaze (),
318+ handleState : func (ctx context.Context , do * dummyObject ) (Result , error ) {
319+ return Result {Result : reconcile.Result {}}, nil
320+ },
321+ },
307322 }
308323
309324 for _ , tc := range tests {
@@ -534,6 +549,33 @@ func (do *dummyObject) DeepCopy() *dummyObject {
534549 }
535550}
536551
552+ func (do * dummyObject ) WithSkipReconciliationAnnotation () * dummyObject {
553+ copyOfDo := do .DeepCopy ()
554+
555+ if copyOfDo .Annotations == nil {
556+ copyOfDo .Annotations = make (map [string ]string )
557+ }
558+ copyOfDo .Annotations [customresource .ReconciliationPolicyAnnotation ] = customresource .ReconciliationPolicySkip
559+
560+ return copyOfDo
561+ }
562+
563+ func (do * dummyObject ) WithDeletedStaze () * dummyObject {
564+ copyOfDo := do .DeepCopy ()
565+
566+ if len (copyOfDo .Status .Conditions ) == 0 {
567+ copyOfDo .Status .Conditions = []metav1.Condition {}
568+ }
569+
570+ copyOfDo .Status .Conditions = append (copyOfDo .Status .Conditions , metav1.Condition {
571+ Type : "State" ,
572+ Status : metav1 .ConditionTrue ,
573+ Reason : "Deleted" ,
574+ })
575+
576+ return copyOfDo
577+ }
578+
537579func prevStatusObject (state state.ResourceState , observedGen int64 ) StatusObject {
538580 return newDummyObject (metav1.ObjectMeta {}, []metav1.Condition {
539581 newStateCondition (state , metav1 .ConditionTrue , observedGen ),
0 commit comments