---
# Following deamonset will run the dhcp daemon built from https://github.com/georgenicoll/plugins
# on all nodes.
# This is as opposed to running the dhcp daemon on the node itself from:
#  /var/snap/microk8s/current/opt/cni/bin/dhcp.
# Inspiration from https://gist.github.com/dougbtv/89284e2a2342d4cbf1ec3bb4fe713f92
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: kube-dhcp-daemon
  namespace: kube-system
  labels:
    tier: node
    app: dhcp
    name: dhcp
spec:
  selector:
    matchLabels:
      name: dhcp
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        tier: node
        app: dhcp
        name: dhcp
    spec:
      # Need to be hostNetwork: true for socket files to work
      hostNetwork: true
      # Need to be hostPID: true so that dhcp process can access all of the netns entries in /proc
      # for all of the containers being spun up (otherwise dhcp would only see itself in /proc)
      hostPID: true
      nodeSelector:
        kubernetes.io/arch: arm64
      tolerations:
      - operator: Exists
        effect: NoSchedule
      containers:
      - name: kube-dhcp
        image: georgenicoll/containernetworking-dhcp:latest
        command:
        - /bin/sh
        args:
        - -c
        - 'rm -f /run/cni/dhcp.sock; exec /dhcp daemon'
        resources:
          requests:
            cpu: "10m"
            memory: "50Mi"
          limits:
            cpu: "100m"
            memory: "50Mi"
        securityContext:
          privileged: true
        volumeMounts:
        - name: run-cni
          mountPath: /run/cni
        - name: var-run
          mountPath: /var/run
          mountPropagation: Bidirectional
      volumes:
        - name: run-cni
          hostPath:
            path: /run/cni
        - name: var-run
          hostPath:
            path: /var/run
