Skip to content

Commit

Permalink
Automate k0sctl version setting across test suites
Browse files Browse the repository at this point in the history
Removes the need to make manual changes for k0sctl version bumps.
The version is obtained from hack/tool/go.mod which is updated
automatically by dependabot. All the other suites that use k0sctl
now get their k0sctl version by reading it from hack/tool/go.mod.

Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Jan 10, 2024
1 parent a8bf7be commit 6b5bc68
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/check-network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_TERRAFORM_KEY }}
AWS_DEFAULT_REGION: eu-west-1
TF_VERSION: 1.2.2
K0SCTL_VERSION: 0.17.2
KUBECONFIG: ${{ github.workspace }}/kubeconfig

name: "K8s Network Conformance Testing"
Expand Down Expand Up @@ -131,11 +130,16 @@ jobs:
terraform apply -auto-approve
- name: Set k0sctl version
run: |
version=$(cd hack/tool; go list -m -f '{{.Version}}' github.com/k0sproject/k0sctl)
echo "K0SCTL_VERSION=${version}" >> $GITHUB_ENV
- name: Create k0s Cluster using k0sctl
id: k0sctl
run: |
# download k0sctl
curl --silent -L "https://github.com/k0sproject/k0sctl/releases/download/v${K0SCTL_VERSION}/k0sctl-linux-x64" -o k0sctl
curl --silent -L "https://github.com/k0sproject/k0sctl/releases/download/${K0SCTL_VERSION}/k0sctl-linux-x64" -o k0sctl
chmod +x ./k0sctl
./k0sctl apply -c k0sctl.yaml
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/ostests-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ on:
type: string
description: The Terraform version to use when provisioning test resources.
default: 1.4.6
k0sctl-version:
type: string
description: The k0sctl version to use when bootstrapping the test cluster.
default: 0.17.2
secrets:
aws-access-key-id:
description: The AWS access key ID to use when provisioning test resources.
Expand Down Expand Up @@ -93,17 +89,22 @@ jobs:
name: k0s-linux-amd64
path: ${{ github.workspace }}/.cache

- name: Set k0sctl version
run: |
version=$(grep k0sproject/k0sctl hack/tool/go.mod|cut -d" " -f2)
echo "Detected k0sctl dependency version ${version}"
echo "K0SCTL_VERSION=${version}" >> $GITHUB_ENV
- name: "Terraform :: Requisites :: Prepare"
env:
K0SCTL_VERSION: ${{ inputs.k0sctl-version }}
K0S_VERSION: ${{ inputs.k0s-version }}
K0S_EXECUTABLE_PATH: ${{ github.workspace }}/.cache/k0s
run: |
kubectl version --client
jq --version
mkdir -p "$(dirname -- "$TF_VAR_k0sctl_executable_path")"
curl -sSLo "$TF_VAR_k0sctl_executable_path" "https://github.com/k0sproject/k0sctl/releases/download/v${K0SCTL_VERSION}/k0sctl-linux-x64"
curl -sSLo "$TF_VAR_k0sctl_executable_path" "https://github.com/k0sproject/k0sctl/releases/download/${K0SCTL_VERSION}/k0sctl-linux-x64"
chmod +x -- "$TF_VAR_k0sctl_executable_path"
"$TF_VAR_k0sctl_executable_path" version
Expand Down
2 changes: 2 additions & 0 deletions inttest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ check-nllb: TIMEOUT=15m
include Makefile.variables

$(smoketests): K0S_PATH ?= $(realpath ../k0s)
$(smoketests): K0SCTL_VERSION ?= $(shell grep k0sproject/k0sctl ../hack/tool/go.mod | cut -d" " -f2)
$(smoketests): K0S_IMAGES_BUNDLE ?= $(realpath ../airgap-image-bundle-linux-$(ARCH).tar)
$(smoketests): .bootloose-alpine.stamp
$(smoketests): TEST_PACKAGE ?= $(subst check-,,$@)
Expand All @@ -123,6 +124,7 @@ $(smoketests):
K0S_UPDATE_FROM_PATH='$(K0S_UPDATE_FROM_PATH)' \
K0S_IMAGES_BUNDLE='$(K0S_IMAGES_BUNDLE)' \
K0S_UPDATE_TO_VERSION='$(K0S_UPDATE_TO_VERSION)' \
K0SCTL_VERSION='$(K0SCTL_VERSION)' \
go test -count=1 -v -timeout $(TIMEOUT) github.com/k0sproject/k0s/inttest/$(TEST_PACKAGE)
.PHONY: clean

Expand Down
19 changes: 11 additions & 8 deletions inttest/k0sctl/k0sctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ type K0sctlSuite struct {
k0sctlEnv []string
}

func (s *K0sctlSuite) haveLatest() bool {
func (s *K0sctlSuite) haveVersion(version string) bool {
cmd := exec.Command("./k0sctl", "version")
cmd.Env = s.k0sctlEnv
out, err := cmd.Output()
if err != nil {
return false
}
return strings.Contains(string(out), fmt.Sprintf("%s\n", k0sctlVersion))
return strings.Contains(string(out), fmt.Sprintf("%s\n", version))
}

func k0sctlFilename() string {
Expand All @@ -76,15 +76,15 @@ func k0sctlFilename() string {
return fmt.Sprintf("k0sctl-%s-%s%s", os, arch, ext)
}

func (s *K0sctlSuite) downloadK0sctl() {
if s.haveLatest() {
s.T().Logf("Already have k0sctl %s", k0sctlVersion)
func (s *K0sctlSuite) downloadK0sctl(version string) {
if s.haveVersion(version) {
s.T().Logf("Already have k0sctl %s", version)
return
}

s.T().Logf("Downloading k0sctl %s", k0sctlVersion)
s.T().Logf("Downloading k0sctl %s", version)

req, err := http.NewRequest("GET", fmt.Sprintf("https://github.com/k0sproject/k0sctl/releases/download/%s/%s", k0sctlVersion, k0sctlFilename()), nil)
req, err := http.NewRequest("GET", fmt.Sprintf("https://github.com/k0sproject/k0sctl/releases/download/%s/%s", version, k0sctlFilename()), nil)
s.Require().NoError(err)
resp, err := http.DefaultClient.Do(req)
s.Require().NoError(err)
Expand Down Expand Up @@ -187,10 +187,13 @@ func (s *K0sctlSuite) k0sctlApply(cfg map[string]interface{}) {

func (s *K0sctlSuite) TestK0sGetsUp() {
k0sBinaryPath := os.Getenv("K0S_PATH")
s.Require().NotEmpty(k0sBinaryPath, "K0S_PATH env var must be set")
k0sVersion, err := exec.Command(k0sBinaryPath, "version").Output()
s.Require().NoError(err, "failed to get k0s version")
k0sctlVersion := os.Getenv("K0SCTL_VERSION")
s.Require().NotEmpty(k0sctlVersion, "K0SCTL_VERSION env var must be set")

s.downloadK0sctl()
s.downloadK0sctl(k0sctlVersion)
cfg := s.k0sctlInitConfig()

spec, ok := cfg["spec"].(map[string]interface{})
Expand Down

0 comments on commit 6b5bc68

Please sign in to comment.