From 25b4a35b65502d8bb52010bb8fac8b207e3bb750 Mon Sep 17 00:00:00 2001 From: Dario Tranchitella Date: Thu, 9 Nov 2023 14:59:34 +0100 Subject: [PATCH] feat(ux): namespace oncrete hook to check namespace exsistence Signed-off-by: Dario Tranchitella --- pkg/webhook/namespace/quota.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/webhook/namespace/quota.go b/pkg/webhook/namespace/quota.go index 810a37f1..c85a643a 100644 --- a/pkg/webhook/namespace/quota.go +++ b/pkg/webhook/namespace/quota.go @@ -38,6 +38,14 @@ func (r *quotaHandler) OnCreate(client client.Client, decoder *admission.Decoder } if tnt.IsFull() { + // Checking if the Namespace already exists. + // If this is the case, no need to return the quota exceeded error: + // the Kubernetes API Server will return an AlreadyExists error, + // adhering more to the native Kubernetes experience. + if err := client.Get(ctx, types.NamespacedName{Name: ns.Name}, &corev1.Namespace{}); err == nil { + return nil + } + recorder.Eventf(tnt, corev1.EventTypeWarning, "NamespaceQuotaExceded", "Namespace %s cannot be attached, quota exceeded for the current Tenant", ns.GetName()) response := admission.Denied(NewNamespaceQuotaExceededError().Error())