Skip to content

Commit

Permalink
Add shellout for port-forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraagnalluri committed Feb 26, 2022
1 parent d911c25 commit 90d42f3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/e2e/framework/helpers/k8s/k8s_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import (
"github.com/apache/incubator-yunikorn-k8shim/test/e2e/framework/configmanager"
)

const hostPort = "9889"
const remotePort = "9080"

type KubeCtl struct {
clientSet *kubernetes.Clientset
kubeConfigPath string
Expand Down Expand Up @@ -127,6 +130,39 @@ func (k *KubeCtl) GetSchedulerPod() (string, error) {
return "", errors.New("YK scheduler pod not found")
}

func (k *KubeCtl) PortForwardPod(name string) error {
app := "kubectl"

arg0 := "port-forward"
arg2 := "-n"

cmd := exec.Command(app, arg0, name, arg2, configmanager.YuniKornTestConfig.YkNamespace, hostPort, remotePort)
stdout, err := cmd.Output()

if err != nil {
fmt.Println(err.Error())
return err
}

// Print the output
fmt.Println(string(stdout))
return nil
}

func (k *KubeCtl) PortForwardSchedulerPod() error {
var schedulerPodName string
err := k.WaitForPodBySelectorRunning(configmanager.YuniKornTestConfig.YkNamespace, fmt.Sprintf("component=%s", configmanager.YKScheduler), 10)
if err != nil {
return err
}
schedulerPodName, err = k.GetSchedulerPod()
if err != nil {
return err
}
return k.PortForwardPod(schedulerPodName)

}

func (k *KubeCtl) UpdatePodWithAnnotation(pod *v1.Pod, namespace, annotationKey, annotationVal string) (*v1.Pod, error) {
annotations := map[string]string{}
if pod.Annotations != nil {
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/recovery_and_restart/recovery_and_restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ var _ = ginkgo.Describe("", func() {
err3 := kClient.WaitForPodBySelectorRunning(configmanager.YuniKornTestConfig.YkNamespace, fmt.Sprintf("component=%s", configmanager.YKScheduler), 10)
Ω(err3).NotTo(gomega.HaveOccurred())
})

ginkgo.AfterEach(func() {
// port-forward the scheduler pod
err := kClient.PortForwardSchedulerPod()
Ω(err).NotTo(gomega.HaveOccurred())
})
})

0 comments on commit 90d42f3

Please sign in to comment.