---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: traces
spec:
  selector:
    matchLabels:
      name: traces
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: "20%"
  template:
    metadata:
      labels:
        name: traces
    spec:
      serviceAccountName: traces
      tolerations:
        - operator: Exists
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - {key: observeinc.com/unschedulable, operator: DoesNotExist}
                  - {key: eks.amazonaws.com/compute-type, operator: NotIn, values: [fargate]}
                  - {key: kubernetes.io/os, operator: NotIn, values: [windows]}
      terminationGracePeriodSeconds: 15
      containers:
        - name: otel-collector
          image: otel/opentelemetry-collector-contrib
          command:
            - "/otelcol-contrib"
            - "--config=/etc/config/config.yaml"
            - "--config=/etc/config/extra.yaml"
            # for internal prometheus metrics
            - "--set=service.telemetry.metrics.address=:58888"
          ports:
            - containerPort: 55679    # ZPages endpoint.
            - containerPort: 4317     # Default OpenTelemetry receiver port.
            - containerPort: 4318     # Default OpenTelemetry HTTP receiver port.
            - containerPort: 9411     # Zipkin
            - containerPort: 58888    # Internal Prometheus Metrics.
              name: metrics
          livenessProbe:
            httpGet:
              path: /
              port: 13133     # Health Check extension default port.
          readinessProbe:
            httpGet:
              path: /
              port: 13133     # Health Check extension default port.
          resources:
            limits:
              cpu: 250m
              memory: 256Mi
            requests:
              cpu: 250m
              memory: 256Mi
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: OBSERVE_CLUSTER
              valueFrom:
                configMapKeyRef:
                  name: cluster-info
                  key: id
          envFrom:
            - configMapRef:
                name: otel-collector-env
            - secretRef:
                name: credentials
            - configMapRef:
                name: env-overrides
                optional: true
            - configMapRef:
                name: otel-collector-env-overrides
                optional: true
          securityContext:
            runAsNonRoot: true
            runAsUser: 65534
            capabilities:
              drop:
                - all
          volumeMounts:
            - mountPath: /etc/config
              name: otel-collector
      volumes:
        - name: otel-collector
          configMap:
            name: otel-collector
