{{- if eq .Values.global.deploymentMode "development" }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: "{{ .Values.kafkadrop.name }}"
  labels:
    app.kubernetes.io/name: {{ .Values.kafkadrop.image.name }}
spec:
  replicas: {{ .Values.kafkadrop.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ .Values.kafkadrop.name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ .Values.kafkadrop.name }}
        collect.logs: "plain-text"
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      initContainers:
        - name: init
          image: {{ template "imageRegistry" . -}} busybox
          command: [ "sh", "-c" ]
          args: [ "while ! nc -w 1 {{ .Values.kafkadrop.brokerConnect }} {{ .Values.kafkadrop.port }} </dev/null; do sleep 10; done;" ]
      containers:
        - name: {{ .Values.kafkadrop.name }}
          image: "{{ template "imageRegistry" . -}} {{ .Values.edpProject }}/{{ .Values.kafkadrop.image.name }}:{{ .Values.kafkadrop.image.version }}"
          env:
          - name: KAFKA_BROKERCONNECT
            value: "{{ .Values.kafkadrop.brokerConnect }}:{{ .Values.kafkadrop.port }}"
          - name: KAFKA_PROPERTIES
            value: "{{ .Values.kafkadrop.properties }}"
          - name: KAFKA_TRUSTSTORE
            value: "{{ .Values.kafkadrop.truststore }}"
          - name: KAFKA_KEYSTORE
            value: "{{ .Values.kafkadrop.keystore }}"
          - name: JVM_OPTS
            value: "{{ .Values.kafkadrop.jvm.opts }}"
          - name: JMX_PORT
            value: "{{ .Values.kafkadrop.jmx.port }}"
          - name: HOST
            value: "{{ .Values.kafkadrop.host }}"
          - name: SERVER_SERVLET_CONTEXTPATH
            value: "{{ .Values.kafkadrop.server.servlet.contextPath | trimSuffix "/" }}"
          - name: KAFKA_PROPERTIES_FILE
            value: "{{ .Values.kafkadrop.propertiesFile }}"
          - name: KAFKA_TRUSTSTORE_FILE
            value: "{{ .Values.kafkadrop.truststoreFile }}"
          - name: KAFKA_KEYSTORE_FILE
            value: "{{ .Values.kafkadrop.keystoreFile }}"
          - name: SERVER_PORT
            value: "{{ .Values.kafkadrop.server.port }}"
          - name: CMD_ARGS
  {{- if .Values.mountProtoDesc.enabled }}
            value: "--message.format=PROTOBUF --protobufdesc.directory=/protodesc/ {{ .Values.kafkadrop.cmdArgs }}"
  {{- else }}
            value: "{{ .Values.kafkadrop.cmdArgs }}"
  {{- end }}
          ports:
            - name: http
              containerPort: 9000
              protocol: TCP
            - name: jvm-metrics
              containerPort: 9999
              protocol: TCP
          livenessProbe:
            httpGet:
              path: "{{ .Values.kafkadrop.server.servlet.contextPath | trimSuffix "/" }}/actuator/health"
              port: http
            initialDelaySeconds: 180
            periodSeconds: 30
            timeoutSeconds: 10
          readinessProbe:
            httpGet:
              path: "{{ .Values.kafkadrop.server.servlet.contextPath | trimSuffix "/" }}/actuator/health"
              port: http
            initialDelaySeconds: 20
            periodSeconds: 5
            timeoutSeconds: 10
          resources:
  {{ toYaml .Values.kafkadropresources | indent 12 }}
  {{- with .Values.nodeSelector }}
      nodeSelector:
  {{ toYaml . | indent 8 }}
  {{- end }}
  {{- with .Values.affinity }}
      affinity:
  {{ toYaml . | indent 8 }}
  {{- end }}
  {{- with .Values.tolerations }}
      tolerations:
  {{ toYaml . | indent 8 }}
  {{- end }}
  {{- if .Values.mountProtoDesc.enabled }}
          volumeMounts:
            - mountPath: /protodesc/
              name: proto-desc
      volumes:
        - name: proto-desc
          hostPath:
            path: {{ .Values.mountProtoDesc.hostPath }}
            type: Directory
  {{- end }}
{{- end }}
