From b666f7a77a721c254be2251387212e7960ac81e3 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 16 Oct 2024 14:26:51 +0200 Subject: [PATCH 1/2] :robot: Fix upgrade k8s test Bring a more updated kairos version and set the version from the test, instead of hardcoded Signed-off-by: Itxaka --- tests/assets/suc.yaml | 6 ++-- tests/provider_upgrade_k8s_test.go | 36 +++++++++++------------ tests/provider_upgrade_latest_k8s_test.go | 8 +++-- tests/tests_suite_test.go | 1 + 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/tests/assets/suc.yaml b/tests/assets/suc.yaml index 460aba926..e76b177b0 100644 --- a/tests/assets/suc.yaml +++ b/tests/assets/suc.yaml @@ -8,15 +8,13 @@ metadata: k3s-upgrade: server spec: concurrency: 1 - #version: latest - version: "v2.3.1-k3sv1.25.11-k3s1" - + version: "%s" nodeSelector: matchExpressions: - {key: kubernetes.io/hostname, operator: Exists} serviceAccountName: system-upgrade cordon: false upgrade: - image: quay.io/kairos/kairos-opensuse-leap + image: quay.io/kairos/opensuse command: - "/usr/sbin/suc-upgrade" diff --git a/tests/provider_upgrade_k8s_test.go b/tests/provider_upgrade_k8s_test.go index 362685750..9ed4f33c0 100644 --- a/tests/provider_upgrade_k8s_test.go +++ b/tests/provider_upgrade_k8s_test.go @@ -4,11 +4,10 @@ package mos_test import ( "fmt" "os" + "path/filepath" "strings" "time" - "gopkg.in/yaml.v3" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/spectrocloud/peg/matcher" @@ -132,7 +131,22 @@ var _ = Describe("k3s upgrade test", Label("provider", "provider-upgrade-k8s"), Expect(resultStr).To(ContainSubstring("quay.io/kairos")) By("copy upgrade plan") - err = vm.Scp("assets/suc.yaml", "./suc.yaml", "0770") + + version := "v3.2.1" + fullArtifact := fmt.Sprintf("leap-15.6-standard-amd64-generic-%s-k3sv1.31.1-k3s1", version) + + tempDir, err := os.MkdirTemp("", "suc-*") + Expect(err).ToNot(HaveOccurred()) + defer os.RemoveAll(tempDir) + + b, err := os.ReadFile("assets/suc.yaml") + Expect(err).ToNot(HaveOccurred()) + + suc := fmt.Sprintf(string(b), fullArtifact) + err = os.WriteFile(filepath.Join(tempDir, "suc.yaml"), []byte(suc), 0777) + Expect(err).ToNot(HaveOccurred()) + + err = vm.Scp(filepath.Join(tempDir, "suc.yaml"), "./suc.yaml", "0770") Expect(err).ToNot(HaveOccurred()) By("apply upgrade plan") @@ -154,27 +168,13 @@ var _ = Describe("k3s upgrade test", Label("provider", "provider-upgrade-k8s"), }, 30*time.Minute, 10*time.Second).ShouldNot(ContainSubstring("ContainerCreating")) By("validate upgraded version") - expectedVersion := getExpectedVersion() Eventually(func() string { out, _ = kubectl(vm, "get pods -A") version, _ := vm.Sudo(getVersionCmd) fmt.Printf("version = %+v\n", version) return version - }, 30*time.Minute, 10*time.Second).Should(ContainSubstring(expectedVersion), func() string { + }, 30*time.Minute, 10*time.Second).Should(ContainSubstring(version), func() string { return out }) }) }) - -func getExpectedVersion() string { - b, err := os.ReadFile("assets/suc.yaml") - Expect(err).ToNot(HaveOccurred()) - - yamlData := make(map[string]interface{}) - err = yaml.Unmarshal(b, &yamlData) - - Expect(err).ToNot(HaveOccurred()) - spec := yamlData["spec"].(map[string]interface{}) - - return strings.TrimSuffix(spec["version"].(string), "-k3s1") -} diff --git a/tests/provider_upgrade_latest_k8s_test.go b/tests/provider_upgrade_latest_k8s_test.go index 190f24185..70ad5f9c9 100644 --- a/tests/provider_upgrade_latest_k8s_test.go +++ b/tests/provider_upgrade_latest_k8s_test.go @@ -172,9 +172,13 @@ var _ = Describe("k3s upgrade test from k8s", Label("provider", "provider-upgrad out, _ = kubectl(vm, "get pods -A") version, err := vm.Sudo(getVersionCmd) if err != nil || !strings.Contains(version, "v") { - // If we met error, keep going with the Eventually - return currentVersion + version, err = vm.Sudo(getVersionCmdOsRelease) + if err != nil || !strings.Contains(version, "v") { + // If we met error, keep going with the Eventually + return currentVersion + } } + return version }, 50*time.Minute, 10*time.Second).ShouldNot(Equal(currentVersion), func() string { out, _ := kubectl(vm, "get pods -A") diff --git a/tests/tests_suite_test.go b/tests/tests_suite_test.go index c06d8e2fb..2fdadd39d 100644 --- a/tests/tests_suite_test.go +++ b/tests/tests_suite_test.go @@ -30,6 +30,7 @@ func TestSuite(t *testing.T) { } var getVersionCmd = ". /etc/kairos-release; [ ! -z \"$KAIROS_VERSION\" ] && echo $KAIROS_VERSION" +var getVersionCmdOsRelease = ". /etc/os-release; [ ! -z \"$KAIROS_VERSION\" ] && echo $KAIROS_VERSION" // https://gist.github.com/sevkin/96bdae9274465b2d09191384f86ef39d // GetFreePort asks the kernel for a free open port that is ready to use. From f12d81eb2b2a6074630fd837fbbf737682fcac6f Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 16 Oct 2024 14:42:40 +0200 Subject: [PATCH 2/2] Bump framework Signed-off-by: Itxaka --- Earthfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Earthfile b/Earthfile index f99868620..7fe8366cf 100644 --- a/Earthfile +++ b/Earthfile @@ -8,7 +8,7 @@ ARG TRIVY_VERSION=0.55.2 # renovate: datasource=docker depName=anchore/grype versioning=semver ARG GRYPE_VERSION=v0.80.1 # renovate: datasource=docker depName=quay.io/kairos/framework versioning=semver -ARG KAIROS_FRAMEWORK_VERSION=v2.14.0 +ARG KAIROS_FRAMEWORK_VERSION=v2.14.1 # renovate: datasource=docker depName=quay.io/kairos/osbuilder-tools versioning=semver ARG OSBUILDER_VERSION=v0.400.0 # renovate: datasource=docker depName=golang versioning=semver