{{- if .Values.installation.createNamespace }}
apiVersion: v1
kind: Namespace
metadata:
  labels:
  {{- include "kruise-state-metrics.labels" . | nindent 4 }}
  name: {{ .Values.installation.namespace }}
  {{- end }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "kruise-state-metrics.fullname" . }}
  namespace: {{ .Values.installation.namespace }}
  labels:
    {{- include "kruise-state-metrics.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "kruise-state-metrics.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "kruise-state-metrics.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "kruise-state-metrics.serviceAccountName" . }}
      containers:
        - name: {{ .Chart.Name }}
          command:
          - /kruise-state-metrics
          args:
            - --logtostderr=true
            - --v=5
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
          - name: http-metrics
            containerPort: 8080
          - name: telemetry
            containerPort: 8081
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8080
          readinessProbe:
            httpGet:
              path: /
              port: 8081
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
