Skip to content

Commit

Permalink
retry bootstrapping k3s on failure
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Oct 9, 2023
1 parent a7024de commit 18c0780
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
12 changes: 1 addition & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,7 @@ bin/k3s/clean:

.PHONY: test/k3s-%
test/k3s-%: dist/img.tar bin/k3s dist-%
sudo cp /var/lib/rancher/k3s/agent/etc/containerd/config.toml /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl
echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm]' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl
echo ' runtime_type = "$(PWD)/dist/bin/containerd-shim-$*-v1"' | sudo tee -a /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl
echo "CONTAINERD_NAMESPACE='$(CONTAINERD_NAMESPACE)'" | sudo tee /etc/systemd/system/k3s-runwasi.service.env
echo "NO_PROXY=192.168.0.0/16" | sudo tee -a /etc/systemd/system/k3s-runwasi.service.env
sudo systemctl daemon-reload
sudo systemctl restart k3s-runwasi
timeout 60 bash -c -- 'while ! sudo bin/k3s ctr version; do sleep 1; done'
sudo bin/k3s ctr image import --all-platforms dist/img.tar
timeout 60 bash -c -- 'while [ "$$(sudo bin/k3s kubectl get pods --all-namespaces --no-headers | wc -l)" == "0" ]; do sleep 1; done'
timeout 60 bash -c -- 'while [ "$$(sudo bin/k3s kubectl get pods --all-namespaces --no-headers | grep -vE "Completed|Running" | wc -l)" != "0" ]; do sleep 1; done'
sudo bash -c -- 'while ! timeout 60 test/k3s/bootstrap.sh "$*"; do $(MAKE) bin/k3s/clean bin/k3s; done'
sudo bin/k3s kubectl get pods --all-namespaces
sudo bin/k3s kubectl apply -f test/k8s/deploy.yaml
sudo bin/k3s kubectl get pods --all-namespaces
Expand Down
21 changes: 21 additions & 0 deletions test/k3s/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -ex

rm -f /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl
cp -f /var/lib/rancher/k3s/agent/etc/containerd/config.toml /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl
cat <<EOF >> /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasm]
runtime_type = "$PWD/dist/bin/containerd-shim-$1-v1"
EOF

cat <<EOF > /etc/systemd/system/k3s-runwasi.service.env
CONTAINERD_NAMESPACE='${CONTAINERD_NAMESPACE:-default}'
NO_PROXY=192.168.0.0/16
EOF

systemctl daemon-reload
systemctl restart k3s-runwasi
while ! bin/k3s ctr version; do sleep 1; done
bin/k3s ctr image import --all-platforms dist/img.tar
while [ "$(bin/k3s kubectl get pods --all-namespaces --no-headers | wc -l)" == "0" ]; do sleep 1; done
while [ "$(bin/k3s kubectl get pods --all-namespaces --no-headers | grep -vE "Completed|Running" | wc -l)" != "0" ]; do sleep 1; done

0 comments on commit 18c0780

Please sign in to comment.