apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "metrics-server.fullname" . }}
  labels: {{- include "metrics-server.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels: {{- include "metrics-server.matchLabels" . | nindent 6 }}
  template:
    metadata:
      labels: {{- include "metrics-server.labels" . | nindent 8 }}
      {{- if .Values.podAnnotations }}
      annotations: {{- include "metrics-server.tplValue" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
      {{- end }}
    spec:
{{- include "metrics-server.imagePullSecrets" . | indent 6 }}
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName | quote }}
      {{- end }}
      serviceAccountName: {{ template "metrics-server.serviceAccountName" . }}
      {{- if .Values.affinity }}
      affinity: {{- include "metrics-server.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.nodeSelector }}
      nodeSelector: {{- include "metrics-server.tplValue" (dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.tolerations }}
      tolerations: {{- include "metrics-server.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.hostNetwork }}
      hostNetwork: true
      {{- end }}
      containers:
        - name: metrics-server
          image: {{ template "metrics-server.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
          ports:
            - name: https
              containerPort: {{ .Values.securePort }}
          command:
            - metrics-server
            - --secure-port={{ .Values.securePort }}
            {{- range $key, $value := .Values.extraArgs }}
            - --{{ $key }}={{ $value }}
            {{- end }}
          {{- if .Values.resources }}
          resources: {{- toYaml .Values.resources | nindent 12 }}
          {{- end }}
