Skip to content

Commit

Permalink
feat(ux): namespace oncrete hook to check namespace exsistence
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Tranchitella <[email protected]>
  • Loading branch information
prometherion committed Nov 9, 2023
1 parent 98b5c3f commit 5d2ea24
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/webhook/namespace/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 5d2ea24

Please sign in to comment.