From 0d1ac64063688d57e973d7e155c4de6125301ac0 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Sat, 21 Dec 2024 01:52:13 +0100 Subject: [PATCH] Some small improvents to intests Only use stdout when fetching the kubeconfig in GetKubeConfig. This make the command work even when it logs something to stderr. When clientcmd.RESTConfigFromKubeConfig failed, the error was checked too late, resulting in a panic. Be fail-fast on some boostrap errors in one inttesst. Signed-off-by: Tom Wieczorek --- inttest/common/bootloosesuite.go | 8 ++++---- inttest/containerdimports/containerd_imports_test.go | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/inttest/common/bootloosesuite.go b/inttest/common/bootloosesuite.go index 9056c3a3aab0..000734fad967 100644 --- a/inttest/common/bootloosesuite.go +++ b/inttest/common/bootloosesuite.go @@ -817,15 +817,15 @@ func (s *BootlooseSuite) GetKubeConfig(node string, k0sKubeconfigArgs ...string) defer ssh.Disconnect() kubeConfigCmd := fmt.Sprintf("%s kubeconfig admin %s", s.K0sFullPath, strings.Join(k0sKubeconfigArgs, " ")) - kubeConf, err := ssh.ExecWithOutput(s.Context(), kubeConfigCmd) - if err != nil { + var kubeConf bytes.Buffer + if err := ssh.Exec(s.Context(), kubeConfigCmd, SSHStreams{Out: &kubeConf}); err != nil { return nil, err } - cfg, err := clientcmd.RESTConfigFromKubeConfig([]byte(kubeConf)) + cfg, err := clientcmd.RESTConfigFromKubeConfig(kubeConf.Bytes()) + s.Require().NoError(err) // The tests are querying the API server quite a lot, so we need to increase the QPS and Burst cfg.QPS = 40.0 cfg.Burst = 400.0 - s.Require().NoError(err) hostURL, err := url.Parse(cfg.Host) if err != nil { diff --git a/inttest/containerdimports/containerd_imports_test.go b/inttest/containerdimports/containerd_imports_test.go index 630d43983560..6265aa22ed74 100644 --- a/inttest/containerdimports/containerd_imports_test.go +++ b/inttest/containerdimports/containerd_imports_test.go @@ -38,17 +38,16 @@ func (s *ContainerdImportsSuite) TestK0sGetsUp() { s.Require().NoError(err) defer ssh.Disconnect() - s.NoError(s.InitController(0)) + s.Require().NoError(s.InitController(0)) - s.NoError(s.RunWorkers()) + s.Require().NoError(s.RunWorkers()) kc, err := s.KubeClient(s.ControllerNode(0)) if err != nil { s.FailNow("failed to obtain Kubernetes client", err) } - err = s.WaitForNodeReady(s.WorkerNode(0), kc) - s.NoError(err) + s.Require().NoError(s.WaitForNodeReady(s.WorkerNode(0), kc)) s.AssertSomeKubeSystemPods(kc)