kind: DaemonSet
apiVersion: apps/v1
metadata:
  labels:
    app: antrea
    component: antrea-node-init
  name: antrea-node-init
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: antrea
      component: antrea-node-init
  template:
    metadata:
      labels:
        app: antrea
        component: antrea-node-init
    spec:
      hostPID: true
      hostNetwork: true
      containers:
        - name: node-init
          image: gcr.io/google-containers/startup-script:v1
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
          env:
          - name: STARTUP_SCRIPT
            value: |
              #! /bin/bash
              set -o errexit
              set -o pipefail
              set -o nounset

              until [ -f /var/run/azure-vnet.json ]; do
                  echo "Waiting for azure vnet config to be created"
                  sleep 1s
              done

              if ip link show azure0; then
                  echo "Toggle azure cni mode from bridge to transparent"
                  sed -i 's/"Mode": "bridge",/"Mode": "transparent",/g' /var/run/azure-vnet.json

                  # Delete the bridge so that ebtables rules do not take effect"
                  echo "Delete azure0 bridge"
                  ip link del azure0

                  # In bridge mode, azure0 interface has the IP
                  # TODO: Figure out primary interface
                  echo "Flap the primary interface"
                  ifdown eth0
                  ifup eth0
              fi
              echo "Node initialization completed"
