apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "kube-state-metrics.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels: {{- include "kube-state-metrics.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels: {{- include "kube-state-metrics.matchLabels" . | nindent 6 }}
  replicas: {{ .Values.replicaCount }}
  strategy: {{- toYaml .Values.updateStrategy | nindent 4 }}
  minReadySeconds: {{ .Values.minReadySeconds }}
  template:
    metadata:
      {{- if .Values.podAnnotations }}
      annotations: {{- include "kube-state-metrics.tplValue" ( dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
      {{- end }}
      labels: {{- include "kube-state-metrics.labels" . | nindent 8 }}
        {{- if .Values.podLabels }}
        {{- toYaml .Values.podLabels | indent 8 }}
        {{- end }}
    spec:
{{- include "kube-state-metrics.imagePullSecrets" . | indent 6 }}
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName }}
      {{- end }}
      {{- if .Values.securityContext.enabled }}
      securityContext:
        runAsUser: {{ .Values.securityContext.runAsUser }}
        fsGroup: {{ .Values.securityContext.fsGroup }}
      {{- end }}
      hostNetwork: {{ .Values.hostNetwork }}
      serviceAccountName: {{ template "kube-state-metrics.serviceAccountName" . }}
      containers:
        - name: kube-state-metrics
          image: {{ template "kube-state-metrics.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
            {{- if .Values.collectors.certificatesigningrequests }}
            - --collectors=certificatesigningrequests
            {{- end }}
            {{- if .Values.collectors.configmaps }}
            - --collectors=configmaps
            {{- end }}
            {{- if .Values.collectors.cronjobs }}
            - --collectors=cronjobs
            {{- end }}
            {{- if .Values.collectors.daemonsets }}
            - --collectors=daemonsets
            {{- end }}
            {{- if .Values.collectors.deployments }}
            - --collectors=deployments
            {{- end }}
            {{- if .Values.collectors.endpoints }}
            - --collectors=endpoints
            {{- end }}
            {{- if .Values.collectors.horizontalpodautoscalers }}
            - --collectors=horizontalpodautoscalers
            {{- end }}
            {{- if .Values.collectors.ingresses }}
            - --collectors=ingresses
            {{- end }}
            {{- if .Values.collectors.jobs }}
            - --collectors=jobs
            {{- end }}
            {{- if .Values.collectors.limitranges }}
            - --collectors=limitranges
            {{- end }}
            {{- if .Values.collectors.mutatingwebhookconfigurations }}
            - --collectors=mutatingwebhookconfigurations
            {{- end }}
            {{- if .Values.collectors.namespaces }}
            - --collectors=namespaces
            {{- end }}
            {{- if .Values.collectors.networkpolicies }}
            - --collectors=networkpolicies
            {{- end }}
            {{- if .Values.collectors.nodes }}
            - --collectors=nodes
            {{- end }}
            {{- if .Values.collectors.persistentvolumeclaims }}
            - --collectors=persistentvolumeclaims
            {{- end }}
            {{- if .Values.collectors.persistentvolumes }}
            - --collectors=persistentvolumes
            {{- end }}
            {{- if .Values.collectors.poddisruptionbudgets }}
            - --collectors=poddisruptionbudgets
            {{- end }}
            {{- if .Values.collectors.pods }}
            - --collectors=pods
            {{- end }}
            {{- if .Values.collectors.replicasets }}
            - --collectors=replicasets
            {{- end }}
            {{- if .Values.collectors.replicationcontrollers }}
            - --collectors=replicationcontrollers
            {{- end }}
            {{- if .Values.collectors.resourcequotas }}
            - --collectors=resourcequotas
            {{- end }}
            {{- if .Values.collectors.secrets }}
            - --collectors=secrets
            {{- end }}
            {{- if .Values.collectors.services }}
            - --collectors=services
            {{- end }}
            {{- if .Values.collectors.statefulsets }}
            - --collectors=statefulsets
            {{- end }}
            {{- if .Values.collectors.storageclasses }}
            - --collectors=storageclasses
            {{- end }}
            {{- if .Values.collectors.verticalpodautoscalers }}
            - --collectors=verticalpodautoscalers
            {{- end }}
            {{- if .Values.collectors.validatingwebhookconfigurations }}
            - --collectors=validatingwebhookconfigurations
            {{- end }}
            {{- if .Values.collectors.volumeattachments }}
            - --collectors=volumeattachments
            {{- end }}
            {{- if .Values.namespace }}
            - --namespace={{ .Values.namespace }}
            {{- end }}
            {{- range $key, $value := .Values.extraArgs }}
            {{- if $value }}
            - --{{ $key }}={{ $value }}
            {{- else }}
            - --{{ $key }}
            {{- end }}
            {{- end }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          {{- if .Values.livenessProbe.enabled }}
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
            successThreshold: {{ .Values.livenessProbe.successThreshold }}
            failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
          {{- end }}
          {{- if .Values.readinessProbe.enabled }}
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
            periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
            timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
            successThreshold: {{ .Values.readinessProbe.successThreshold }}
            failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
          {{- end }}
          {{- if .Values.resources }}
          resources: {{- toYaml .Values.resources | nindent 12 }}
          {{- end }}
      {{- if .Values.nodeSelector }}
      nodeSelector: {{- include "kube-state-metrics.tplValue" (dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.tolerations }}
      tolerations: {{- include "kube-state-metrics.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.affinity }}
      affinity: {{- include "kube-state-metrics.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
      {{- end }}
