From 39f1d79ab615aca722745a21a3b65c8bbc7e921d Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Thu, 2 Nov 2023 15:02:17 +0200 Subject: [PATCH] Add a dry-run smoke-test Signed-off-by: Kimmo Lehto --- .github/workflows/go.yml | 1 + .github/workflows/smoke.yml | 22 +++++------ Makefile | 2 +- smoke-test/Makefile | 3 ++ smoke-test/k0sctl-dryrun.yaml | 24 ++++++++++++ smoke-test/smoke-dryrun.sh | 74 +++++++++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 smoke-test/k0sctl-dryrun.yaml create mode 100755 smoke-test/smoke-dryrun.sh diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 13b29494..3688090a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -6,6 +6,7 @@ on: - '**.go' - go.mod - go.sum + - Makefile jobs: gotest: diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index 47ad4743..c4e5808b 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -59,7 +59,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run smoke tests @@ -82,7 +82,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Build image @@ -112,7 +112,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run smoke tests @@ -140,7 +140,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run smoke tests @@ -165,7 +165,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run smoke tests @@ -186,7 +186,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run OS override smoke test @@ -216,7 +216,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run smoke tests @@ -247,7 +247,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run smoke tests @@ -277,7 +277,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run smoke tests @@ -307,7 +307,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run smoke tests @@ -330,7 +330,7 @@ jobs: - {"name":"Compiled binary cache","uses":"actions/download-artifact@v3","with":{"name":"k0sctl","path":"."}} - {"name":"K0sctl cache","uses":"actions/cache@v3","with":{"path":"/var/cache/k0sctl/k0s\n~/.cache/k0sctl/k0s\n","key":"k0sctl-cache"}} - - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh) }}","restore-keys":"kubectl-"}} + - {"name":"Kubectl cache","uses":"actions/cache@v3","with":{"path":"smoke-test/kubectl\n","key":"kubectl-${{ hashFiles('smoke-test/smoke.common.sh') }}","restore-keys":"kubectl-"}} - {"name":"Make binaries executable","run":"chmod +x k0sctl\nchmod +x smoke-test/kubectl"} - name: Run init smoke test diff --git a/Makefile b/Makefile index eca91a84..99d742c8 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ build-all: $(addprefix bin/,$(bins)) bin/checksums.md clean: rm -rf bin/ k0sctl -smoketests := smoke-basic smoke-files smoke-upgrade smoke-reset smoke-os-override smoke-init smoke-backup-restore smoke-dynamic smoke-basic-openssh +smoketests := smoke-basic smoke-files smoke-upgrade smoke-reset smoke-os-override smoke-init smoke-backup-restore smoke-dynamic smoke-basic-openssh smoke-dryrun .PHONY: $(smoketests) $(smoketests): k0sctl $(MAKE) -C smoke-test $@ diff --git a/smoke-test/Makefile b/smoke-test/Makefile index 26b0829b..5d910d5b 100644 --- a/smoke-test/Makefile +++ b/smoke-test/Makefile @@ -37,6 +37,9 @@ smoke-init: $(bootloose) id_rsa_k0s k0sctl smoke-upgrade: $(bootloose) id_rsa_k0s k0sctl ./smoke-upgrade.sh +smoke-dryrun: $(bootloose) id_rsa_k0s k0sctl + ./smoke-dryrun.sh + smoke-reset: $(bootloose) id_rsa_k0s k0sctl ./smoke-reset.sh diff --git a/smoke-test/k0sctl-dryrun.yaml b/smoke-test/k0sctl-dryrun.yaml new file mode 100644 index 00000000..b4e1ad3a --- /dev/null +++ b/smoke-test/k0sctl-dryrun.yaml @@ -0,0 +1,24 @@ +apiVersion: k0sctl.k0sproject.io/v1beta1 +kind: cluster +spec: + hosts: + - role: controller + uploadBinary: true + os: "$OS_OVERRIDE" + ssh: + address: "127.0.0.1" + port: 9022 + keyPath: ./id_rsa_k0s + - role: worker + uploadBinary: true + os: "$OS_OVERRIDE" + ssh: + address: "127.0.0.1" + port: 9023 + keyPath: ./id_rsa_k0s + k0s: + version: "${K0S_VERSION}" + config: + spec: + telemetry: + enabled: false diff --git a/smoke-test/smoke-dryrun.sh b/smoke-test/smoke-dryrun.sh new file mode 100755 index 00000000..a9c66cfb --- /dev/null +++ b/smoke-test/smoke-dryrun.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +K0SCTL_CONFIG=${K0SCTL_CONFIG:-"k0sctl-dryrun.yaml"} + +set -ex + +. ./smoke.common.sh +trap cleanup EXIT + +deleteCluster +createCluster + +remoteCommand() { + local userhost="$1" + shift + echo "* Running command on ${userhost}: $*" + bootloose ssh "${userhost}" -- "$*" +} + +color_echo() { + echo "\033[1;33m$*\033[0m" +} + +# Create config with older version and apply +K0S_VERSION="${K0S_FROM}" +color_echo "* Installing ${K0S_VERSION} using dry-run" +../k0sctl apply --config "${K0SCTL_CONFIG}" --debug --dry-run | tee k0sctl-dry-run.log +remoteCommand "root@manager0" "test ! -d /etc/k0s" +remoteCommand "root@manager0" "test ! -f /etc/k0s/k0s.yaml" +count=$(grep -c "dry-run" k0sctl-dry-run.log) +if [ "${count}" -lt 3 ]; then + echo "Expected at least dry-run lines, got ${count}" + exit 1 +fi +grep -q "write k0s configuration" k0sctl-dry-run.log +echo "* Dry-run filtered log:" +grep "dry-run" k0sctl-dry-run.log + +color_echo "* Installing ${K0S_VERSION} without dry-run" +../k0sctl apply --config "${K0SCTL_CONFIG}" --debug | tee k0sctl.log +remoteCommand "root@manager0" "test -d /etc/k0s" +remoteCommand "root@manager0" "test -f /etc/k0s/k0s.yaml" +remoteCommand "root@manager0" "k0s version | grep -q ${K0S_VERSION}" +grep -q "dry-run" k0sctl.log && exit 1 + +color_echo "* Installing ${K0S_VERSION} with dry-run again" +../k0sctl apply --config "${K0SCTL_CONFIG}" --debug --dry-run | tee k0sctl.log +remoteCommand "root@manager0" "k0s version | grep -q ${K0S_VERSION}" +grep -q "no cluster state altering actions" k0sctl.log + +K0S_VERSION=$(curl -s "https://docs.k0sproject.io/stable.txt") + +color_echo "* Upgrading to k0s latest using dry-run" +../k0sctl apply --config "${K0SCTL_CONFIG}" --debug --dry-run | tee k0sctl-dry-run.log +remoteCommand "root@manager0" "k0s version | grep -q ${K0S_FROM}" +count=$(grep -c "dry-run" k0sctl-dry-run.log) +if [ "${count}" -lt 3 ]; then + echo "Expected at least dry-run lines, got ${count}" + exit 1 +fi +echo "* Dry-run filtered log:" +grep "dry-run" k0sctl-dry-run.log + +color_echo "* Upgrading to k0s latest without dry-run" +../k0sctl apply --config "${K0SCTL_CONFIG}" --debug | tee k0sctl.log +remoteCommand "root@manager0" "k0s version | grep -vq ${K0S_FROM}" +grep -q "dry-run" k0sctl.log && exit 1 + +color_echo "* Upgrading ${K0S_VERSION} with dry-run again" +../k0sctl apply --config "${K0SCTL_CONFIG}" --debug --dry-run | tee k0sctl.log +remoteCommand "root@manager0" "k0s version | grep -q ${K0S_VERSION}" +grep -q "no cluster state altering actions" k0sctl.log + +