<commit_before>#!/usr/bin/env bash
set -ex

echo Args passed: [[ $@ ]]

# Pull images if not present
if [ -f /vagrant/images.tar ]; then
    echo 'Found saved images at /vagrant/images.tar'
    docker load -i /vagrant/images.tar
elif [ "${dep_scenario}" != "calico" ]; then
  echo "Pulling Contiv-VPP plugin images..."
  sudo -E ${contiv_dir}/k8s/pull-images.sh -b "${image_tag}"
fi

# --------------------------------------------------------
# ---> Build Contiv/VPP-vswitch Development Image <---
# --------------------------------------------------------

if [ "${dep_env}" = "dev" ]; then
    # wait for apt auto-update to finish so we don't get conflicts
    #TODO: disable apt daily services in the vagrant box
    while `ps aux | grep -q [a]pt`; do
      sleep 20
    done

    sudo -E apt-get install -y xorg \
                            openbox

    echo "Downloading and installing Goland..."
    curl -sL https://download.jetbrains.com/go/goland-"${goland_version}".tar.gz > /tmp/goland.tar.gz
    tar -xvzf /tmp/goland.tar.gz --directory /home/vagrant >/dev/null 2>&1

    if [ -f /vagrant/dev-contiv-vswitch.tar ]; then
        echo "Found saved dev image at /vagrant/dev-contiv-vswitch.tar"
        docker load -i /vagrant/dev-contiv-vswitch.tar
    else
        echo "vagrant" >> ${contiv_dir}/.dockerignore
        echo "Building development contivpp/vswitch image..."
        cd ${contiv_dir}/docker; ./build-all.sh
    fi
fi

# --------------------------------------------------------
# ---> Create token and export it with kube master IP <---
# --------------------------------------------------------

echo "Exporting Kube Master IP and Kubeadm Token..."
echo "export KUBEADM_TOKEN=$(kubeadm token generate)" >> /vagrant/config/init

if [ "${dep_scenario}" != 'nostn' ] && [ "${ip_version}" != 'ipv6' ]; then
  echo "export KUBE_MASTER_IP=$(hostname -I | cut -f2 -d' ')" >> /vagrant/config/init
  source /vagrant/config/init
  sed 's/127\.0\.1\.1.*k8s.*/'"$KUBE_MASTER_IP"' '"$1"'/' -i /etc/hosts
  echo "export no_proxy='$1,$KUBE_MASTER_IP,localhost,127.0.0.1'" >> /etc/profile.d/envvar.sh
  echo "export no_proxy='$1,$KUBE_MASTER_IP,localhost,127.0.0.1'" >> /home/vagrant/.profile
else
  echo "export KUBE_MASTER_IP=$2" >> /vagrant/config/init
  source /vagrant/config/init
  sed 's/127\.0\.1\.1.*k8s.*/'"$2"' '"$1"'/' -i /etc/hosts
  echo "export no_proxy='$1,$KUBE_MASTER_IP,localhost,127.0.0.1'" >> /etc/profile.d/envvar.sh
  echo "export no_proxy='$1,$KUBE_MASTER_IP,localhost,127.0.0.1'" >> /home/vagrant/.profile
fi

source /etc/profile.d/envvar.sh
source /home/vagrant/.profile

# --------------------------------------------------------
# --------------> Kubeadm & Networking <------------------
# --------------------------------------------------------

# Based on kubernetes version, disable hugepages in Kubelet
# Initialize Kubernetes master

service_cidr="10.96.0.0/12"
pod_network_cidr="10.10.0.0/16"
if [ "${ip_version}" == "ipv6" ]; then
  pod_network_cidr="2001::/16"
  service_cidr="2096::/110"
elif [ "${dep_scenario}" != 'calico' ] && [ "${dep_scenario}" != 'calicovpp' ]; then
  pod_network_cidr="10.0.0.0/8"
fi

split_k8s_version="$(cut -d "." -f 2 <<< "${k8s_version}")"
if [ $split_k8s_version -gt 10 ] ; then
  if [ "${node_os_release}" == "16.04" ] ; then
    sed -i '1s/.*/KUBELET_EXTRA_ARGS=--node-ip='"$KUBE_MASTER_IP"' --feature-gates HugePages=false/' /etc/default/kubelet
  else
    sed -i '1s/.*/KUBELET_EXTRA_ARGS=--node-ip='"$KUBE_MASTER_IP"' --feature-gates HugePages=false --resolv-conf=\/run\/systemd\/resolve\/resolv.conf/' /etc/default/kubelet
  fi
  systemctl daemon-reload
  systemctl restart kubelet
  if [ "${dep_scenario}" != 'calico' ] && [ "${dep_scenario}" != 'calicovpp' ]; then
    echo "$(kubeadm init --token-ttl 0 --kubernetes-version=v"${k8s_version}" --pod-network-cidr="${pod_network_cidr}" --apiserver-advertise-address="${KUBE_MASTER_IP}" --service-cidr="${service_cidr}" --token="${KUBEADM_TOKEN}")" >> /vagrant/config/cert
  else
    echo "$(kubeadm init --token-ttl 0 --kubernetes-version=v"${k8s_version}" --pod-network-cidr="${pod_network_cidr}" --apiserver-advertise-address="${KUBE_MASTER_IP}" --service-cidr="${service_cidr}" --token="${KUBEADM_TOKEN}")" >> /vagrant/config/cert
  fi
