apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "chaoskube.fullname" . }}
  labels:
{{ include "labels.standard" . | indent 4 }}
spec:
  replicas: {{ .Values.replicas }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "chaoskube.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
{{ include "labels.standard" . | indent 8 }}
    {{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
    {{- end }}
    {{- if .Values.podAnnotations }}
      annotations:
{{ toYaml .Values.podAnnotations | indent 8 }}
    {{- end }}
    spec:
      containers:
        - name: {{ .Values.name }}
          image: {{ .Values.image }}:{{ .Values.imageTag }}
          args:
            - --interval={{ .Values.interval }}
            - --labels={{ .Values.labels }}
            {{- if .Values.kinds }}
            - --kinds={{ .Values.kinds }}
            {{- end }}
            - --annotations={{ .Values.annotations }}
            - --namespaces={{ .Values.namespaces }}
            {{- if not .Values.dryRun }}
            - --no-dry-run
            {{- end }}
            {{- if .Values.includedPodNames }}
            - --included-pod-names={{ .Values.includedPodNames }}
            {{- end }}
            {{- if .Values.excludedPodNames }}
            - --excluded-pod-names={{ .Values.excludedPodNames }}
            {{- end }}
            - --excluded-weekdays={{ .Values.excludedWeekdays }}
            - --excluded-times-of-day={{ .Values.excludedTimesOfDay }}
            - --excluded-days-of-year={{ .Values.excludedDaysOfYear }}
            - --timezone={{ .Values.timezone }}
            {{- if .Values.logFormat }}
            - --log-format={{ .Values.logFormat }}
            {{- end }}
            {{- if .Values.debug }}
            - --debug
            {{- end }}
            - --minimum-age={{ .Values.minimumAge }}
            - --grace-period={{ .Values.gracePeriod }}
          {{- if .Values.metrics.enabled }}
            - --metrics-address=:{{ .Values.metrics.port }}
          {{- else }}
            - --metrics-address=
          {{- end }}
          {{- if .Values.metrics.enabled }}
          ports:
            - name: metrics
              containerPort: {{ .Values.metrics.port }}
          {{- end }}
          resources:
{{ toYaml .Values.resources | indent 12 }}
          securityContext:
            runAsNonRoot: true
            runAsUser: 65534
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
{{- if .Values.priorityClassName }}
      priorityClassName: "{{ .Values.priorityClassName }}"
{{- end }}
      serviceAccountName: {{ if .Values.rbac.create }}{{ printf "%s-%s" .Release.Name .Values.name }}{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }}
{{- if .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 8 }}
{{- end }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
