---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: hcloud-connect-agent
  namespace: kube-system
spec:
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: hcloud-connect
  template:
    metadata:
      labels:
        app: hcloud-connect
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ""
    spec:
      dnsPolicy: Default
      tolerations:
        # this taint is set by all kubelets running `--cloud-provider=external`
        # so we should tolerate it to schedule the cloud controller manager
        - key: "node.cloudprovider.kubernetes.io/uninitialized"
          value: "true"
          effect: "NoSchedule"
        - key: "CriticalAddonsOnly"
          operator: "Exists"
        # cloud controller manages should be able to run on masters
        - key: "node-role.kubernetes.io/master"
          effect: NoSchedule
        - key: "node.kubernetes.io/not-ready"
          effect: "NoSchedule"
      hostNetwork: true
      containers:
        - image: ghcr.io/bluebamboostudios/hcloud-connect:latest
          name: hcloud-connect
          resources:
            requests:
              cpu: 100m
              memory: 50Mi
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: HCLOUD_TOKEN
              valueFrom:
                secretKeyRef:
                  name: hcloud
                  key: token
            - name: HCLOUD_LOAD_BALANCER
              valueFrom:
                secretKeyRef:
                  name: hcloud
                  key: loadBalancer