else
  sed -i '4 a Environment="KUBELET_EXTRA_ARGS=--node-ip='"$KUBE_MASTER_IP"' --feature-gates HugePages=false"' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
  systemctl daemon-reload
  systemctl restart kubelet
  echo "$(kubeadm init --token-ttl 0 --kubernetes-version=v"${k8s_version}" --pod-network-cidr="${pod_network_cidr}" --apiserver-advertise-address="${KUBE_MASTER_IP}" --service-cidr="${service_cidr}" --token="${KUBEADM_TOKEN}")" >> /vagrant/config/cert
fi

echo "Create folder to store kubernetes and network configuration"
mkdir -p /home/vagrant/.kube
sudo cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
sudo chown vagrant:vagrant -R /home/vagrant/.kube
sleep 2;

applySTNScenario() {
  gw="10.130.1.254";
  if [ "${ip_version}" = "ipv6" ]; then
     gw="fdf8:f53e:61e4::18";
  fi
  if [ "${dep_scenario}" = "nostn" ]; then

    # Generate node config for use with CRD
    cat > ${contiv_dir}/k8s/node-config/crd.yaml <<EOL
# Configuration for node config in the cluster
apiVersion: nodeconfig.contiv.vpp/v1
kind: NodeConfig
metadata:
  name: k8s-master
spec:
  mainVPPInterface:
    interfaceName: "GigabitEthernet0/8/0"
  gateway: $gw

---
EOL
    counter=1;
    until ((counter > "${num_nodes}"))
    do

       # Generate node config for use with CRD
      cat <<EOL >> ${contiv_dir}/k8s/node-config/crd.yaml
# Configuration for node config in the cluster
apiVersion: nodeconfig.contiv.vpp/v1
kind: NodeConfig
metadata:
  name: k8s-worker$counter
spec:
  mainVPPInterface:
    interfaceName: "GigabitEthernet0/8/0"
  gateway: $gw

---
EOL

    ((counter++))
    done
  else
    curl -s https://raw.githubusercontent.com/contiv/vpp/master/k8s/stn-install.sh > /tmp/contiv-stn.sh
    chmod +x /tmp/contiv-stn.sh
    sudo /tmp/contiv-stn.sh
    # For use without CRD
    stn_config="--set contiv.stealInterface=enp0s8"

    # Generate node config for use with CRD
    cat > ${contiv_dir}/k8s/node-config/crd.yaml <<EOL
# Configuration for node config in the cluster
apiVersion: nodeconfig.contiv.vpp/v1
kind: NodeConfig
metadata:
  name: k8s-master
spec:
  mainVPPInterface:
    interfaceName: "GigabitEthernet0/8/0"

---
EOL

    counter=1;
    until ((counter > "${num_nodes}"))
    do
      # Generate node config for use with CRD
      cat <<EOL >> ${contiv_dir}/k8s/node-config/crd.yaml
# Configuration for node config in the cluster
apiVersion: nodeconfig.contiv.vpp/v1
kind: NodeConfig
metadata:
  name: k8s-worker$counter
spec:
  mainVPPInterface:
    interfaceName: "GigabitEthernet0/8/0"

---
EOL

      ((counter++))
    done
  fi
}

