{{- if .Values.starrocksOperator.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "operator.name" . }}-operator
  namespace: {{ template "operator.namespace" . }}
  labels:
    app: {{ template "operator.name" . }}-operator
  {{- if .Values.starrocksOperator.annotations }}
  annotations:
    {{- toYaml .Values.starrocksOperator.annotations | nindent 4 }}
  {{- end }}
spec:
  selector:
    matchLabels:
      app: {{ template "operator.name" . }}-operator
  replicas: {{ .Values.starrocksOperator.replicaCount }}
  template:
    metadata:
      annotations:
        kubectl.kubernetes.io/default-container: manager
      {{- if .Values.starrocksOperator.annotations }}
        {{- toYaml .Values.starrocksOperator.annotations | nindent 8 }}
      {{- end }}
      labels:
        app: {{ template "operator.name" . }}-operator
        version: {{ $.Chart.Version }}
    spec:
      automountServiceAccountToken: true
      {{- if .Values.starrocksOperator.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml .Values.starrocksOperator.imagePullSecrets | nindent 6 }}
      {{- end }}
      containers:
      - command:
        - /sroperator
        args:
        - --leader-elect
        {{- toYaml .Values.starrocksOperator.log | nindent 8 }}
        {{- if .Values.starrocksOperator.watchNamespace }}
        - --namespace={{ .Values.starrocksOperator.watchNamespace }}
        {{- end }}
        {{- if .Values.starrocksOperator.dnsDomainSuffix }}
        - --dns-domain-suffix={{ .Values.starrocksOperator.dnsDomainSuffix }}
        {{- end }}
        - --volume-name-with-hash={{ .Values.starrocksOperator.volumeNameWithHash }}
        env:
        - name: TZ
          value: {{ .Values.timeZone }}
        {{- if .Values.starrocksOperator.env }}
        {{- toYaml .Values.starrocksOperator.env | nindent 8 }}
        {{- end }}
        image: "{{ .Values.starrocksOperator.image.repository }}:{{ .Values.starrocksOperator.image.tag }}"
        imagePullPolicy: {{ .Values.starrocksOperator.imagePullPolicy }}
        name: manager
        {{- if .Values.starrocksOperator.securityContext }}
        securityContext:
          {{- toYaml .Values.starrocksOperator.securityContext | nindent 10 }}
        {{- end }}
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8081
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8081
          initialDelaySeconds: 5
          periodSeconds: 10
        # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
        resources:
          {{- toYaml .Values.starrocksOperator.resources | nindent 10 }}
      serviceAccountName: {{ template "operator.serviceAccountName" . }}
      terminationGracePeriodSeconds: 10
      {{- if .Values.starrocksOperator.nodeSelector }}
      nodeSelector:
        {{- toYaml .Values.starrocksOperator.nodeSelector | nindent 8 }}
      {{- end }}
      {{- if .Values.starrocksOperator.affinity }}
      affinity:
        {{- toYaml .Values.starrocksOperator.affinity | nindent 8 }}
      {{- end }}
      {{- if .Values.starrocksOperator.tolerations }}
      tolerations:
        {{- toYaml .Values.starrocksOperator.tolerations | nindent 8 }}
      {{- end }}
{{- end }}
