From ada65b988a33e743e9c043d419b5b7f177eca836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 7 Sep 2023 16:27:21 +0200 Subject: [PATCH] ci: k8s: Use vanilla kubectl with k3s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's download the vanilla kubectl binary into `/usr/bin/`, as we need to avoid hitting issues like: ```sh error: open /etc/rancher/k3s/k3s.yaml.lock: permission denied ``` The issue basically happens because k3s links `/usr/local/bin/kubectl` to `/usr/local/bin/k3s`, and that does extra stuff that vanilla `kubectl` doesn't do. Also, in order to properly use the k3s.yaml config with the vanilla kubectl, we're copying it to ~/.kube/config. Signed-off-by: Fabiano FidĂȘncio --- tests/integration/kubernetes/gha-run.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/integration/kubernetes/gha-run.sh b/tests/integration/kubernetes/gha-run.sh index 567d08282..8dca94a2c 100755 --- a/tests/integration/kubernetes/gha-run.sh +++ b/tests/integration/kubernetes/gha-run.sh @@ -145,6 +145,27 @@ function deploy_k3s() { # This is an arbitrary value that came up from local tests sleep 240s + + # Download the kubectl binary into /usr/bin and remove /usr/local/bin/kubectl + # + # We need to do this to avoid hitting issues like: + # ```sh + # error: open /etc/rancher/k3s/k3s.yaml.lock: permission denied + # ``` + # Which happens basically because k3s links `/usr/local/bin/kubectl` + # to `/usr/local/bin/k3s`, and that does extra stuff that vanilla + # `kubectl` doesn't do. + ARCH=$(uname -m) + if [ "${ARCH}" = "x86_64" ]; then + ARCH=amd64 + fi + kubectl_version=$(/usr/local/bin/k3s kubectl version --short 2>/dev/null | grep "Client Version" | sed -e 's/Client Version: //' -e 's/\+k3s1//') + sudo curl -fL --progress-bar -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${kubectl_version}/bin/linux/${ARCH}/kubectl + sudo chmod +x /usr/bin/kubectl + sudo rm -rf /usr/local/bin/kubectl + + mkdir -p ~/.kube + cp /etc/rancher/k3s/k3s.yaml ~/.kube/config } function deploy_k8s() {