{{- if and .Values.gc.enable -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "node-feature-discovery.fullname" . }}-gc
  namespace: {{ include "node-feature-discovery.namespace" . }}
  labels:
    {{- include "node-feature-discovery.labels" . | nindent 4 }}
    role: gc
  {{- with .Values.gc.deploymentAnnotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  replicas: {{ .Values.gc.replicaCount | default 1 }}
  revisionHistoryLimit: {{ .Values.gc.revisionHistoryLimit }}
  selector:
    matchLabels:
      {{- include "node-feature-discovery.selectorLabels" . | nindent 6 }}
      role: gc
  template:
    metadata:
      labels:
        {{- include "node-feature-discovery.selectorLabels" . | nindent 8 }}
        role: gc
      {{- with .Values.gc.annotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      serviceAccountName: {{ include "node-feature-discovery.gc.serviceAccountName" . }}
      dnsPolicy: {{ .Values.gc.dnsPolicy }}
    {{- with .Values.priorityClassName }}
      priorityClassName: {{ . }}
    {{- end }}
      imagePullSecrets: {{ include "node-feature-discovery.imagePullSecrets" . }}
      securityContext:
        {{- toYaml .Values.gc.podSecurityContext | nindent 8 }}
      hostNetwork: {{ .Values.gc.hostNetwork }}
      containers:
      - name: gc
        image: "{{ include "node-feature-discovery.system_default_registry" . }}{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
        imagePullPolicy: "{{ .Values.image.pullPolicy }}"
        livenessProbe:
          httpGet:
            path: /healthz
            port: http
        {{- with .Values.gc.livenessProbe.initialDelaySeconds }}
          initialDelaySeconds: {{ . }}
        {{- end }}
        {{- with .Values.gc.livenessProbe.failureThreshold }}
          failureThreshold: {{ . }}
        {{- end }}
        {{- with .Values.gc.livenessProbe.periodSeconds }}
          periodSeconds: {{ . }}
        {{- end }}
        {{- with .Values.gc.livenessProbe.timeoutSeconds }}
          timeoutSeconds: {{ . }}
        {{- end }}
        readinessProbe:
          httpGet:
            path: /healthz
            port: http
        {{- with .Values.gc.readinessProbe.initialDelaySeconds }}
          initialDelaySeconds: {{ . }}
        {{- end }}
        {{- with .Values.gc.readinessProbe.failureThreshold }}
          failureThreshold: {{ . }}
        {{- end }}
        {{- with .Values.gc.readinessProbe.periodSeconds }}
          periodSeconds: {{ . }}
        {{- end }}
        {{- with .Values.gc.readinessProbe.timeoutSeconds }}
          timeoutSeconds: {{ . }}
        {{- end }}
        {{- with .Values.gc.readinessProbe.successThreshold }}
          successThreshold: {{ . }}
        {{- end }}
        env:
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
      {{- with .Values.gc.extraEnvs }}
        {{- toYaml . | nindent 8 }}
      {{- end}}
        command:
          - "nfd-gc"
        args:
          {{- if .Values.gc.interval | empty | not }}
          - "-gc-interval={{ .Values.gc.interval }}"
          {{- end }}
          {{- with .Values.gc.extraArgs }}
          {{- toYaml . | nindent 10 }}
          {{- end }}
        resources:
      {{- toYaml .Values.gc.resources | nindent 12 }}
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop: [ "ALL" ]
          readOnlyRootFilesystem: true
          runAsNonRoot: true
        ports:
          - name: http
            containerPort: {{ .Values.gc.port | default "8080"}}

    {{- with .Values.gc.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.gc.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.gc.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
{{- end }}
