Skip to content

Instantly share code, notes, and snippets.

@dims
Last active December 6, 2023 19:11
Show Gist options
  • Save dims/2ce24579c60fd71400696251fda6c6a5 to your computer and use it in GitHub Desktop.
Save dims/2ce24579c60fd71400696251fda6c6a5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# NOTE : DO NOT RUN ON macos/arm64 !
# Start a kubekins container to run tests
sudo mkdir /tmp/docker-graph
cd ~/go/src/k8s.io/kubernetes
cat << 'EOF' | sudo tee /tmp/docker-graph/local-up.sh
# tell docker to start CRI service
cat <<'DOCKEREOF' >> /etc/default/docker
DOCKER_OPTS="${DOCKER_OPTS} --cri-containerd"
DOCKEREOF
# ensure docker starts
runner.sh
service docker start
# configure shared mounts to prevent failure in DIND scenarios
mount --make-rshared /
# kubekins has a special directory for docker root
export DOCKER_ROOT="/docker-graph"
export KUBETEST_IN_DOCKER=false
# install missing stuff
apt update && apt install -y conntrack vim sudo htop ripgrep
apt-get remove -y systemd
# setup config needed for local-up-cluster.sh
cd /go/src/k8s.io/kubernetes
#install etcd
hack/install-etcd.sh
export PATH="${PWD}/third_party/etcd:${PATH}"
echo "PATH: $PATH"
# disable ipv6
sysctl -w net.ipv6.conf.all.disable_ipv6=0
sysctl -w net.ipv6.conf.default.disable_ipv6=0
sysctl -w net.ipv6.conf.eth0.disable_ipv6=0
sysctl -p
# setup ip address
export IP=$((ip addr show docker0 || ip addr show eth0) | grep ' inet ' | cut -f 1 -d '/' | awk '{print $2}')
echo "IP Address: $IP"
export API_HOST_IP=$IP
export HOSTNAME_OVERRIDE=$IP
export KUBELET_HOST="0.0.0.0"
export ENABLE_DAEMON=true
export ALLOW_PRIVILEGED=true
# CRI socket
export CONTAINER_RUNTIME_ENDPOINT=/var/run/docker/containerd/containerd.sock
# note this directory will be available on your host as /tmp/docker-graph/logs/
export LOG_DIR=/docker-graph/logs
mkdir -p $LOG_DIR
# mark k8s.io as safe directory
git config --global --add safe.directory /go/src/k8s.io/kubernetes
# build stuff we need
make WHAT="test/e2e/e2e.test vendor/github.com/onsi/ginkgo/ginkgo"
# run it!
hack/local-up-cluster.sh
EOF
sudo chmod +x /tmp/docker-graph/local-up.sh
export IMAGE=gcr.io/k8s-staging-test-infra/kubekins-e2e:v20231122-5f461e0995-master
docker run -e DOCKER_IN_DOCKER_ENABLED=true --privileged --rm \
--entrypoint=/bin/bash \
-it \
-v /tmp/docker-graph:/docker-graph \
-v $HOME/go/src/k8s.io/kubernetes:/go/src/k8s.io/kubernetes \
$IMAGE -c "/docker-graph/local-up.sh; cd /go/src/k8s.io/kubernetes; /bin/bash"
# on the shell prompt, you can check if things are running (you can use the same shell as above or start another one using docker exec)
export KUBECONFIG=/var/run/kubernetes/admin.kubeconfig
kubectl get nodes
# build and run tests (you can use the same shell as above or start another one using docker exec)
export KUBECONFIG=/var/run/kubernetes/admin.kubeconfig
cd /go/src/k8s.io/kubernetes
# if you need to rebuild the test suite if you are making changes locally here
# make WHAT="test/e2e/e2e.test vendor/github.com/onsi/ginkgo/ginkgo"
# Run one of these to try a single test
_output/local/go/bin/e2e.test --provider=local --ginkgo.focus="Pods should get a host IP" # this works!!! (both linux and macos/adm64)
_output/local/go/bin/e2e.test --provider=local --ginkgo.focus="HostPort validates that there is no conflict between pods with same hostPort but different hostIP and protocol" # this works!!! (both linux and macos/adm64)
_output/local/go/bin/e2e.test --provider=local --ginkgo.focus="should support OIDC discovery of service account issuer" # this currently fails :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment