apiVersion: v1
kind: ServiceAccount
metadata:
  name: azure-cns
  namespace: kube-system
  labels:
    addonmanager.kubernetes.io/mode: EnsureExists
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: azure-cns-win
  namespace: kube-system
  labels:
    app: azure-cns-win
spec:
  selector:
    matchLabels:
      k8s-app: azure-cns-win
  template:
    metadata:
      labels:
        k8s-app: azure-cns-win
      annotations:
        cluster-autoscaler.kubernetes.io/daemonset-pod: "true"
        prometheus.io/port: "10092"
    spec:
      securityContext:
        windowsOptions:
          hostProcess: true
          runAsUserName: "NT AUTHORITY\\SYSTEM"
      containers:
        - name: cns-container
          image: acnpublic.azurecr.io/azure-cns:v1.4.26-9-gc40fb852
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
          command: ["powershell.exe"]
          args: 
            [ 
              '.\setkubeconfigpath.ps1', ";",
              'powershell.exe', '.\azure-cns.exe',
              '-c', "tcp://$(CNSIpAddress):$(CNSPort)",
              '-t', "$(CNSLogTarget)",
              '-o', "$(CNSLogDir)",
              '-storefilepath', "$(CNSStoreFilePath)",
              '-config-path', "%CONTAINER_SANDBOX_MOUNT_POINT%\\$(CNS_CONFIGURATION_PATH)",
              '--kubeconfig', '.\kubeconfig',
            ]
          volumeMounts:
            - name: log
              mountPath: /k
            - name: cns-config
              mountPath: etc/azure-cns
          ports:
            - containerPort: 10090
              name: api
            - containerPort: 10092
              name: metrics
          env:
            - name: CNSIpAddress
              value: "127.0.0.1"
            - name: CNSPort
              value: "10090"
            - name: CNSLogTarget
              value: "stdoutfile"
            - name: CNSLogDir
              value: /k
            - name: CNSStoreFilePath
              value: /k/
            - name: CNS_CONFIGURATION_PATH
              value: etc/azure-cns/cns_config.json
            - name: NODENAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName 
      hostNetwork: true
      volumes:
        - name: log
          hostPath:
            path: /k
            type: Directory
        - name: cns-config
          configMap:
            name: cns-config
      nodeSelector:
        kubernetes.io/os: windows
      serviceAccountName: azure-cns
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: cns-config
  namespace: kube-system
data:
  cns_config.json: |
    {
      "TelemetrySettings": {
          "TelemetryBatchSizeBytes": 16384,
          "TelemetryBatchIntervalInSecs": 15,
          "RefreshIntervalInSecs": 15,
          "DisableAll": false,
          "HeartBeatIntervalInMins": 30,
          "DebugMode": false,
          "SnapshotIntervalInMins": 60
      },
      "ManagedSettings": {
          "PrivateEndpoint": "",
          "InfrastructureNetworkID": "",
          "NodeID": "",
          "NodeSyncIntervalInSeconds": 30
      },
      "ChannelMode": "CRD",
      "InitializeFromCNI": true
    }