applyVPPnetwork() {
  helm_opts="${helm_extra_opts}"

  if [ "${image_tag}" != "latest" ]; then
    helm_opts="${helm_opts} --set vswitch.image.tag=${image_tag} --set cni.image.tag=${image_tag} --set ksr.image.tag=${image_tag} --set crd.image.tag=${image_tag}"
  fi<commit_msg>disable coredns loop plugin when testing noOverlayMode<commit_after>#!/usr/bin/env bash
set -ex

echo Args passed: [[ $@ ]]

# Pull images if not present
if [ -f /vagrant/images.tar ]; then
    echo 'Found saved images at /vagrant/images.tar'
    docker load -i /vagrant/images.tar
elif [ "${dep_scenario}" != "calico" ]; then
  echo "Pulling Contiv-VPP plugin images..."
  sudo -E ${contiv_dir}/k8s/pull-images.sh -b "${image_tag}"
fi

# --------------------------------------------------------
# ---> Build Contiv/VPP-vswitch Development Image <---
# --------------------------------------------------------

if [ "${dep_env}" = "dev" ]; then
    # wait for apt auto-update to finish so we don't get conflicts
    #TODO: disable apt daily services in the vagrant box
    while `ps aux | grep -q [a]pt`; do
      sleep 20
    done

    sudo -E apt-get install -y xorg \
                            openbox

    echo "Downloading and installing Goland..."
    curl -sL https://download.jetbrains.com/go/goland-"${goland_version}".tar.gz > /tmp/goland.tar.gz
    tar -xvzf /tmp/goland.tar.gz --directory /home/vagrant >/dev/null 2>&1

    if [ -f /vagrant/dev-contiv-vswitch.tar ]; then
        echo "Found saved dev image at /vagrant/dev-contiv-vswitch.tar"
        docker load -i /vagrant/dev-contiv-vswitch.tar
    else
        echo "vagrant" >> ${contiv_dir}/.dockerignore
        echo "Building development contivpp/vswitch image..."
        cd ${contiv_dir}/docker; ./build-all.sh
    fi
fi

# --------------------------------------------------------
# ---> Create token and export it with kube master IP <---
# --------------------------------------------------------

echo "Exporting Kube Master IP and Kubeadm Token..."
echo "export KUBEADM_TOKEN=$(kubeadm token generate)" >> /vagrant/config/init

if [ "${dep_scenario}" != 'nostn' ] && [ "${ip_version}" != 'ipv6' ]; then
  echo "export KUBE_MASTER_IP=$(hostname -I | cut -f2 -d' ')" >> /vagrant/config/init
  source /vagrant/config/init
  sed 's/127\.0\.1\.1.*k8s.*/'"$KUBE_MASTER_IP"' '"$1"'/' -i /etc/hosts
  echo "export no_proxy='$1,$KUBE_MASTER_IP,localhost,127.0.0.1'" >> /etc/profile.d/envvar.sh
  echo "export no_proxy='$1,$KUBE_MASTER_IP,localhost,127.0.0.1'" >> /home/vagrant/.profile
else
  echo "export KUBE_MASTER_IP=$2" >> /vagrant/config/init
  source /vagrant/config/init
  sed 's/127\.0\.1\.1.*k8s.*/'"$2"' '"$1"'/' -i /etc/hosts
  echo "export no_proxy='$1,$KUBE_MASTER_IP,localhost,127.0.0.1'" >> /etc/profile.d/envvar.sh
  echo "export no_proxy='$1,$KUBE_MASTER_IP,localhost,127.0.0.1'" >> /home/vagrant/.profile
fi

source /etc/profile.d/envvar.sh
source /home/vagrant/.profile

# --------------------------------------------------------
# --------------> Kubeadm & Networking <------------------
# --------------------------------------------------------

# Based on kubernetes version, disable hugepages in Kubelet
# Initialize Kubernetes master

service_cidr="10.96.0.0/12"
pod_network_cidr="10.10.0.0/16"
if [ "${ip_version}" == "ipv6" ]; then
  pod_network_cidr="2001::/16"
  service_cidr="2096::/110"
elif [ "${dep_scenario}" != 'calico' ] && [ "${dep_scenario}" != 'calicovpp' ]; then
  pod_network_cidr="10.0.0.0/8"
fi

split_k8s_version="$(cut -d "." -f 2 <<< "${k8s_version}")"
if [ $split_k8s_version -gt 10 ] ; then
  if [ "${node_os_release}" == "16.04" ] ; then
    sed -i '1s/.*/KUBELET_EXTRA_ARGS=--node-ip='"$KUBE_MASTER_IP"' --feature-gates HugePages=false/' /etc/default/kubelet
  else
    sed -i '1s/.*/KUBELET_EXTRA_ARGS=--node-ip='"$KUBE_MASTER_IP"' --feature-gates HugePages=false --resolv-conf=\/run\/systemd\/resolve\/resolv.conf/' /etc/default/kubelet
  fi
  systemctl daemon-reload
  systemctl restart kubelet
  if [ "${dep_scenario}" != 'calico' ] && [ "${dep_scenario}" != 'calicovpp' ]; then
    echo "$(kubeadm init --token-ttl 0 --kubernetes-version=v"${k8s_version}" --pod-network-cidr="${pod_network_cidr}" --apiserver-advertise-address="${KUBE_MASTER_IP}" --service-cidr="${service_cidr}" --token="${KUBEADM_TOKEN}")" >> /vagrant/config/cert
  else
    echo "$(kubeadm init --token-ttl 0 --kubernetes-version=v"${k8s_version}" --pod-network-cidr="${pod_network_cidr}" --apiserver-advertise-address="${KUBE_MASTER_IP}" --service-cidr="${service_cidr}" --token="${KUBEADM_TOKEN}")" >> /vagrant/config/cert
  fi
else
  sed -i '4 a Environment="KUBELET_EXTRA_ARGS=--node-ip='"$KUBE_MASTER_IP"' --feature-gates HugePages=false"' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
  systemctl daemon-reload
  systemctl restart kubelet
  echo "$(kubeadm init --token-ttl 0 --kubernetes-version=v"${k8s_version}" --pod-network-cidr="${pod_network_cidr}" --apiserver-advertise-address="${KUBE_MASTER_IP}" --service-cidr="${service_cidr}" --token="${KUBEADM_TOKEN}")" >> /vagrant/config/cert
fi

echo "Create folder to store kubernetes and network configuration"
mkdir -p /home/vagrant/.kube
sudo cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
sudo chown vagrant:vagrant -R /home/vagrant/.kube
sleep 2;

applySTNScenario() {
  gw="10.130.1.254";
  if [ "${ip_version}" = "ipv6" ]; then
     gw="fdf8:f53e:61e4::18";
  fi
  if [ "${dep_scenario}" = "nostn" ]; then

    # Generate node config for use with CRD
    cat > ${contiv_dir}/k8s/node-config/crd.yaml <<EOL
# Configuration for node config in the cluster
apiVersion: nodeconfig.contiv.vpp/v1
kind: NodeConfig
metadata:
  name: k8s-master
spec:
  mainVPPInterface:
    interfaceName: "GigabitEthernet0/8/0"
  gateway: $gw

---
EOL
    counter=1;
    until ((counter > "${num_nodes}"))
    do

       # Generate node config for use with CRD
      cat <<EOL >> ${contiv_dir}/k8s/node-config/crd.yaml
# Configuration for node config in the cluster
apiVersion: nodeconfig.contiv.vpp/v1
kind: NodeConfig
metadata:
  name: k8s-worker$counter
spec:
  mainVPPInterface:
    interfaceName: "GigabitEthernet0/8/0"
  gateway: $gw

---
EOL

    ((counter++))
    done
  else
    curl -s https://raw.githubusercontent.com/contiv/vpp/master/k8s/stn-install.sh > /tmp/contiv-stn.sh
    chmod +x /tmp/contiv-stn.sh
    sudo /tmp/contiv-stn.sh
    # For use without CRD
    stn_config="--set contiv.stealInterface=enp0s8"

    # Generate node config for use with CRD
    cat > ${contiv_dir}/k8s/node-config/crd.yaml <<EOL
# Configuration for node config in the cluster
apiVersion: nodeconfig.contiv.vpp/v1
kind: NodeConfig
metadata:
  name: k8s-master
spec:
  mainVPPInterface:
    interfaceName: "GigabitEthernet0/8/0"

---
EOL

    counter=1;
    until ((counter > "${num_nodes}"))
    do
      # Generate node config for use with CRD
      cat <<EOL >> ${contiv_dir}/k8s/node-config/crd.yaml
# Configuration for node config in the cluster
apiVersion: nodeconfig.contiv.vpp/v1
kind: NodeConfig
metadata:
  name: k8s-worker$counter
spec:
  mainVPPInterface:
    interfaceName: "GigabitEthernet0/8/0"

---
EOL

      ((counter++))
    done
  fi
}

applyVPPnetwork() {

  if [[ $helm_extra_opts == *"contiv.useNoOverlay=true"* ]]; then
    # Disable coredns loop detection plugin
    kubectl get configmap coredns \
        -o yaml \
        -n kube-system  \
        --export >> coredns-config.yaml
    sed -i '/loop/d' coredns-config.yaml
    kubectl apply -f coredns-config.yaml -n kube-system
  fi

  helm_opts="${helm_extra_opts}"

  if [ "${image_tag}" != "latest" ]; then
    helm_opts="${helm_opts} --set vswitch.image.tag=${image_tag} --set cni.image.tag=${image_tag} --set ksr.image.tag=${image_tag} --set crd.image.tag=${image_tag}"
  fi
{'fraction_non_alphanumeric': 0.21098285636227035, 'fraction_numerical': 0.021583225189536235, 'mean_word_length': 2.8160020849622103, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 79, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 16, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '395161', 'n_tokens_mistral': 5569, 'n_tokens_neox': 5401, 'n_words': 1095}