Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Remove unnecessary code for removing managed cluster resources #330

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions pkg/registration/hub/managedcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,10 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
return nil
}

// Hub cluster-admin denies the current spoke cluster, we remove its related resources and update its condition.
// Hub cluster-admin denies the current spoke cluster, update its condition.
// The resources applied on this spoke will keep there.
c.eventRecorder.Eventf("ManagedClusterDenied", "managed cluster %s is denied by hub cluster admin", managedClusterName)

if err := c.removeManagedClusterResources(ctx, managedClusterName); err != nil {
return err
}

meta.SetStatusCondition(&newManagedCluster.Status.Conditions, metav1.Condition{
Type: v1.ManagedClusterConditionHubAccepted,
Status: metav1.ConditionFalse,
Expand Down Expand Up @@ -186,16 +183,3 @@ func (c *managedClusterController) sync(ctx context.Context, syncCtx factory.Syn
}
return operatorhelpers.NewMultiLineAggregate(errs)
}

func (c *managedClusterController) removeManagedClusterResources(ctx context.Context, managedClusterName string) error {
var errs []error
// Clean up managed cluster manifests
assetFn := helpers.ManagedClusterAssetFn(manifests.RBACManifests, managedClusterName)
resourceResults := resourceapply.DeleteAll(ctx, resourceapply.NewKubeClientHolder(c.kubeClient), c.eventRecorder, assetFn, staticFiles...)
for _, result := range resourceResults {
if result.Error != nil {
errs = append(errs, fmt.Errorf("%q (%T): %v", result.File, result.Type, result.Error))
}
}
return operatorhelpers.NewMultiLineAggregate(errs)
}
Loading