Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve kubectl utility in e2e tests #394

Merged
merged 13 commits into from
Oct 8, 2024
4 changes: 2 additions & 2 deletions tests/e2e/controlplane/control_plane_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
bookinfoNamespace = env.Get("BOOKINFO_NAMESPACE", "bookinfo")
multicluster = env.GetBool("MULTICLUSTER", false)

k *kubectl.KubectlBuilder
k kubectl.Kubectl
)

func TestInstall(t *testing.T) {
Expand All @@ -62,5 +62,5 @@ func setup() {
cl, err = k8sclient.InitK8sClient("")
Expect(err).NotTo(HaveOccurred())

k = kubectl.NewKubectlBuilder()
k = kubectl.New()
}
14 changes: 6 additions & 8 deletions tests/e2e/controlplane/control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ spec:
})

It("doesn't continuously reconcile the IstioCNI CR", func() {
Eventually(k.SetNamespace(namespace).Logs).WithArguments("deploy/"+deploymentName, ptr.Of(30*time.Second)).
Eventually(k.WithNamespace(namespace).Logs).WithArguments("deploy/"+deploymentName, ptr.Of(30*time.Second)).
ShouldNot(ContainSubstring("Reconciliation done"), "IstioCNI is continuously reconciling")
k.ResetNamespace()
Success("IstioCNI stopped reconciling")
})
})
Expand Down Expand Up @@ -222,9 +221,8 @@ spec:
})

It("doesn't continuously reconcile the Istio CR", func() {
Eventually(k.SetNamespace(namespace).Logs).WithArguments("deploy/"+deploymentName, ptr.Of(30*time.Second)).
Eventually(k.WithNamespace(namespace).Logs).WithArguments("deploy/"+deploymentName, ptr.Of(30*time.Second)).
ShouldNot(ContainSubstring("Reconciliation done"), "Istio CR is continuously reconciling")
k.ResetNamespace()
Success("Istio CR stopped reconciling")
})
})
Expand Down Expand Up @@ -269,7 +267,7 @@ spec:

