@@ -18,6 +18,7 @@ var projectsGVR = schema.GroupVersionResource{
1818
1919// Validator validates the namespace admission request.
2020type Validator struct {
21+ deleteNamespaceAdmitter deleteNamespaceAdmitter
2122 psaAdmitter psaLabelAdmitter
2223 projectNamespaceAdmitter projectNamespaceAdmitter
2324 requestWithinLimitAdmitter requestLimitAdmitter
@@ -26,6 +27,7 @@ type Validator struct {
2627// NewValidator returns a new validator used for validation of namespace requests.
2728func NewValidator (sar authorizationv1.SubjectAccessReviewInterface ) * Validator {
2829 return & Validator {
30+ deleteNamespaceAdmitter : deleteNamespaceAdmitter {},
2931 psaAdmitter : psaLabelAdmitter {
3032 sar : sar ,
3133 },
@@ -49,6 +51,7 @@ func (v *Validator) Operations() []admissionv1.OperationType {
4951 return []admissionv1.OperationType {
5052 admissionv1 .Update ,
5153 admissionv1 .Create ,
54+ admissionv1 .Delete ,
5255 }
5356}
5457
@@ -87,7 +90,19 @@ func (v *Validator) ValidatingWebhook(clientConfig admissionv1.WebhookClientConf
8790 }
8891 kubeSystemCreateWebhook .FailurePolicy = admission .Ptr (admissionv1 .Ignore )
8992
90- return []admissionv1.ValidatingWebhook {* standardWebhook , * createWebhook , * kubeSystemCreateWebhook }
93+ deleteNamespaceWebhook := admission .NewDefaultValidatingWebhook (v , clientConfig , admissionv1 .ClusterScope , []admissionv1.OperationType {admissionv1 .Delete })
94+ deleteNamespaceWebhook .Name = admission .CreateWebhookName (v , "delete-namespace" )
95+ deleteNamespaceWebhook .NamespaceSelector = & metav1.LabelSelector {
96+ MatchExpressions : []metav1.LabelSelectorRequirement {
97+ {
98+ Key : corev1 .LabelMetadataName ,
99+ Operator : metav1 .LabelSelectorOpIn ,
100+ Values : []string {"fleet-local" , "local" },
101+ },
102+ },
103+ }
104+
105+ return []admissionv1.ValidatingWebhook {* deleteNamespaceWebhook , * standardWebhook , * createWebhook , * kubeSystemCreateWebhook }
91106}
92107
93108// Admitters returns the psaAdmitter and the projectNamespaceAdmitter for namespaces.
0 commit comments