{{- if and (ne .Values.omsagent.secret.key "<your_workspace_key>") (ne .Values.omsagent.secret.wsid "<your_workspace_id>") (or (ne .Values.omsagent.env.clusterName "<your_cluster_name>") (ne .Values.omsagent.env.clusterId "<your_cluster_id>"))}}
apiVersion: apps/v1
kind: DaemonSet
metadata:
 name: omsagent
 namespace: kube-system
 labels:
   chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
   release: {{ .Release.Name }}
   heritage: {{ .Release.Service }}
   component: oms-agent
   tier: node
spec:
 updateStrategy:
  type: RollingUpdate
 selector:
   matchLabels:
     dsName: "omsagent-ds"
 template:
  metadata:
   labels:
    dsName: "omsagent-ds"
   annotations:
    agentVersion: {{ .Values.omsagent.image.tag }}
    dockerProviderVersion: {{ .Values.omsagent.image.dockerProviderVersion }}
    schema-versions: "v1"
  spec:
   {{- if .Values.omsagent.rbac }}
   serviceAccountName: omsagent
   {{- end }}
   containers:
     - name: omsagent
       {{- if eq (.Values.omsagent.domain | lower) "opinsights.azure.cn" }}
       image: "mcr.azk8s.cn/azuremonitor/containerinsights/ciprod:{{ .Values.omsagent.image.tag }}"
       {{- else }}
       image: {{ printf "%s:%s" .Values.omsagent.image.repo .Values.omsagent.image.tag }}
       {{- end }}
       imagePullPolicy: IfNotPresent
       resources:
{{ toYaml .Values.omsagent.resources.daemonset | indent 9 }}
       env:
       {{- if ne .Values.omsagent.env.clusterId "<your_cluster_id>" }}
       - name: AKS_RESOURCE_ID
         value: {{ .Values.omsagent.env.clusterId | quote }}
       {{- if ne .Values.omsagent.env.clusterRegion "<your_cluster_region>" }}
       - name: AKS_REGION
         value: {{ .Values.omsagent.env.clusterRegion | quote }}
       {{- end }}
       {{- else }}
       - name: ACS_RESOURCE_NAME
         value: {{ .Values.omsagent.env.clusterName | quote }}
       {{- end }}
       - name: CONTROLLER_TYPE
         value: "DaemonSet"
       - name: NODE_IP
         valueFrom:
            fieldRef:
              fieldPath: status.hostIP
       - name: USER_ASSIGNED_IDENTITY_CLIENT_ID
         value: ""
       {{- if .Values.omsagent.logsettings.logflushintervalsecs }}
       - name: FBIT_SERVICE_FLUSH_INTERVAL
         value: {{ .Values.omsagent.logsettings.logflushintervalsecs | quote }}
       {{- end }}
       {{- if .Values.omsagent.logsettings.tailbufchunksizemegabytes }}
       - name: FBIT_TAIL_BUFFER_CHUNK_SIZE
         value: {{ .Values.omsagent.logsettings.tailbufchunksizemegabytes | quote }}
       {{- end }}
       {{- if .Values.omsagent.logsettings.tailbufmaxsizemegabytes }}
       - name: FBIT_TAIL_BUFFER_MAX_SIZE
         value: {{ .Values.omsagent.logsettings.tailbufmaxsizemegabytes | quote }}
       {{- end }}
       securityContext:
         privileged: true
       ports:
       - containerPort: 25225
         protocol: TCP
       - containerPort: 25224
         protocol: UDP
       volumeMounts:
        - mountPath: /hostfs
          name: host-root
          readOnly: true
        - mountPath: /var/run/host
          name: docker-sock
        - mountPath: /var/log
          name: host-log
        - mountPath: /var/lib/docker/containers
          name: containerlog-path
        - mountPath: /etc/kubernetes/host
          name: azure-json-path
        - mountPath: /etc/omsagent-secret
          name: omsagent-secret
          readOnly: true
        - mountPath: /etc/config/settings
          name: settings-vol-config
          readOnly: true
        {{- if .Values.omsagent.logsettings.custommountpath }}
        - mountPath: {{ .Values.omsagent.logsettings.custommountpath }}
          name: custom-mount-path
        {{- end }}
        - mountPath: /etc/config/settings/adx
          name: omsagent-adx-secret
          readOnly: true
       livenessProbe:
        exec:
         command:
         - /bin/bash
         - -c
         - "/opt/livenessprobe.sh"
        initialDelaySeconds: 60
        periodSeconds: 60
   {{- with .Values.omsagent.daemonset.affinity }}
   affinity: {{- toYaml . | nindent 8 }}
   {{- end }}
   {{- with .Values.omsagent.tolerations }}
   tolerations: {{- toYaml . | nindent 8 }}
   {{- end }}
   volumes:
    - name: host-root
      hostPath:
       path: /
    - name: docker-sock
      hostPath:
       path: /var/run
    - name: container-hostname
      hostPath:
       path: /etc/hostname
    - name: host-log
      hostPath:
       path: /var/log
    - name: containerlog-path
      hostPath:
       path: /var/lib/docker/containers
    - name: azure-json-path
      hostPath:
       path: /etc/kubernetes
    - name: omsagent-secret
      secret:
       secretName: omsagent-secret
    - name: settings-vol-config
      configMap:
        name: container-azm-ms-agentconfig
        optional: true
    {{- if .Values.omsagent.logsettings.custommountpath }}
    - name: custom-mount-path
      hostPath:
       path: {{ .Values.omsagent.logsettings.custommountpath }}
    {{- end }}
    - name: omsagent-adx-secret
      secret:
       secretName: omsagent-adx-secret
       optional: true
{{- end }}
