Skip to content

Commit

Permalink
🤖 Fix upgrade k8s test (#2947)
Browse files Browse the repository at this point in the history
* 🤖 Fix upgrade k8s test

Bring a more updated kairos version and set the version from the test,
instead of hardcoded

Signed-off-by: Itxaka <itxaka@kairos.io>

* Bump framework

Signed-off-by: Itxaka <itxaka@kairos.io>

---------

Signed-off-by: Itxaka <itxaka@kairos.io>
  • Loading branch information
Itxaka authored Oct 16, 2024
1 parent 3085d54 commit 83c0aef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions tests/assets/suc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
36 changes: 18 additions & 18 deletions tests/provider_upgrade_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -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")
}
8 changes: 6 additions & 2 deletions tests/provider_upgrade_latest_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions tests/tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 83c0aef

Please sign in to comment.