{{- if .Values.externalKeyStore.enabled }}
---
apiVersion: v1
kind: Secret
metadata:
  name:  gerrit-operator-ssl
  namespace: {{ .Release.Namespace }}
data:
  keystore.jks: {{ .Values.externalKeyStore.jks }}
  keystore.password: {{ .Values.externalKeyStore.password | b64enc }}
type: Opaque
{{- end }}


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gerrit-operator
  namespace: {{ .Release.Namespace }}
spec:
  selector:
    matchLabels:
      app: gerrit-operator
  template:
    metadata:
      labels:
        app: gerrit-operator
    spec:
      serviceAccountName: gerrit-operator
      {{- with .Values.image.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
      - name: operator
        image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.org }}/{{ .Values.image.name }}:{{ .Values.image.tag | default "latest" }}
        imagePullPolicy: {{ .Values.image.imagePullPolicy }}
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: INGRESS
          value: {{ .Values.ingress.type }}
        ports:
        - containerPort: 80
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
            scheme: HTTPS
          initialDelaySeconds: 10
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
            scheme: HTTPS
          initialDelaySeconds: 30
        {{- if .Values.externalKeyStore.enabled }}
        volumeMounts:
        - name: ssl
          readOnly: true
          mountPath: /operator
        {{- end }}
      {{- if .Values.externalKeyStore.enabled }}
      volumes:
      - name: ssl
        secret:
          secretName: gerrit-operator-ssl
      {{- end }}
