{{- if .Values.yawolCloudController.enabled }}
apiVersion: {{ include "deploymentversion" . }}
kind: Deployment
metadata:
  name: yawol-cloud-controller
  namespace: {{ .Values.namespace }}
  labels:
    garden.sapcloud.io/role: controlplane
    app: kubernetes
    role: yawol-cloud-controller
spec:
  revisionHistoryLimit: 0
  replicas: {{ .Values.replicas }}
  selector:
    matchLabels:
      app: kubernetes
      role: yawol-cloud-controller
  template:
    metadata:
{{- if .Values.podAnnotations }}
      annotations:
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
      labels:
        app: kubernetes
        role: yawol-cloud-controller
{{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
{{- end }}
    spec:
      serviceAccountName: yawol-cloud-controller
      containers:
      - name: yawol-cloud-controller
        image: "{{ .Values.yawolCloudController.image.repository }}:{{ default .Chart.AppVersion .Values.yawolCloudController.image.tag }}"
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: metrics
        args:
{{- if .Values.yawolCloudController.additionalArguments }}
{{ toYaml .Values.yawolCloudController.additionalArguments | indent 8 }}
{{- end }}
        - -leader-elect
        {{- if .Values.yawolClassName }}
        - -classname={{ .Values.yawolClassName }}
        {{- end }}
        env:
        {{- if .Values.namespace }}
        - name: CLUSTER_NAMESPACE
          value: {{ .Values.namespace }}
        {{- end }}
        {{- if .Values.yawolOSSecretName }}
        - name: SECRET_NAME
          value: {{ .Values.yawolOSSecretName }}
        {{- end }}
        {{- if .Values.yawolFloatingID }}
        - name: FLOATING_NET_ID
          value: {{ .Values.yawolFloatingID }}
        {{- end }}
        {{- if .Values.yawolNetworkID }}
        - name: NETWORK_ID
          value: {{ .Values.yawolNetworkID }}
        {{- end }}
        {{- if .Values.yawolFlavorID }}
        - name: FLAVOR_ID
          value: {{ .Values.yawolFlavorID }}
        {{- end }}
        {{- if .Values.yawolImageID }}
        - name: IMAGE_ID
          value: {{ .Values.yawolImageID }}
        {{- end }}
        {{- if .Values.yawolAvailabilityZone }}
        - name: AVAILABILITY_ZONE
          value: {{ .Values.yawolAvailabilityZone }}
        {{- end }}
        {{- if .Values.resources.yawolCloudController }}
        resources:
{{ toYaml .Values.resources.yawolCloudController | indent 10 }}
        {{- end }}
{{- if .Values.yawolCloudController.additionalVolumeMounts }}
        volumeMounts:
{{ toYaml .Values.yawolCloudController.additionalVolumeMounts | indent 8 }}
{{- end }}
        securityContext:
          runAsNonRoot: true
          allowPrivilegeEscalation: false
          capabilities:
            drop:
              - ALL
      dnsPolicy: ClusterFirst
      restartPolicy: Always
{{- if .Values.yawolCloudController.additionalVolumes }}
      volumes:
{{ toYaml .Values.yawolCloudController.additionalVolumes | indent 6 }}
{{- end }}
{{- end }}
