apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "knowstreaming-manager.fullname" . }}
  labels:
    app: {{ template "knowstreaming-manager.name" . }}
    chart: {{ template "knowstreaming-manager.chart" . }}
    {{- include "knowstreaming-manager.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "knowstreaming-manager.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        release: {{ .Release.Name | quote }}
        {{- include "knowstreaming-manager.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      initContainers:
      - name: init-config
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        command: ['/bin/bash', '/conf/init_es_index.sh']
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
        volumeMounts:
          - name: configmap
            mountPath: /conf
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command: ['/usr/bin/java', '-Xmx8g', '-Xms8g', '-jar', '/km-rest.jar', '--spring.config.location=/conf/application-test.yml']
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: TZ
              value: Asia/Shanghai
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /ks-km/api/v3/open/health
              port: http
          readinessProbe:
            httpGet:
              path: /ks-km/api/v3/open/health
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
            - name: configmap
              mountPath: /conf
      volumes:
        - name: configmap
          configMap:
            name: {{ include "knowstreaming-manager.fullname" . }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
