From ab440e31c06420fedc16382673dc90b03ec8fa9b Mon Sep 17 00:00:00 2001 From: adjoly Date: Tue, 16 Dec 2025 21:36:24 +0100 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E2=9C=A8=E3=80=8D=20feat:=20fixed=20t?= =?UTF-8?q?he=20p1=20so=20it=20launch=20in=20one=20command,=20no=20more=20?= =?UTF-8?q?--no-provision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + p1/Vagrantfile | 23 +++++++++++------------ p1/scripts/install-all.sh | 4 ---- p1/scripts/setup-S.sh | 11 +++++++++-- p1/scripts/setup-SW.sh | 34 +++++++++++++++++++++++++++++----- vm/Vagrantfile | 13 +++++++++++++ 6 files changed, 63 insertions(+), 23 deletions(-) delete mode 100644 p1/scripts/install-all.sh create mode 100644 vm/Vagrantfile diff --git a/.gitignore b/.gitignore index 18e50c0..4ad24c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .direnv/ .vagrant/ +*.log iot-box.qcow2 .env diff --git a/p1/Vagrantfile b/p1/Vagrantfile index 21a9566..64ecbc4 100644 --- a/p1/Vagrantfile +++ b/p1/Vagrantfile @@ -23,27 +23,26 @@ end # • Be able to connect with SSH on both machines with no password. Vagrant.configure("2") do |config| - config.vagrant.plugins = [] + config.vm.box = "generic/alpine319" - config.vm.box = "debian/bookworm64" config.vm.provider "#{IOT_PROVIDER}" do |provider| - provider.cpus = 1 - provider.memory = 1024 + provider.cpus = 2 + provider.memory = 2048 end config.vm.define "#{IOT_LOGIN}S" do |server| server.vm.hostname = "#{IOT_LOGIN}S" - server.vm.network "private_network", ip: "192.168.56.110", auto_config: true + server.vm.network "private_network", ip: "192.168.56.110" + server.vm.synced_folder ".", "/vagrant" - server.vm.provision "shell", path: "scripts/install-all.sh" - server.vm.provision "shell", path: "scripts/setup-S.sh" + server.vm.provision "shell", privileged: true, path: "scripts/setup-S.sh" end - config.vm.define "#{IOT_LOGIN}SW" do |serverworker| - serverworker.vm.hostname = "#{IOT_LOGIN}SW" - serverworker.vm.network "private_network", ip: "192.168.56.111", auto_config: true + config.vm.define "#{IOT_LOGIN}SW" do |worker| + worker.vm.hostname = "#{IOT_LOGIN}SW" + worker.vm.network "private_network", ip: "192.168.56.111" + worker.vm.synced_folder ".", "/vagrant" - serverworker.vm.provision "shell", path: "scripts/install-all.sh" - serverworker.vm.provision "shell", path: "scripts/setup-SW.sh" + worker.vm.provision "shell", privileged: true, path: "scripts/setup-SW.sh" end end diff --git a/p1/scripts/install-all.sh b/p1/scripts/install-all.sh deleted file mode 100644 index ef24fd5..0000000 --- a/p1/scripts/install-all.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh - -sudo apt update -sudo apt install curl -y diff --git a/p1/scripts/setup-S.sh b/p1/scripts/setup-S.sh index f6db1b1..12f3d81 100644 --- a/p1/scripts/setup-S.sh +++ b/p1/scripts/setup-S.sh @@ -1,6 +1,13 @@ #!/usr/bin/env sh +S_ADDR="192.168.56.110" + echo "Launching k3s install" -curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--write-kubeconfig-mode 644" sh -s - server --cluster-init --node-ip=192.168.56.110 +curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--write-kubeconfig-mode 644" sh -s - server --cluster-init --node-ip=$S_ADDR --bind-address=$S_ADDR --advertise-address=$S_ADDR + +# Additional wait to ensure API is responsive (optional but helpful) +echo Waiting +sleep 15 + echo "Copying token" -sudo cat /var/lib/rancher/k3s/server/node-token > /vagrant/node-token +cat /var/lib/rancher/k3s/server/node-token > /vagrant/node-token diff --git a/p1/scripts/setup-SW.sh b/p1/scripts/setup-SW.sh index f46315a..21108d7 100644 --- a/p1/scripts/setup-SW.sh +++ b/p1/scripts/setup-SW.sh @@ -1,8 +1,32 @@ #!/usr/bin/env sh -while [ ! -f /vagrant/node-token ]; - do sleep 2; -done +S_ADDR="192.168.56.110" +SW_ADDR="192.168.56.111" -TOKEN=$(cat /vagrant/node-token) -curl -sfL https://get.k3s.io | K3S_URL=https://192.168.56.110:6443 K3S_TOKEN=$TOKEN sh -s - --node-ip=192.168.56.111 +# In setup-SW.sh, before the k3s install command +# echo "Checking connectivity to server" +# I=0 +# while ! curl -k https://$S_ADDR:6443/healthz > /dev/null 2>&1; do +# echo "Server API not reachable yet, waiting..." +# sleep 5 +# I=$((I+1)) +# if [ $I -eq 5 ]; then +# exit 1 +# fi +# done +echo "Server is reachable, proceeding with k3s agent install" + +echo "Waiting for token" +I=0 +while [ ! -f /vagrant/node-token ]; do + sleep 2; + I=$((I+1)) + if [ $I -eq 20 ]; then + echo "threshold gone, ffs" + exit 1 + fi +done +echo "Token found" + +echo "Launching k3s install" +curl -sfL https://get.k3s.io | K3S_URL=https://$S_ADDR:6443 sh -s - agent --node-ip=$SW_ADDR --token-file /vagrant/node-token --server https://$S_ADDR:6443 diff --git a/vm/Vagrantfile b/vm/Vagrantfile new file mode 100644 index 0000000..4079c41 --- /dev/null +++ b/vm/Vagrantfile @@ -0,0 +1,13 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + config.vm.box = "generic/debian12" + config.vm.box_version = "4.3.12" + config.vm.network "public_network" + + config.vm.provision "shell", inline: <<-SHELL + apt-get update -y + apt-get install -y git curl + SHELL +end