Skip to content

Commit 55aead1

Browse files
authored
Merge pull request #6525 from XiShanYongYe-Chang/fix-6510
Fixed the issue that resources will be recreated after deleted on the cluster when resource is suspended for dispatching
2 parents 9966a3f + b8e9c84 commit 55aead1

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
@@ -291,6 +291,11 @@ func (c *WorkStatusController) handleDeleteEvent(ctx context.Context, key keys.F
291291
return nil
292292
}
293293

294+
// skip processing as the work object is suspended for dispatching.
295+
if util.IsWorkSuspendDispatching(work) {
296+
return nil
297+
}
298+
294299
//nolint:staticcheck // SA1019 ignore deprecated util.PropagationInstruction
295300
if util.GetLabelValue(work.Labels, util.PropagationInstruction) == util.PropagationInstructionSuppressed {
296301
return nil

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"
@@ -579,6 +580,7 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
579580
expectedError bool
580581
wrongWorkNS bool
581582
workApplyFunc func(work *workv1alpha1.Work)
583+
assertFunc func(t *testing.T, dynamicClientSets *dynamicfake.FakeDynamicClient)
582584
}{
583585
{
584586
name: "failed to exec NeedUpdate",
@@ -669,6 +671,23 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
669671
work.SetDeletionTimestamp(ptr.To(metav1.Now()))
670672
},
671673
},
674+
{
675+
name: "resource not found, work suspendDispatching true, should not recreate resource",
676+
obj: newPodObj("karmada-es-cluster"),
677+
pod: nil, // Simulate the resource does not exist in the member cluster
678+
raw: []byte(`{"apiVersion":"v1","kind":"Pod","metadata":{"name":"pod","namespace":"default"}}`),
679+
controllerWithoutInformer: true,
680+
expectedError: false,
681+
workApplyFunc: func(work *workv1alpha1.Work) {
682+
work.Spec.SuspendDispatching = ptr.To(true)
683+
},
684+
assertFunc: func(t *testing.T, dynamicClientSets *dynamicfake.FakeDynamicClient) {
685+
gvr := corev1.SchemeGroupVersion.WithResource("pods")
686+
obj, err := dynamicClientSets.Resource(gvr).Namespace("default").Get(context.Background(), "pod", metav1.GetOptions{})
687+
assert.True(t, apierrors.IsNotFound(err), "expected a NotFound error but got: %s", err)
688+
assert.Nil(t, obj)
689+
},
690+
},
672691
}
673692

674693
for _, tt := range tests {
@@ -709,6 +728,10 @@ func TestWorkStatusController_syncWorkStatus(t *testing.T) {
709728
} else {
710729
assert.NoError(t, err)
711730
}
731+
732+
if tt.assertFunc != nil {
733+
tt.assertFunc(t, dynamicClientSet)
734+
}
712735
})
713736
}
714737
}

0 commit comments

Comments
 (0)