diff --git a/pkg/registration/hub/importer/importer.go b/pkg/registration/hub/importer/importer.go index cae9a528e..83a854f6e 100644 --- a/pkg/registration/hub/importer/importer.go +++ b/pkg/registration/hub/importer/importer.go @@ -116,6 +116,11 @@ func (i *Importer) sync(ctx context.Context, syncCtx factory.SyncContext, cluste return err } + // If the cluster is in terminating state, skip the reconcile + if !cluster.DeletionTimestamp.IsZero() { + return nil + } + // If the cluster is imported, skip the reconcile if meta.IsStatusConditionTrue(cluster.Status.Conditions, ManagedClusterConditionImported) { return nil diff --git a/pkg/registration/hub/importer/importer_test.go b/pkg/registration/hub/importer/importer_test.go index 50881899f..6ad234531 100644 --- a/pkg/registration/hub/importer/importer_test.go +++ b/pkg/registration/hub/importer/importer_test.go @@ -28,6 +28,7 @@ import ( ) func TestSync(t *testing.T) { + now := metav1.Now() cases := []struct { name string provider *fakeProvider @@ -62,6 +63,15 @@ func TestSync(t *testing.T) { testingcommon.AssertNoActions(t, actions) }, }, + { + name: "cluster in terminating state", + provider: &fakeProvider{isOwned: true}, + key: "cluster1", + cluster: &clusterv1.ManagedCluster{ObjectMeta: metav1.ObjectMeta{Name: "cluster1", DeletionTimestamp: &now}}, + validate: func(t *testing.T, actions []clienttesting.Action) { + testingcommon.AssertNoActions(t, actions) + }, + }, { name: "not owned by the provider", provider: &fakeProvider{isOwned: false},