apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: netclient
  labels:
    app: netclient
spec:
  selector:
    matchLabels:
      app: netclient
  template:
    metadata:
      labels:
        app: netclient
    spec:
      hostNetwork: true
      containers:
      - name: netclient
        image: gravitl/netclient:v0.5.8
        command: ['bash', '-c', "/root/netclient join -t $ACCESS_TOKEN --daemon off --name $(echo $NODE_NAME| sed -e s/.$NETWORK//); while true; do /root/netclient checkin -n $NETWORK; sleep $SLEEP; done"]
        env:
        - name: ACCESS_TOKEN
          value: "ACCESS_TOKEN_VALUE"
        - name: NETWORK
          value: "microk8s"
        - name: SLEEP
          value: "30"
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        volumeMounts:
        - mountPath: /etc/netclient
          name: etc-netclient
        - mountPath: /usr/bin/wg
          name: wg
        - mountPath: /var/run/dbus/system_bus_socket
          name: systemd-bus-socket
        securityContext:
          privileged: true
          #capabilities:
          #  add:
          #  - ["NET_ADMIN","SYS_ADMIN","SYS_MODULE"]
      volumes:
      - hostPath:
          path: /etc/netclient
          type: DirectoryOrCreate
        name: etc-netclient
      - hostPath:
          path: /usr/bin/wg
          type: File
        name: wg 
      - hostPath:
          path: /usr/bin/resolvectl
          type: File
        name: resolvectl
      - hostPath:
          path: /var/run/dbus/system_bus_socket
          type: ""
        name: systemd-bus-socket


