# helm_charts_deployment-admission-server.yaml
{{- if .Values.webhook.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "openebs.fullname" . }}-admission-server
  labels:
    app: admission-webhook
    chart: {{ template "openebs.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
    component: admission-webhook
    openebs.io/component-name: admission-webhook
    openebs.io/version: {{ .Values.release.version }}
spec:
  replicas: {{ .Values.webhook.replicas }}
  strategy:
    type: "Recreate"
    rollingUpdate: null
  selector:
    matchLabels:
      app: admission-webhook
  template:
    metadata:
      labels:
        app: admission-webhook
        name: admission-webhook
        release: {{ .Release.Name }}
        openebs.io/version: {{ .Values.release.version }}
        openebs.io/component-name: admission-webhook
    spec:
{{- if .Values.webhook.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.webhook.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.webhook.tolerations }}
      tolerations:
{{ toYaml .Values.webhook.tolerations | indent 8 }}
{{- end }}
{{- if .Values.webhook.affinity }}
      affinity:
{{ toYaml .Values.webhook.affinity | indent 8 }}
{{- end }}
      serviceAccountName: {{ template "openebs.serviceAccountName" . }}
      containers:
        - name: admission-webhook
          image: "{{ .Values.image.repository }}{{ .Values.webhook.image }}:{{ .Values.webhook.imageTag }}"
          imagePullPolicy: Always 
          args:
            - -alsologtostderr
            - -v=2
            - 2>&1
          env:
            - name: OPENEBS_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          # Process name used for matching is limited to the 15 characters
          # present in the pgrep output.
          # So fullname can't be used here with pgrep (>15 chars).A regular expression
          # Anchor `^` : matches any string that starts with `admission-serve`
          # `.*`: matche any string that has `admission-serve` followed by zero or more char
          # that matches the entire command name has to specified.
          livenessProbe:
            exec:
              command:
              - sh
              - -c
              - test `pgrep -c "^admission-serve.*"` = 1
            initialDelaySeconds: {{ .Values.webhook.healthCheck.initialDelaySeconds }}
            periodSeconds: {{ .Values.webhook.healthCheck.periodSeconds }}
{{- end }}