From 84dc7edd471fb9497d9f5be9f5a6ed0dad96c378 Mon Sep 17 00:00:00 2001 From: Hamed Karbasi Date: Wed, 4 Dec 2024 16:20:44 +0330 Subject: [PATCH 1/2] Allow to delete namespaces having no team --- custom_webhooks/resourcequota_webhook.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_webhooks/resourcequota_webhook.go b/custom_webhooks/resourcequota_webhook.go index 4947af1..72147f6 100644 --- a/custom_webhooks/resourcequota_webhook.go +++ b/custom_webhooks/resourcequota_webhook.go @@ -54,7 +54,8 @@ func (v *ResourceQuotaValidator) Handle(ctx context.Context, req admission.Reque } else if req.Operation == "DELETE" { teamName, ok := ns.GetLabels()[teamLabel] if !ok { - return admission.Denied("no team found for the project. please join your project to a team") + // It's OK to delete namespaces having no team. + return admission.Allowed("DELETE") } if req.Name == "default" && teamName != snappcloudTeamName { return admission.Denied("default resourcequota cannot be deleted") From f3c26c45003af79587c04ba8e12e0c5d455f653b Mon Sep 17 00:00:00 2001 From: Hamed Karbasi Date: Wed, 4 Dec 2024 17:11:54 +0330 Subject: [PATCH 2/2] fix bug of the default resource quota deletion --- custom_webhooks/resourcequota_webhook.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/custom_webhooks/resourcequota_webhook.go b/custom_webhooks/resourcequota_webhook.go index 72147f6..72b0d4e 100644 --- a/custom_webhooks/resourcequota_webhook.go +++ b/custom_webhooks/resourcequota_webhook.go @@ -52,12 +52,13 @@ func (v *ResourceQuotaValidator) Handle(ctx context.Context, req admission.Reque return admission.Allowed("updating resourcequota") } } else if req.Operation == "DELETE" { - teamName, ok := ns.GetLabels()[teamLabel] - if !ok { - // It's OK to delete namespaces having no team. - return admission.Allowed("DELETE") - } - if req.Name == "default" && teamName != snappcloudTeamName { + if req.Name == "default" { + teamName, ok := ns.GetLabels()[teamLabel] + if ok { + if teamName == snappcloudTeamName { + return admission.Allowed("DELETE") + } + } return admission.Denied("default resourcequota cannot be deleted") } return admission.Allowed("DELETE")