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

              if grep -q "network-plugin=kubenet" /etc/default/kubelet; then
                  echo "Changing kubelet configuration to --network-plugin=cni --cni-bin-dir=/home/kubernetes/bin"
                  mkdir -p /home/kubernetes/bin
                  sed -i "s:--network-plugin=kubenet:--network-plugin=cni\ --cni-bin-dir=/home/kubernetes/bin:g" /etc/default/kubelet

                  echo "Restarting kubelet..."
                  systemctl restart kubelet
              fi

              if ip link show cbr0; then
                  echo "Detected cbr0 bridge. Deleting interface..."
                  ip link del cbr0
              fi

              echo "Node initialization complete"
