Merge pull request #4128 from xyz-li/cleanup_app

clean up app when workspace is deleted
This commit is contained in:
KubeSphere CI Bot
2021-09-07 16:58:15 +08:00
committed by GitHub
6 changed files with 357 additions and 6 deletions

View File

@@ -424,11 +424,16 @@ func (r *Reconciler) deleteHelmApps(ctx context.Context, ws string) error {
if err != nil {
return err
}
for i := range apps.Items {
state := apps.Items[i].Status.State
// active and suspended applications belong to app store, they should not be removed here.
if !(state == v1alpha1.StateActive || state == v1alpha1.StateSuspended) {
err = r.Delete(ctx, &apps.Items[i])
for _, app := range apps.Items {
if app.Annotations == nil {
app.Annotations = map[string]string{}
}
if _, exists := app.Annotations[constants.DanglingAppCleanupKey]; !exists {
// Mark the app, the cleanup is in the application controller.
appCopy := app.DeepCopy()
appCopy.Annotations[constants.DanglingAppCleanupKey] = constants.CleanupDanglingAppOngoing
appPatch := client.MergeFrom(&app)
err = r.Patch(ctx, appCopy, appPatch)
if err != nil {
return err
}