---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: events
spec:
  selector:
    matchLabels:
      name: events
  template:
    metadata:
      labels:
        name: events
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - {key: observeinc.com/unschedulable, operator: DoesNotExist}
                  - {key: kubernetes.io/os, operator: NotIn, values: [windows]}
      serviceAccountName: events
      initContainers:
        - name: kube-cluster-info
          image: observeinc/kube-cluster-info:latest
          env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
      containers:
        - name: kube-state-events
          image: observeinc/kube-state-events:latest
          args:
            - -healthz-addr=:5171
            - -metrics-addr=:9090
            - -o=$(OBSERVE_COLLECTOR_SCHEME)://$(OBSERVE_CUSTOMER):$(OBSERVE_TOKEN)@$(OBSERVE_COLLECTOR_HOST):$(OBSERVE_COLLECTOR_PORT)/v1/http/kubernetes/events?clusterUid=$(OBSERVE_CLUSTER)
          ports:
            - containerPort: 5171
            - containerPort: 9090
              name: http-metrics
          env:
            - name: OBSERVE_CLUSTER
              valueFrom:
                configMapKeyRef:
                  name: cluster-info
                  key: id
          envFrom:
            - configMapRef:
                name: kube-state-events-env
            - secretRef:
                name: credentials
            - configMapRef:
                name: env-overrides
                optional: true
            - configMapRef:
                name: kube-state-events-env-overrides
                optional: true
          readinessProbe:
            httpGet:
              path: /healthz
              port: 5171
          livenessProbe:
            httpGet:
              path: /healthz
              port: 5171
            timeoutSeconds: 5
            failureThreshold: 10
          resources:
            limits:
              cpu: 50m
              memory: 256Mi
            requests:
              cpu: 50m
              memory: 256Mi
          securityContext:
            runAsNonRoot: true
            runAsUser: 65534
            capabilities:
              drop:
                - all
