apiVersion: apps/v1
kind: Deployment
metadata:
  name: testground-daemon
  labels:
    app: testground-daemon
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testground-daemon
  template:
    metadata:
      labels:
        app: testground-daemon
    spec:
      serviceAccountName: testground-daemon
      hostPID: true
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      nodeSelector:
        testground.node.role.infra: "true"
      initContainers:
      - name: iproute-add
        image: busybox:1.31.1
        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;
      containers:
      - name: goproxy
        image: iptestground/goproxy:2.0.2
        ports:
        - containerPort: 8081
          hostPort: 8081
        volumeMounts:
          - name: envtoml
            mountPath: /root/testground/.env.toml
            subPath: .env.toml
          - name: efs-pvc
            mountPath: "/go"
        resources:
          requests:
            memory: 512Mi
            cpu: 500m
          limits:
            memory: 512Mi
      - name: testground-daemon
        image: iptestground/testground:edge
        imagePullPolicy: Always
        env:
        - name: REDIS_HOST
          value: "testground-infra-redis-headless"
        securityContext:
          privileged: true
        ports:
        - containerPort: 8042
          hostPort: 8042
        volumeMounts:
          - name: daemon-datadir
            mountPath: "/root/testground/"
          - name: efs-pvc
            mountPath: "/efs"
          - name: dockersock
            mountPath: "/var/run/docker.sock"
          - name: envtoml
            mountPath: /root/testground/.env.toml
            subPath: .env.toml
        resources:
          requests:
            memory: 2048Mi
            cpu: 2000m
          limits:
            memory: 2048Mi
      volumes:
        - name: efs-pvc
          persistentVolumeClaim:
            claimName: efs
        - name: daemon-datadir
          persistentVolumeClaim:
            claimName: testground-daemon-datadir-pvc
        - name: dockersock
          hostPath:
            path: /var/run/docker.sock
        - name: envtoml
          configMap:
            name: env-toml-cfg
