{{- if .Values.windows.enabled}}
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ template "sscdpa.fullname" . }}-windows
  namespace: {{ .Release.Namespace }}
{{ include "sscdpa.labels" . | indent 2 }}
spec:
  updateStrategy:
{{ toYaml .Values.windows.updateStrategy | indent 4 }}
  selector:
    matchLabels:
      app: {{ template "sscdpa.name" . }}
  template:
    metadata:
{{ include "sscdpa.labels" . | indent 6 }}
{{- if .Values.windows.podLabels }}
{{- toYaml .Values.windows.podLabels | nindent 8 }}
{{- end }}
{{- if or .Values.windows.podAnnotations .Values.enableArcExtension }}
      annotations:
{{- if .Values.windows.podAnnotations}}
{{- toYaml .Values.windows.podAnnotations | nindent 8 }}
{{- end }}
{{- if .Values.enableArcExtension }}
{{- if .Values.arc.enableMonitoring }}
        prometheus.io/scrape: "true"
        prometheus.io/port: "{{ .Values.metricsAddr }}"
{{- end }}
{{- end }}
{{- end }}
    spec:
      {{- if .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 8 }}
      {{- end }}
      serviceAccountName: csi-secrets-store-provider-azure
      containers:
        - name: provider-azure-installer
          image: "{{ .Values.windows.image.repository }}:{{ .Values.windows.image.tag }}"
          imagePullPolicy: {{ .Values.windows.image.pullPolicy }}
          args:
            - --endpoint=unix://C:\\provider\\azure.sock
            {{- if .Values.logFormatJSON }}
            - --log-format-json={{ .Values.logFormatJSON }}
            {{- end }}
            {{- if .Values.logVerbosity }}
            - -v={{ .Values.logVerbosity }}
            {{- end }}
            {{- if .Values.constructPEMChain }}
            - --construct-pem-chain={{ .Values.constructPEMChain }}
            {{- end }}
            {{- if .Values.windows.customUserAgent }}
            - --custom-user-agent={{ .Values.windows.customUserAgent }}
            {{- end }}
            - --healthz-port={{ .Values.windows.healthzPort }}
            - --healthz-path={{ .Values.windows.healthzPath }}
            - --healthz-timeout={{ .Values.windows.healthzTimeout }}
            {{- if .Values.writeCertAndKeyInSeparateFiles }}
            - --write-cert-and-key-in-separate-files={{ .Values.writeCertAndKeyInSeparateFiles }}
            {{- end }}
          livenessProbe:
            httpGet:
              path: {{ .Values.windows.healthzPath }}
              port: {{ .Values.windows.healthzPort }}
            failureThreshold: 3
            initialDelaySeconds: 5
            timeoutSeconds: 10
            periodSeconds: 30
          resources:
{{ toYaml .Values.windows.resources | indent 12 }}
          {{- if .Values.enableArcExtension }}
          {{- if .Values.Azure.proxySettings.isProxyEnabled }}
          envFrom:
            - secretRef:
                name: arc-proxy-config
          {{- end }}
          {{- end }}
          ports:
            - containerPort: {{ .Values.metricsAddr }}
              name: metrics
              protocol: TCP          
          volumeMounts:
            - name: provider-vol
              mountPath: "C:\\provider"
            {{- if .Values.windows.volumeMounts }}
            {{- toYaml .Values.windows.volumeMounts | nindent 12 }}
            {{- end}}
      affinity:
{{ toYaml .Values.windows.affinity | indent 8 }}
      {{- if .Values.windows.priorityClassName }}
      priorityClassName: {{ .Values.windows.priorityClassName | quote }}
      {{- end }}
      volumes:
        - name: provider-vol
          hostPath:
            path: {{ .Values.windows.providersDir }}
            type: DirectoryOrCreate
        {{- if .Values.windows.volumes }}
        {{- toYaml .Values.windows.volumes | nindent 8 }}
        {{- end}}
      nodeSelector:
        kubernetes.io/os: windows
{{- if .Values.windows.nodeSelector }}
{{- toYaml .Values.windows.nodeSelector | nindent 8 }}
{{- end }}
{{- with .Values.windows.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
{{- end -}}
