Skip to content

Commit 8ff423d

Browse files
authored
Merge pull request #6538 from luyb177/automated-cherry-pick-of-#6525-upstream-release-1.12
Automated cherry pick of #6525: don't recreate resource in the member cluster when it is
2 parents 102ebfe + ea81e65 commit 8ff423d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

pkg/controllers/status/work_status_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ func (c *WorkStatusController) handleDeleteEvent(ctx context.Context, key keys.F
294294
return nil
295295
}
296296

297+
// skip processing as the work object is suspended for dispatching.
298+
if helper.IsWorkSuspendDispatching(work) {
299+
return nil
300+
}
301+
297302
if util.GetLabelValue(work.Labels, util.PropagationInstruction) == util.PropagationInstructionSuppressed {
298303
return nil
299304
}

pkg/controllers/status/work_status_controller_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/stretchr/testify/assert"
2727
corev1 "k8s.io/api/core/v1"
2828
rbacv1 "k8s.io/api/rbac/v1"
29+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2930
"k8s.io/apimachinery/pkg/api/meta"
3031
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -578,6 +579,7 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
578579
expectedError bool
579580
wrongWorkNS bool
580581
workApplyFunc func(work *workv1alpha1.Work)
582+
assertFunc func(t *testing.T, dynamicClientSets *dynamicfake.FakeDynamicClient)
581583
}{
582584
{
583585
name: "failed to exec NeedUpdate",
@@ -668,6 +670,23 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
668670
work.SetDeletionTimestamp(ptr.To(metav1.Now()))
669671
},
670672
},
673+
{
674+
name: "resource not found, work suspendDispatching true, should not recreate resource",
675+
obj: newPodObj("karmada-es-cluster"),
676+
pod: nil, // Simulate the resource does not exist in the member cluster
677+
raw: []byte(`{"apiVersion":"v1","kind":"Pod","metadata":{"name":"pod","namespace":"default"}}`),
678+
controllerWithoutInformer: true,
679+
expectedError: false,
680+
workApplyFunc: func(work *workv1alpha1.Work) {
681+
work.Spec.SuspendDispatching = ptr.To(true)
682+
},
683+
assertFunc: func(t *testing.T, dynamicClientSets *dynamicfake.FakeDynamicClient) {
684+
gvr := corev1.SchemeGroupVersion.WithResource("pods")
685+
obj, err := dynamicClientSets.Resource(gvr).Namespace("default").Get(context.Background(), "pod", metav1.GetOptions{})
686+
assert.True(t, apierrors.IsNotFound(err), "expected a NotFound error but got: %s", err)
687+
assert.Nil(t, obj)
688+
},
689+
},
671690
}
672691

673692
for _, tt := range tests {
@@ -708,6 +727,10 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
708727
} else {
709728
assert.NoError(t, err)
710729
}
730+
731+
if tt.assertFunc != nil {
732+
tt.assertFunc(t, dynamicClientSet)
733+
}
711734
})
712735
}
713736
}

0 commit comments

Comments
 (0)