apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "hub-net-controller-manager.fullname" . }}
  namespace: {{ .Values.fleetSystemNamespace }}
  labels:
    {{- include "hub-net-controller-manager.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "hub-net-controller-manager.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "hub-net-controller-manager.selectorLabels" . | nindent 8 }}
    spec:
      serviceAccountName:  {{ include "hub-net-controller-manager.fullname" . }}-sa
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
            - --leader-election-namespace={{ .Values.leaderElectionNamespace }}
            - --v={{ .Values.logVerbosity }}
            - --add_dir_header
            - --force-delete-wait-time={{ .Values.forceDeleteWaitTime }}
            - --enable-traffic-manager-feature={{ .Values.enableTrafficManagerFeature }}
            {{- if .Values.enableTrafficManagerFeature }}
            - --cloud-config=/etc/kubernetes/provider/azure.json
            {{- end }}
          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
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          {{- if .Values.enableTrafficManagerFeature }}
          volumeMounts:
          - name: cloud-provider-config
            mountPath: /etc/kubernetes/provider
            readOnly: true
          {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.enableTrafficManagerFeature }}
      volumes:
      - name: cloud-provider-config
        secret:
          secretName: azure-cloud-config
      {{- end }}
