Skip to content

Commit 8589809

Browse files
authored
test: verify kubectl exec functionality (#21)
1 parent 1c4fe6c commit 8589809

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/functional-test/cluster_orch_functional_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,28 @@ var _ = Describe("Cluster Orch Functional tests", Ordered, Label(clusterOrchFunc
181181
cmd := exec.Command("clusterctl", "get", "kubeconfig", clusterName, "--namespace", defaultNamespace) // ">", "kubeconfig.yaml")
182182
output, err := cmd.Output()
183183
Expect(err).NotTo(HaveOccurred())
184+
184185
kubeConfigName := "kubeconfig.yaml"
185186
err = os.WriteFile(kubeConfigName, output, 0644)
186187
Expect(err).NotTo(HaveOccurred())
188+
187189
By("Setting in kubeconfig server to cluster connect gateway")
188190
cmd = exec.Command("sed", "-i", "s|http://[[:alnum:].-]*:8080/|http://127.0.0.1:8081/|", "kubeconfig.yaml")
189191
_, err = cmd.Output()
190192
Expect(err).NotTo(HaveOccurred())
193+
191194
By("Getting list of pods")
192195
cmd = exec.Command("kubectl", "--kubeconfig", "kubeconfig.yaml", "get", "pods")
193196
_, err = cmd.Output()
194197
Expect(err).NotTo(HaveOccurred())
198+
199+
// Exec into one of the pods in the kube-system namespace on the edge node cluster
200+
By("Executing command in kube-scheduler-cluster-agent-0 pod")
201+
cmd = exec.Command("kubectl", "exec", "-it", "-n", "kube-system", "kube-scheduler-cluster-agent-0", "--", "ls")
202+
output, err = cmd.Output()
203+
Expect(err).NotTo(HaveOccurred())
204+
By("Printing the output of the command")
205+
fmt.Printf("Output of `ls` command:\n%s\n", string(output))
195206
})
196207
It("TC-CO-INT-009: Should verify that a cluster template cannot be deleted if there is a cluster using it", func() {
197208
By("Trying to delete the cluster template")

tests/smoke-test/cluster_orch_smoke_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,43 @@ var _ = Describe("TC-CO-INT-001: Single Node RKE2 Cluster Create and Delete usin
162162
// Calculate and print the total time taken
163163
totalTime := clusterCreateEndTime.Sub(clusterCreateStartTime)
164164
fmt.Printf("\033[32mTotal time from cluster creation to fully active: %v 🚀 ✅\033[0m\n", totalTime)
165+
166+
// cmd := exec.Command("curl", "-X", "GET", fmt.Sprintf("127.0.0.1:%v/kubernetes/%v-%v/api/v1/namespaces/default/pods", portForwardGatewayLocalPort, namespace, clusterName))
167+
By("Getting kubeconfig")
168+
fmt.Println(clusterName)
169+
cmd := exec.Command("clusterctl", "get", "kubeconfig", clusterName, "--namespace", defaultNamespace) // ">", "kubeconfig.yaml")
170+
output, err := cmd.Output()
171+
Expect(err).NotTo(HaveOccurred())
172+
173+
kubeConfigName := "kubeconfig.yaml"
174+
err = os.WriteFile(kubeConfigName, output, 0644)
175+
Expect(err).NotTo(HaveOccurred())
176+
177+
By("Setting in kubeconfig server to cluster connect gateway")
178+
cmd = exec.Command("sed", "-i", "s|http://[[:alnum:].-]*:8080/|http://127.0.0.1:8081/|", "kubeconfig.yaml")
179+
_, err = cmd.Output()
180+
Expect(err).NotTo(HaveOccurred())
181+
182+
By("Getting list of pods")
183+
cmd = exec.Command("kubectl", "--kubeconfig", "kubeconfig.yaml", "get", "pods")
184+
_, err = cmd.Output()
185+
Expect(err).NotTo(HaveOccurred())
186+
187+
// Dump kubectl client and server version
188+
By("Dumping kubectl client and server version")
189+
cmd = exec.Command("kubectl", "version", "--kubeconfig", "kubeconfig.yaml")
190+
output, err = cmd.Output()
191+
Expect(err).NotTo(HaveOccurred())
192+
By("Printing the output of the command")
193+
fmt.Printf("kubectl client and server version:\n%s\n", string(output))
194+
195+
// Exec into one of the pods in the kube-system namespace on the edge node cluster
196+
By("Executing command in kube-scheduler-cluster-agent-0 pod")
197+
cmd = exec.Command("kubectl", "exec", "--kubeconfig", "kubeconfig.yaml", "-it", "-n", "kube-system", "kube-scheduler-cluster-agent-0", "--", "ls")
198+
output, err = cmd.Output()
199+
Expect(err).NotTo(HaveOccurred())
200+
By("Printing the output of the command")
201+
fmt.Printf("Output of `ls` command:\n%s\n", string(output))
165202
})
166203

167204
JustAfterEach(func() {

0 commit comments

Comments
 (0)