apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: testground-sidecar
  annotations:
    cni: "flannel"
spec:
  selector:
    matchLabels:
      name: testground-sidecar
  template:
    metadata:
      annotations:
        cni: "flannel"
      labels:
        name: testground-sidecar
    spec:
      terminationGracePeriodSeconds: 10
      hostPID: true
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      initContainers:
      - name: iproute-add
        image: busybox
        securityContext:
          privileged: true
        command:
        - sh
        - -ac
        - >
          while [ "$GW" = "" ]; do export GW=$(ip route | grep cni0 | awk '{print $7}'); echo "Got GW: $GW"; sleep 5; done;
          echo $GW &&
          ip route &&
          ip route add 100.64.0.0/16 via $GW &&
          ip route || true;
          nslookup redis-headless;
          while [ $? -ne 0 ]; do echo "redis-headless doesn't resolve."; sleep 5; nslookup redis-headless; done;
          echo "redis-headless resolved."
      containers:
      - name: testground-sidecar
        image: ipfs/testground:edge
        imagePullPolicy: Always
        command: ["testground"]
        args: ["--vv", "sidecar", "--runner", "k8s"]
        securityContext:
          capabilities:
            add: ["NET_ADMIN", "SYS_ADMIN", "SYS_TIME"]
          privileged: true
        env:
        - name: REDIS_HOST
          value: "redis-headless"
        resources:
          limits:
            memory: 1024Mi
          requests:
            cpu: 200m
            memory: 1024Mi
        volumeMounts:
          - name: dockersock
            mountPath: "/var/run/docker.sock"
          - name: cnibin
            mountPath: "/host/opt/cni/bin"
      volumes:
      - name: dockersock
        hostPath:
          path: /var/run/docker.sock
      - name: cnibin
        hostPath:
          path: /opt/cni/bin

