---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
  name: {{.SRIOVMutatingWebhookName}}
  annotations:
    {{- if eq .ClusterType "openshift" }}
    service.beta.openshift.io/inject-cabundle: "true"
    {{- else if and (not .CaBundle) (eq .ClusterType "kubernetes") }}
    cert-manager.io/inject-ca-from: {{.Namespace}}/operator-webhook-service
    {{- end }}
webhooks:
  - name: operator-webhook.sriovnetwork.openshift.io
    sideEffects: None
    admissionReviewVersions: ["v1", "v1beta1"]
    failurePolicy: Fail
    clientConfig:
      service:
        name: operator-webhook-service
        namespace: {{.Namespace}}
        path: "/mutating-custom-resource"
      {{- if and (.CaBundle) (eq .ClusterType "kubernetes") }}
      caBundle: "{{.CaBundle}}"
      {{- end}}
    rules:
      - operations: [ "CREATE", "UPDATE" ]
        apiGroups: ["sriovnetwork.openshift.io"]
        apiVersions: ["v1"]
        resources: ["sriovnetworknodepolicies"]

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: {{.SRIOVMutatingWebhookName}}
  annotations:
    {{- if eq .ClusterType "openshift" }}
    service.beta.openshift.io/inject-cabundle: "true"
    {{- else if and (not .CaBundle) (eq .ClusterType "kubernetes") }}
    cert-manager.io/inject-ca-from: {{.Namespace}}/operator-webhook-service
    {{- end }}
webhooks:
  - name: operator-webhook.sriovnetwork.openshift.io
    sideEffects: None
    admissionReviewVersions: ["v1", "v1beta1"]
    failurePolicy: Fail
    clientConfig:
      service:
        name: operator-webhook-service
        namespace: {{.Namespace}}
        path: "/validating-custom-resource"
      {{- if and (.CaBundle) (eq .ClusterType "kubernetes") }}
      caBundle: "{{.CaBundle}}"
      {{- end }}
    rules:
      - operations: [ "CREATE", "UPDATE", "DELETE" ]
        apiGroups: ["sriovnetwork.openshift.io"]
        apiVersions: ["v1"]
        resources: ["sriovnetworknodepolicies"]
