# helm_charts_omsagent-deployment.yaml
{{- 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: Deployment
metadata:
 name: omsagent-rs
 namespace: kube-system
 labels:
   chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
   release: {{ .Release.Name }}
   heritage: {{ .Release.Service }}
   component: oms-agent
   tier: node
spec:
 replicas: 1
 selector:
  matchLabels:
   rsName: "omsagent-rs"
 strategy:
  type: RollingUpdate
 template:
  metadata:
   labels:
    rsName: "omsagent-rs"
   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.deployment | 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: "ReplicaSet"
       - name: NODE_IP
         valueFrom:
            fieldRef:
              fieldPath: status.hostIP
       - name: USER_ASSIGNED_IDENTITY_CLIENT_ID
         value: ""
       securityContext:
         privileged: true
       ports:
       - containerPort: 25225
         protocol: TCP
       - containerPort: 25224
         protocol: UDP
       - containerPort: 25227
         protocol: TCP
         name: in-rs-tcp
       volumeMounts:
        - 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
          name: omsagent-rs-config
        - 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.deployment.affinity }}
   affinity: {{- toYaml . | nindent 8 }}
   {{- end }}
   {{- with .Values.omsagent.tolerations }}
   tolerations: {{- toYaml . | nindent 8 }}
   {{- end }}
   volumes:
    - 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: omsagent-rs-config
      configMap:
        name: omsagent-rs-config
    - 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 }}