When("the Istio CR is deleted", func() {
BeforeEach(func() {
Expect(k.SetNamespace(controlPlaneNamespace).Delete("istio", istioName)).To(Succeed(), "Istio CR failed to be deleted")
Expect(k.WithNamespace(controlPlaneNamespace).Delete("istio", istioName)).To(Succeed(), "Istio CR failed to be deleted")
Success("Istio CR deleted")
})

Expand All @@ -283,7 +281,7 @@ spec:

When("the IstioCNI CR is deleted", func() {
BeforeEach(func() {
Expect(k.SetNamespace(istioCniNamespace).Delete("istiocni", istioCniName)).To(Succeed(), "IstioCNI CR failed to be deleted")
Expect(k.WithNamespace(istioCniNamespace).Delete("istiocni", istioCniName)).To(Succeed(), "IstioCNI CR failed to be deleted")
Success("IstioCNI deleted")
})

Expand Down Expand Up @@ -389,7 +387,7 @@ func getBookinfoURL(version supportedversion.VersionInfo) string {

func deployBookinfo(version supportedversion.VersionInfo) error {
bookinfoURL := getBookinfoURL(version)
err := k.SetNamespace(bookinfoNamespace).Apply(bookinfoURL)
err := k.WithNamespace(bookinfoNamespace).Apply(bookinfoURL)
if err != nil {
return fmt.Errorf("error deploying bookinfo: %w", err)
}
Expand All @@ -398,7 +396,7 @@ func deployBookinfo(version supportedversion.VersionInfo) error {
}

func getProxyVersion(podName, namespace string) (*semver.Version, error) {
output, err := k.SetNamespace(namespace).Exec(
output, err := k.WithNamespace(namespace).Exec(
podName,
"istio-proxy",
`curl -s http://localhost:15000/server_info | grep "ISTIO_VERSION" | awk -F '"' '{print $4}'`)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/dualstack/dualstack_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
multicluster = env.GetBool("MULTICLUSTER", false)
ipFamily = env.Get("IP_FAMILY", "ipv4")

k *kubectl.KubectlBuilder
k kubectl.Kubectl
)

func TestDualStack(t *testing.T) {
Expand All @@ -63,5 +63,5 @@ func setup() {
cl, err = k8sclient.InitK8sClient("")
Expect(err).NotTo(HaveOccurred())

k = kubectl.NewKubectlBuilder()
k = kubectl.New()
}
16 changes: 8 additions & 8 deletions tests/e2e/dualstack/dualstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var _ = Describe("DualStack configuration ", Ordered, func() {
continue
}

Context("Istio version is: "+version.Version.String(), func() {
Context(fmt.Sprintf("Istio version %s", version.Version), func() {
BeforeAll(func() {
Expect(k.CreateNamespace(controlPlaneNamespace)).To(Succeed(), "Istio namespace failed to be created")
Expect(k.CreateNamespace(istioCniNamespace)).To(Succeed(), "IstioCNI namespace failed to be created")
Expand Down Expand Up @@ -205,10 +205,10 @@ spec:
Expect(k.Patch("namespace", SleepNamespace, "merge", `{"metadata":{"labels":{"istio-injection":"enabled"}}}`)).
To(Succeed(), "Error patching sleep namespace")

Expect(k.SetNamespace(DualStackNamespace).Apply(getYAMLPodURL(version, DualStackNamespace))).To(Succeed(), "error deploying tcpDualStack pod")
Expect(k.SetNamespace(IPv4Namespace).Apply(getYAMLPodURL(version, IPv4Namespace))).To(Succeed(), "error deploying ipv4 pod")
Expect(k.SetNamespace(IPv6Namespace).Apply(getYAMLPodURL(version, IPv6Namespace))).To(Succeed(), "error deploying ipv6 pod")
Expect(k.SetNamespace(SleepNamespace).Apply(getYAMLPodURL(version, SleepNamespace))).To(Succeed(), "error deploying sleep pod")
Expect(k.WithNamespace(DualStackNamespace).Apply(getYAMLPodURL(version, DualStackNamespace))).To(Succeed(), "error deploying tcpDualStack pod")
Expect(k.WithNamespace(IPv4Namespace).Apply(getYAMLPodURL(version, IPv4Namespace))).To(Succeed(), "error deploying ipv4 pod")
Expect(k.WithNamespace(IPv6Namespace).Apply(getYAMLPodURL(version, IPv6Namespace))).To(Succeed(), "error deploying ipv6 pod")
Expect(k.WithNamespace(SleepNamespace).Apply(getYAMLPodURL(version, SleepNamespace))).To(Succeed(), "error deploying sleep pod")

Success("dualStack validation pods deployed")
})
Expand Down Expand Up @@ -254,7 +254,7 @@ spec:

When("the Istio CR is deleted", func() {
BeforeEach(func() {
Expect(k.SetNamespace(controlPlaneNamespace).Delete("istio", istioName)).To(Succeed(), "Istio CR failed to be deleted")
Expect(k.WithNamespace(controlPlaneNamespace).Delete("istio", istioName)).To(Succeed(), "Istio CR failed to be deleted")
Success("Istio CR deleted")
})

Expand All @@ -268,7 +268,7 @@ spec:

When("the IstioCNI CR is deleted", func() {
BeforeEach(func() {
Expect(k.SetNamespace(istioCniNamespace).Delete("istiocni", istioCniName)).To(Succeed(), "IstioCNI CR failed to be deleted")
Expect(k.WithNamespace(istioCniNamespace).Delete("istiocni", istioCniName)).To(Succeed(), "IstioCNI CR failed to be deleted")
Success("IstioCNI deleted")
})

Expand Down Expand Up @@ -356,7 +356,7 @@ func getYAMLPodURL(version supportedversion.VersionInfo, namespace string) strin

func checkPodConnectivity(podName, namespace, echoStr string) {
command := fmt.Sprintf(`sh -c 'echo %s | nc tcp-echo.%s 9000'`, echoStr, echoStr)
response, err := k.SetNamespace(namespace).Exec(podName, "sleep", command)
response, err := k.WithNamespace(namespace).Exec(podName, "sleep", command)
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("error connecting to the %q pod", podName))
Expect(response).To(ContainSubstring(fmt.Sprintf("hello %s", echoStr)), fmt.Sprintf("Unexpected response from %s pod", podName))
}
Loading