From bdf239f1aea289cbb969ec2ad6059315d49feb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E5=85=83?= Date: Thu, 11 Mar 2021 15:34:38 +0800 Subject: [PATCH] delete health scope when delete app --- references/common/application.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/references/common/application.go b/references/common/application.go index e200c79d5..ffc4abf7f 100644 --- a/references/common/application.go +++ b/references/common/application.go @@ -224,7 +224,21 @@ func (o *DeleteOptions) DeleteApp() (string, error) { return "", fmt.Errorf("delete application err: %w", err) } - // TODO(wonderflow): delete the default health scope here + for _, cmp := range app.Spec.Components { + healthScopeName, ok := cmp.Scopes[api.DefaultHealthScopeKey] + if ok { + var healthScope corev1alpha2.HealthScope + if err := o.Client.Get(ctx, client.ObjectKey{Namespace: o.Env.Namespace, Name: healthScopeName}, &healthScope); err != nil { + if apierrors.IsNotFound(err) { + continue + } + return "", fmt.Errorf("delete health scope %s err: %w", healthScopeName, err) + } + if err = o.Client.Delete(ctx, &healthScope); err != nil { + return "", fmt.Errorf("delete health scope %s err: %w", healthScopeName, err) + } + } + } return fmt.Sprintf("app \"%s\" deleted from env \"%s\"", o.AppName, o.Env.Name), nil }