apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: admission-control
  namespace: admission-control
  labels:
    control-plane: controller-manager
    controller-tools.k8s.io: "1.0"
    app.kubernetes.io/name: admission-control
spec:
  selector:
    matchLabels:
      control-plane: controller-manager
      controller-tools.k8s.io: "1.0"
      app.kubernetes.io/name: admission-control
  serviceName: admission-control-service
  template:
    metadata:
      labels:
        control-plane: controller-manager
        controller-tools.k8s.io: "1.0"
        app.kubernetes.io/name: admission-control
    spec:
      containers:
      - command:
        - /root/manager
        image: cloudoperators/admission-control:0.1.0
#        image: lauratest/admission-control:0.1.0
        imagePullPolicy: Always
        name: manager
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: SECRET_NAME
          value: admission-webhook-certs
        - name: WEBHOOK_SERVICE_NAME
          value: admission-control-service
        - name: CERT_DIR
          value: /tmp/cert      
        # enable label validation in admission control
        - name: ADMISSION_CONTROL_LABELS
          value: "false"            
        # enable immutable validation in admission control
        - name: ADMISSION_CONTROL_IMMUTABLES
          value: "true"
        # enable mutal exclusive validation in admission control
        - name: ADMISSION_CONTROL_MUTUAL_EXCLUSIVES
          value: "true"
         # enable mutation webhook
        - name: ADMISSION_CONTROL_MUTATION
          value: "true"            
        resources:
          limits:
            cpu: 100m
            memory: 300Mi
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 443
          name: webhook-server
          protocol: TCP
        volumeMounts:
        - name: cert
          mountPath: /tmp/cert
          readOnly: true
        - name: config-validation-rules-volume
          mountPath: /etc/config/validation
          readOnly: true
        - name: config-validate-wh-volume
          mountPath: /etc/config/validate-wh
          readOnly: true
        - name: config-mutate-wh-volume
          mountPath: /etc/config/mutate-wh
          readOnly: true         
      terminationGracePeriodSeconds: 10
      serviceAccountName: admission-control
      volumes:
      - name: cert
        secret:
          defaultMode: 420
          secretName: admission-webhook-certs
      - name: config-validation-rules-volume
        configMap:
          name: validation-rules-config
      - name: config-validate-wh-volume
        configMap:
          name: validate-wh-config
      - name: config-mutate-wh-volume
        configMap:
          name: mutate-wh-config