# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "hertzbeat.manager" . }}
  labels:
    {{- include "hertzbeat.labels" . | nindent 4 }}
    component: manager
spec:
  replicas: 1
  selector:
    matchLabels:
      {{- include "hertzbeat.selectorLabels" . | nindent 6 }}
      component: manager
  template:
    metadata:
      {{- with .Values.manager.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "hertzbeat.selectorLabels" . | nindent 8 }}
        component: manager
    spec:
      securityContext:
        {{- toYaml .Values.manager.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.manager.securityContext | nindent 12 }}
          image: "{{ .Values.manager.image.repository }}:{{ .Values.manager.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.manager.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 1157
              protocol: TCP
            - name: cluster
              containerPort: 1158
              protocol: TCP
          livenessProbe:
            tcpSocket:
              port: 1157
          readinessProbe:
            tcpSocket:
              port: 1157
          volumeMounts:
            - mountPath: /opt/hertzbeat/config/application.yml
              subPath: application.yml
              name: application
            - mountPath: /opt/hertzbeat/config/sureness.yml
              subPath: sureness.yml
              name: sureness
          resources:
            {{- toYaml .Values.manager.resources | nindent 12 }}
      volumes:
        - name: application
          configMap:
            name: {{ include "hertzbeat.manager" . }}
        - name: sureness
          configMap:
            name: {{ include "hertzbeat.manager" . }}
      {{- with .Values.manager.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.manager.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.manager.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
