From d4102e75a657f61a999b775c40e149d84b5bcf09 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Fri, 19 Jan 2024 16:16:02 +0100 Subject: [PATCH] Drop k0sctl integration test The k0s CI uses k0sctl in several places these days: The nightly check-network workflow, the OS testing matrix, and most importantly, the release pipeline. The individual k0sctl integration test is no longer needed. Signed-off-by: Tom Wieczorek --- inttest/Makefile | 2 - inttest/Makefile.variables | 1 - inttest/k0sctl/.gitignore | 1 - inttest/k0sctl/k0sctl_test.go | 230 ---------------------------------- 4 files changed, 234 deletions(-) delete mode 100644 inttest/k0sctl/.gitignore delete mode 100644 inttest/k0sctl/k0sctl_test.go diff --git a/inttest/Makefile b/inttest/Makefile index 721dd835af90..889e49c80480 100644 --- a/inttest/Makefile +++ b/inttest/Makefile @@ -115,7 +115,6 @@ 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-,,$@) @@ -124,7 +123,6 @@ $(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 diff --git a/inttest/Makefile.variables b/inttest/Makefile.variables index ac5c579d84b1..ad860c113674 100644 --- a/inttest/Makefile.variables +++ b/inttest/Makefile.variables @@ -38,7 +38,6 @@ smoketests := \ check-hacontrolplane \ check-hostnameoverride \ check-k0scloudprovider \ - check-k0sctl \ check-kine \ check-kubectl \ check-kubeletcertrotate \ diff --git a/inttest/k0sctl/.gitignore b/inttest/k0sctl/.gitignore deleted file mode 100644 index b8fe557a745c..000000000000 --- a/inttest/k0sctl/.gitignore +++ /dev/null @@ -1 +0,0 @@ -k0sctl diff --git a/inttest/k0sctl/k0sctl_test.go b/inttest/k0sctl/k0sctl_test.go deleted file mode 100644 index 386a97578602..000000000000 --- a/inttest/k0sctl/k0sctl_test.go +++ /dev/null @@ -1,230 +0,0 @@ -/* -Copyright 2022 k0s authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package k0sctl - -import ( - "bufio" - "bytes" - "fmt" - "io" - "net/http" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - "sync" - "testing" - - "github.com/stretchr/testify/suite" - "golang.org/x/exp/slices" - "sigs.k8s.io/yaml" - - "github.com/k0sproject/k0s/inttest/common" -) - -type K0sctlSuite struct { - common.BootlooseSuite - k0sctlEnv []string -} - -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", version)) -} - -func k0sctlFilename() string { - var ext string - os := runtime.GOOS - if os == "windows" { - os = "win" - ext = ".exe" - } - - var arch string - switch runtime.GOARCH { - case "amd64": - arch = "x64" - case "arm64", "arm64be": - arch = "arm64" - case "amd64p32", "arm", "armbe": - arch = "arm" - default: - arch = runtime.GOARCH - } - return fmt.Sprintf("k0sctl-%s-%s%s", os, arch, ext) -} - -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", version) - - 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) - - defer resp.Body.Close() - - f, err := os.OpenFile("k0sctl", os.O_CREATE|os.O_WRONLY, 0755) - s.Require().NoError(err) - defer f.Close() - - _, err = io.Copy(f, resp.Body) - s.Require().NoError(err) - s.T().Logf("Download of %s complete", f.Name()) -} - -func (s *K0sctlSuite) k0sctlInitConfig() map[string]interface{} { - nodes := make([]string, s.ControllerCount+s.WorkerCount) - addresses := make([]string, s.ControllerCount+s.WorkerCount) - for i := 0; i < s.ControllerCount; i++ { - nodes[i] = s.ControllerNode(i) - } - for i := 0; i < s.WorkerCount; i++ { - nodes[i+s.ControllerCount] = s.WorkerNode(i) - } - - machines, err := s.InspectMachines(nodes) - s.Require().NoError(err) - - for _, m := range machines { - port, err := m.HostPort(22) - s.Require().NoError(err) - addresses = append(addresses, fmt.Sprintf("127.0.0.1:%d", port)) - } - - ssh, err := s.SSH(s.Context(), nodes[0]) - if err != nil { - s.FailNow("ssh connection failed", "%s", err) - } - ssh.Disconnect() - args := []string{"init", "--controller-count", fmt.Sprintf("%d", s.ControllerCount), "--key-path", ssh.KeyPath, "--user", ssh.User} - args = append(args, addresses...) - cmd := exec.Command("./k0sctl", args...) - cmd.Env = s.k0sctlEnv - out, err := cmd.Output() - s.Require().NoError(err) - - cfg := map[string]interface{}{} - err = yaml.Unmarshal(out, &cfg) - - s.Require().NoError(err) - return cfg -} - -func (s *K0sctlSuite) k0sctlApply(cfg map[string]interface{}) { - plain, err := yaml.Marshal(cfg) - s.Require().NoError(err) - - cacheHome := s.T().TempDir() - s.T().Logf("Applying k0sctl config:\n%s", plain) - cmd := exec.Command("./k0sctl", "apply", "--config", "-") - cmd.Env = append(slices.Clone(s.k0sctlEnv), fmt.Sprintf("XDG_CACHE_HOME=%s", cacheHome)) - cmd.Stdin = bytes.NewReader(plain) - - stdout, err := cmd.StdoutPipe() - s.Require().NoError(err) - stderr, err := cmd.StderrPipe() - s.Require().NoError(err) - - var wg sync.WaitGroup - - wg.Add(1) - go func() { - defer wg.Done() - scanner := bufio.NewScanner(stdout) - for scanner.Scan() { - s.T().Log(scanner.Text()) - } - }() - - wg.Add(1) - go func() { - defer wg.Done() - scanner := bufio.NewScanner(stderr) - for scanner.Scan() { - s.T().Log("STDERR", scanner.Text()) - } - }() - - s.Require().NoError(cmd.Start()) - - err = cmd.Wait() - wg.Wait() - log, logErr := os.ReadFile(filepath.Join(cacheHome, "k0sctl", "k0sctl.log")) - if !s.NoError(logErr) { - log = []byte{} - } - - s.Require().NoError(err, string(log)) -} - -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(k0sctlVersion) - cfg := s.k0sctlInitConfig() - - spec, ok := cfg["spec"].(map[string]interface{}) - s.Require().True(ok, "could not find spec in generated k0sctl.yaml") - hosts, ok := spec["hosts"].([]interface{}) - s.Require().True(ok, "could not find spec.hosts in generated k0sctl.yaml") - - for _, host := range hosts { - h, ok := host.(map[string]interface{}) - s.Require().True(ok, "host not what was expected") - h["uploadBinary"] = true - h["k0sBinaryPath"] = k0sBinaryPath - } - - k0s, ok := spec["k0s"].(map[string]interface{}) - s.Require().True(ok, "could not find spec.k0s in generated k0sctl.yaml") - - k0s["version"] = strings.TrimSpace(string(k0sVersion)) - - s.k0sctlApply(cfg) -} - -func TestK0sctlSuite(t *testing.T) { - s := K0sctlSuite{ - common.BootlooseSuite{ - ControllerCount: 1, - WorkerCount: 1, - }, - []string{ - fmt.Sprintf("USER=%s", t.Name()), - fmt.Sprintf("HOME=%s", t.TempDir()), - fmt.Sprintf("TMPDIR=%s", t.TempDir()), - }, - } - suite.Run(t, &s) -}