diff --git a/tests/e2e/ambient/ambient_suite_test.go b/tests/e2e/ambient/ambient_suite_test.go index eecfccab4..ec3f17dcb 100644 --- a/tests/e2e/ambient/ambient_suite_test.go +++ b/tests/e2e/ambient/ambient_suite_test.go @@ -62,5 +62,5 @@ func setup() { cl, err = k8sclient.InitK8sClient("") Expect(err).NotTo(HaveOccurred()) - k = kubectl.New("clAmbient") + k = kubectl.New() } diff --git a/tests/e2e/controlplane/control_plane_suite_test.go b/tests/e2e/controlplane/control_plane_suite_test.go index e73d01a11..ce355e11d 100644 --- a/tests/e2e/controlplane/control_plane_suite_test.go +++ b/tests/e2e/controlplane/control_plane_suite_test.go @@ -62,5 +62,5 @@ func setup() { cl, err = k8sclient.InitK8sClient("") Expect(err).NotTo(HaveOccurred()) - k = kubectl.New("clControlPlane") + k = kubectl.New() } diff --git a/tests/e2e/dualstack/dualstack_suite_test.go b/tests/e2e/dualstack/dualstack_suite_test.go index a18166cc4..dd581b58a 100644 --- a/tests/e2e/dualstack/dualstack_suite_test.go +++ b/tests/e2e/dualstack/dualstack_suite_test.go @@ -62,5 +62,5 @@ func setup() { cl, err = k8sclient.InitK8sClient("") Expect(err).NotTo(HaveOccurred()) - k = kubectl.New("clDualStack") + k = kubectl.New() } diff --git a/tests/e2e/multicluster/multicluster_suite_test.go b/tests/e2e/multicluster/multicluster_suite_test.go index d00b9c64e..0865775f5 100644 --- a/tests/e2e/multicluster/multicluster_suite_test.go +++ b/tests/e2e/multicluster/multicluster_suite_test.go @@ -99,6 +99,6 @@ func setup(t *testing.T) { exposeIstiodYAML = fmt.Sprintf("%s/docs/multicluster/expose-istiod.yaml", baseRepoDir) // Initialize kubectl utilities, one for each cluster - k1 = kubectl.New("clPrimary").WithKubeconfig(kubeconfig) - k2 = kubectl.New("clRemote").WithKubeconfig(kubeconfig2) + k1 = kubectl.New().WithClusterName("primary").WithKubeconfig(kubeconfig) + k2 = kubectl.New().WithClusterName("remote").WithKubeconfig(kubeconfig2) } diff --git a/tests/e2e/multicontrolplane/multi_control_plane_suite_test.go b/tests/e2e/multicontrolplane/multi_control_plane_suite_test.go index 26f063b61..fe70e7167 100644 --- a/tests/e2e/multicontrolplane/multi_control_plane_suite_test.go +++ b/tests/e2e/multicontrolplane/multi_control_plane_suite_test.go @@ -67,5 +67,5 @@ func setup() { cl, err = k8sclient.InitK8sClient("") Expect(err).NotTo(HaveOccurred()) - k = kubectl.New("clControlPlane") + k = kubectl.New() } diff --git a/tests/e2e/operator/operator_suite_test.go b/tests/e2e/operator/operator_suite_test.go index 11063b486..700677b5a 100644 --- a/tests/e2e/operator/operator_suite_test.go +++ b/tests/e2e/operator/operator_suite_test.go @@ -57,5 +57,5 @@ func setup() { cl, err = k8sclient.InitK8sClient("") Expect(err).NotTo(HaveOccurred()) - k = kubectl.New("clOperator") + k = kubectl.New() } diff --git a/tests/e2e/util/common/e2e_utils.go b/tests/e2e/util/common/e2e_utils.go index d16839b28..bc97172f2 100644 --- a/tests/e2e/util/common/e2e_utils.go +++ b/tests/e2e/util/common/e2e_utils.go @@ -136,7 +136,11 @@ func LogDebugInfo(k kubectl.Kubectl) { // TODO: Add the creation of file with this information to be attached to the test report GinkgoWriter.Println() - GinkgoWriter.Printf("The test run has failures and the debug information is as follows from cluster: %q:\n", k.GetClusterName()) + if k.ClusterName == "" { + GinkgoWriter.Println("The test run has failures and the debug information is as follows:") + } else { + GinkgoWriter.Printf("The test run has failures and the debug information is as follows (cluster: %q):\n", k.ClusterName) + } GinkgoWriter.Println("=========================================================") logOperatorDebugInfo(k) GinkgoWriter.Println("=========================================================") @@ -218,7 +222,7 @@ func logDebugElement(caption string, info string, err error) { } func GetVersionFromIstiod() (*semver.Version, error) { - k := kubectl.New("testCluster") + k := kubectl.New() output, err := k.WithNamespace(controlPlaneNamespace).Exec("deploy/istiod", "", "pilot-discovery version") if err != nil { return nil, fmt.Errorf("error getting version from istiod: %w", err) diff --git a/tests/e2e/util/kubectl/kubectl.go b/tests/e2e/util/kubectl/kubectl.go index d01e5e9f5..c3b05694e 100644 --- a/tests/e2e/util/kubectl/kubectl.go +++ b/tests/e2e/util/kubectl/kubectl.go @@ -25,15 +25,15 @@ import ( ) type Kubectl struct { - name string - binary string - namespace string - kubeconfig string + ClusterName string + binary string + namespace string + kubeconfig string } // New creates a new kubectl.Kubectl -func New(name string) Kubectl { - return Kubectl{name: name}.WithBinary(os.Getenv("COMMAND")) +func New() Kubectl { + return Kubectl{}.WithBinary(os.Getenv("COMMAND")) } func (k Kubectl) build(cmd string) string { @@ -55,6 +55,12 @@ func (k Kubectl) build(cmd string) string { return strings.Join(args, " ") } +// WithClusterName sets the cluster clusterName on this Kubectl +func (k Kubectl) WithClusterName(name string) Kubectl { + k.ClusterName = name + return k +} + // WithBinary returns a new Kubectl with the binary set to the given value; if the value is "", the binary is set to "kubectl" func (k Kubectl) WithBinary(binary string) Kubectl { if binary == "" { @@ -218,11 +224,6 @@ func (k Kubectl) ForceDelete(kind, name string) error { return k.Delete(kind, name) } -// Gets cluster name defined during initialization -func (k Kubectl) GetClusterName() string { - return k.name -} - // GetYAML returns the yaml of a resource func (k Kubectl) GetYAML(kind, name string) (string, error) { cmd := k.build(fmt.Sprintf(" get %s %s -o yaml", kind, name))