apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "hub-agent.fullname" . }}
  namespace: {{ .Values.namespace }}
  labels:
    {{- include "hub-agent.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      {{- include "hub-agent.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "hub-agent.selectorLabels" . | nindent 8 }}
    spec:
      serviceAccountName: {{ include "hub-agent.fullname" . }}-sa
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
            - --leader-elect=true
            - --enable-webhook={{ .Values.enableWebhook }}
            - --webhook-service-name={{ .Values.webhookServiceName }}
            - --enable-guard-rail={{ .Values.enableGuardRail }}
            - --whitelisted-users=system:serviceaccount:fleet-system:hub-agent-sa
            - --webhook-client-connection-type={{.Values.webhookClientConnectionType}}
            - --v={{ .Values.logVerbosity }}
            - -add_dir_header
            - --enable-v1alpha1-apis={{ .Values.enableV1Alpha1APIs }}
            - --enable-v1beta1-apis={{ .Values.enableV1Beta1APIs }}
            - --enable-cluster-inventory-apis={{ .Values.enableClusterInventoryAPI }}
            - --enable-staged-update-run-apis={{ .Values.enableStagedUpdateRunAPIs }}
            - --enable-eviction-apis={{ .Values.enableEvictionAPIs}}
            - --max-concurrent-cluster-placement={{ .Values.MaxConcurrentClusterPlacement }}
            - --concurrent-resource-change-syncs={{ .Values.ConcurrentResourceChangeSyncs }}
            - --log_file_max_size={{ .Values.logFileMaxSize }}
            - --max-fleet-size={{ .Values.MaxFleetSizeSupported }}
            - --hub-api-qps={{ .Values.hubAPIQPS }}
            - --hub-api-burst={{ .Values.hubAPIBurst }}
            - --force-delete-wait-time={{ .Values.forceDeleteWaitTime }}
            - --cluster-unhealthy-threshold={{ .Values.clusterUnhealthyThreshold }}
          ports:
            - name: metrics
              containerPort: 8080
              protocol: TCP
            - name: healthz
              containerPort: 8081
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /healthz
              port: healthz
          readinessProbe:
            httpGet:
              path: /readyz
              port: healthz
          env:
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.namespace
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
