Skip to content

Commit

Permalink
Remove unnecessary complexity around Kubectl.name
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Lukša <[email protected]>
  • Loading branch information
luksa committed Feb 6, 2025
1 parent bae66ad commit 2bffd8c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/ambient/ambient_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ func setup() {
cl, err = k8sclient.InitK8sClient("")
Expect(err).NotTo(HaveOccurred())

k = kubectl.New("clAmbient")
k = kubectl.New()
}
2 changes: 1 addition & 1 deletion tests/e2e/controlplane/control_plane_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ func setup() {
cl, err = k8sclient.InitK8sClient("")
Expect(err).NotTo(HaveOccurred())

k = kubectl.New("clControlPlane")
k = kubectl.New()
}
2 changes: 1 addition & 1 deletion tests/e2e/dualstack/dualstack_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ func setup() {
cl, err = k8sclient.InitK8sClient("")
Expect(err).NotTo(HaveOccurred())

k = kubectl.New("clDualStack")
k = kubectl.New()
}
4 changes: 2 additions & 2 deletions tests/e2e/multicluster/multicluster_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ func setup() {
cl, err = k8sclient.InitK8sClient("")
Expect(err).NotTo(HaveOccurred())

k = kubectl.New("clControlPlane")
k = kubectl.New()
}
2 changes: 1 addition & 1 deletion tests/e2e/operator/operator_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ func setup() {
cl, err = k8sclient.InitK8sClient("")
Expect(err).NotTo(HaveOccurred())

k = kubectl.New("clOperator")
k = kubectl.New()
}
8 changes: 6 additions & 2 deletions tests/e2e/util/common/e2e_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("=========================================================")
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 12 additions & 11 deletions tests/e2e/util/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 2bffd8c

Please sign in to comment.