@@ -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