apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "flux-operator.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "flux-operator.labels" . | nindent 4 }}
    {{- with .Values.commonLabels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .Values.commonAnnotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  selector:
    matchLabels:
      {{- include "flux-operator.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8080"
        prometheus.io/path: "/metrics"
        {{- with .Values.commonAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      labels:
        {{- include "flux-operator.labels" . | nindent 8 }}
        {{- with .Values.commonLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.priorityClassName }}
      priorityClassName: {{ . }}
      {{- end }}
      {{- with .Values.image.pullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "flux-operator.serviceAccountName" . }}
      {{- with .Values.podSecurityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.hostNetwork }}
      hostNetwork: true
      {{- end }}
      containers:
        - name: manager
          args:
            - --log-level={{ .Values.logLevel }}
            {{- if .Values.multitenancy.enabled }}
            - --default-service-account={{ .Values.multitenancy.defaultServiceAccount }}
            {{- end }}
            {{- range .Values.extraArgs }}
            - {{ . }}
            {{- end }}
          env:
            - name: RUNTIME_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: REPORTING_INTERVAL
              value: {{ .Values.reporting.interval }}
            {{- with .Values.marketplace.type }}
            - name: MARKETPLACE_TYPE
              value: {{ . }}
            {{- end }}
            {{- with .Values.marketplace.account }}
            - name: MARKETPLACE_ACCOUNT
              value: {{ . }}
            {{- end }}
            {{- with .Values.marketplace.license }}
            - name: MARKETPLACE_LICENSE
              value: {{ . }}
            {{- end }}
            {{- if .Values.extraEnvs }}
              {{- toYaml .Values.extraEnvs | nindent 12 }}
            {{- end }}
            {{- include "cozy.kubernetes_envs" . | nindent 12 }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: "{{ .Values.image.imagePullPolicy }}"
          ports:
            - name: http-metrics
              containerPort: 8080
              protocol: TCP
            - name: http
              containerPort: 8081
              protocol: TCP
          livenessProbe:
            {{- toYaml .Values.livenessProbe | nindent 12 }}
          readinessProbe:
            {{- toYaml .Values.readinessProbe | nindent 12 }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
            - name: temp
              mountPath: /tmp
      volumes:
        - name: temp
          emptyDir: {}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}

