feat(ux): namespace oncrete hook to check namespace exsistence

Signed-off-by: Dario Tranchitella <dario@tranchitella.eu>
This commit is contained in:
Dario Tranchitella
2023-11-09 15:48:04 +01:00
parent 98b5c3f076
commit 25b4a35b65
+8
View File
@@ -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())