# grafana_charts_no-downscale-webhook.yaml
{{- if .Values.webhooks.enabled -}}
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: no-downscale-{{ .Release.Namespace }}
  labels:
    grafana.com/inject-rollout-operator-ca: "true"
    grafana.com/namespace: {{ .Release.Namespace | quote }}
    {{- include "rollout-operator.labels" . | nindent 4 }}
webhooks:
  - name: no-downscale-{{ .Release.Namespace }}.grafana.com
    clientConfig:
      service:
        namespace: {{ .Release.Namespace | quote }}
        name: {{ include "rollout-operator.fullname" . }}
        path: /admission/no-downscale
        port: 443
    rules:
      - operations:
          - UPDATE
        apiGroups:
          - apps
        apiVersions:
          - v1
        resources:
          - statefulsets
          - statefulsets/scale
        scope: Namespaced
    admissionReviewVersions:
      - v1
    {{- if not (kindIs "invalid" .Values.namespaceSelector) }}
    namespaceSelector:
      {{- if .Values.namespaceSelector.matchLabels }}
      matchLabels:
        {{- toYaml .Values.namespaceSelector.matchLabels | nindent 8 }}
      {{- with .Values.namespaceSelector.matchExpressions }}
      matchExpressions:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- else }}
      matchLabels:
        kubernetes.io/metadata.name: {{ .Release.Namespace | quote }}
      {{- with .Values.namespaceSelector.matchExpressions }}
      matchExpressions:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- end }}
    {{- end }}
    {{- with .Values.webhooks.objectSelector }}
    objectSelector:
      {{- toYaml . | nindent 6 }}
    {{- end }}
    sideEffects: None
    failurePolicy: {{.Values.webhooks.failurePolicy}}
{{- end -}}