{{ $fullName := include "mariadb-operator.fullname" . }}
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
  name: {{ $fullName }}-webhook
  labels:
    {{ include "mariadb-operator-webhook.labels" . | nindent 4 }}
  annotations:
    {{- if .Values.webhook.cert.certManager.enabled }}
    cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "mariadb-operator.fullname" . }}-webhook-cert
    {{- else }}
    k8s.mariadb.com/webhook: ""
    {{- end }}
    {{ with .Values.webhook.annotations }}
    {{ toYaml . | indent 4 }}
    {{ end }}
webhooks:
- admissionReviewVersions:
  - v1
  clientConfig:
    service:
      name: {{ $fullName }}-webhook
      namespace: {{ .Release.Namespace }}
      path: /mutate-k8s-mariadb-com-v1alpha1-mariadb
  failurePolicy: Fail
  name: mmariadb.kb.io
  rules:
  - apiGroups:
    - k8s.mariadb.com
    apiVersions:
    - v1alpha1
    operations:
    - CREATE
    - UPDATE
    resources:
    - mariadbs
  sideEffects: None
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: {{ $fullName }}-webhook
  labels:
    {{ include "mariadb-operator-webhook.labels" . | nindent 4 }}
  annotations:
    {{- if .Values.webhook.cert.certManager.enabled }}
    cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ include "mariadb-operator.fullname" . }}-webhook-cert
    {{- else }}
    k8s.mariadb.com/webhook: ""
    {{- end }}
    {{ with .Values.webhook.annotations }}
    {{ toYaml . | indent 4 }}
    {{ end }}
webhooks:
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-backup
    failurePolicy: Fail
    name: vbackup.kb.io
    rules:
      - apiGroups:
          - k8s.mariadb.com
        apiVersions:
          - v1alpha1
        operations:
          - CREATE
          - UPDATE
        resources:
          - backups
    sideEffects: None
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-connection
    failurePolicy: Fail
    name: vconnection.kb.io
    rules:
      - apiGroups:
          - k8s.mariadb.com
        apiVersions:
          - v1alpha1
        operations:
          - CREATE
          - UPDATE
        resources:
          - connections
    sideEffects: None
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-database
    failurePolicy: Fail
    name: vdatabase.kb.io
    rules:
      - apiGroups:
          - k8s.mariadb.com
        apiVersions:
          - v1alpha1
        operations:
          - CREATE
          - UPDATE
        resources:
          - databases
    sideEffects: None
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-grant
    failurePolicy: Fail
    name: vgrant.kb.io
    rules:
      - apiGroups:
          - k8s.mariadb.com
        apiVersions:
          - v1alpha1
        operations:
          - CREATE
          - UPDATE
        resources:
          - grants
    sideEffects: None
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-mariadb
    failurePolicy: Fail
    name: vmariadb.kb.io
    rules:
      - apiGroups:
          - k8s.mariadb.com
        apiVersions:
          - v1alpha1
        operations:
          - CREATE
          - UPDATE
        resources:
          - mariadbs
    sideEffects: None
  - admissionReviewVersions:
    - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-maxscale
    failurePolicy: Fail
    name: vmaxscale.kb.io
    rules:
    - apiGroups:
      - k8s.mariadb.com
      apiVersions:
      - v1alpha1
      operations:
      - CREATE
      - UPDATE
      resources:
      - maxscales
    sideEffects: None
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-restore
    failurePolicy: Fail
    name: vrestore.kb.io
    rules:
      - apiGroups:
          - k8s.mariadb.com
        apiVersions:
          - v1alpha1
        operations:
          - CREATE
          - UPDATE
        resources:
          - restores
    sideEffects: None
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-sqljob
    failurePolicy: Fail
    name: vsqljob.kb.io
    rules:
      - apiGroups:
          - k8s.mariadb.com
        apiVersions:
          - v1alpha1
        operations:
          - CREATE
          - UPDATE
        resources:
          - sqljobs
    sideEffects: None
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: {{ $fullName }}-webhook
        namespace: {{ .Release.Namespace }}
        path: /validate-k8s-mariadb-com-v1alpha1-user
    failurePolicy: Fail
    name: vuser.kb.io
    rules:
      - apiGroups:
          - k8s.mariadb.com
        apiVersions:
          - v1alpha1
        operations:
          - CREATE
          - UPDATE
        resources:
          - users
    sideEffects: None