consistant naming for kubectl runner
parent
673b82a157
commit
aeaa5733f8
|
@ -28,12 +28,12 @@ import (
|
|||
)
|
||||
|
||||
func testClusterStatus(t *testing.T) {
|
||||
kubectlRunner := util.NewKubectlRunner(t)
|
||||
kr := util.NewKubectlRunner(t)
|
||||
cs := api.ComponentStatusList{}
|
||||
|
||||
healthy := func() error {
|
||||
t.Log("Checking if cluster is healthy.")
|
||||
if err := kubectlRunner.RunCommandParseOutput([]string{"get", "cs"}, &cs); err != nil {
|
||||
if err := kr.RunCommandParseOutput([]string{"get", "cs"}, &cs); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, i := range cs.Items {
|
||||
|
|
|
@ -60,7 +60,7 @@ func testMounting(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
kubectlRunner := util.NewKubectlRunner(t)
|
||||
kr := util.NewKubectlRunner(t)
|
||||
podName := "busybox-mount"
|
||||
curdir, err := filepath.Abs("")
|
||||
if err != nil {
|
||||
|
@ -77,14 +77,14 @@ func testMounting(t *testing.T) {
|
|||
// Create the pods we need outside the main test loop.
|
||||
setupTest := func() error {
|
||||
t.Logf("Deploying pod from: %s", podPath)
|
||||
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {
|
||||
if _, err := kr.RunCommand([]string{"create", "-f", podPath}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
t.Logf("Deleting pod from: %s", podPath)
|
||||
if out, err := kubectlRunner.RunCommand([]string{"delete", "-f", podPath}); err != nil {
|
||||
if out, err := kr.RunCommand([]string{"delete", "-f", podPath}); err != nil {
|
||||
t.Logf("delete -f %s failed: %v\noutput: %s\n", podPath, err, out)
|
||||
}
|
||||
}()
|
||||
|
@ -99,7 +99,7 @@ func testMounting(t *testing.T) {
|
|||
t.Logf("Pods appear to be running")
|
||||
|
||||
mountTest := func() error {
|
||||
if err := verifyFiles(mk, kubectlRunner, tempDir, podName, expected); err != nil {
|
||||
if err := verifyFiles(mk, kr, tempDir, podName, expected); err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ func waitForPods(s map[string]string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func verifyFiles(mk util.MinikubeRunner, kubectlRunner *util.KubectlRunner, tempDir string, podName string, expected string) error {
|
||||
func verifyFiles(mk util.MinikubeRunner, kr *util.KubectlRunner, tempDir string, podName string, expected string) error {
|
||||
path := filepath.Join(tempDir, "frompod")
|
||||
out, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
|
@ -156,7 +156,7 @@ func verifyFiles(mk util.MinikubeRunner, kubectlRunner *util.KubectlRunner, temp
|
|||
}
|
||||
|
||||
// test that file written from host was read in by the pod via cat /mount-9p/fromhost;
|
||||
if out, err = kubectlRunner.RunCommand([]string{"logs", podName}); err != nil {
|
||||
if out, err = kr.RunCommand([]string{"logs", podName}); err != nil {
|
||||
return err
|
||||
}
|
||||
if string(out) != expected {
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestPersistence(t *testing.T) {
|
|||
}
|
||||
mk.EnsureRunning()
|
||||
|
||||
kubectlRunner := util.NewKubectlRunner(t)
|
||||
kr := util.NewKubectlRunner(t)
|
||||
curdir, err := filepath.Abs("")
|
||||
if err != nil {
|
||||
t.Errorf("Error getting the file path for current directory: %s", curdir)
|
||||
|
@ -43,7 +43,7 @@ func TestPersistence(t *testing.T) {
|
|||
podPath := path.Join(curdir, "testdata", "busybox.yaml")
|
||||
|
||||
// Create a pod and wait for it to be running.
|
||||
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil {
|
||||
if _, err := kr.RunCommand([]string{"create", "-f", podPath}); err != nil {
|
||||
t.Fatalf("Error creating test pod: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -40,10 +40,10 @@ var (
|
|||
|
||||
func testProvisioning(t *testing.T) {
|
||||
t.Parallel()
|
||||
kubectlRunner := util.NewKubectlRunner(t)
|
||||
kr := util.NewKubectlRunner(t)
|
||||
|
||||
defer func() {
|
||||
if out, err := kubectlRunner.RunCommand([]string{"delete", "pvc", pvcName}); err != nil {
|
||||
if out, err := kr.RunCommand([]string{"delete", "pvc", pvcName}); err != nil {
|
||||
t.Logf("delete pvc %s failed: %v\noutput: %s\n", pvcName, err, out)
|
||||
}
|
||||
}()
|
||||
|
@ -53,7 +53,7 @@ func testProvisioning(t *testing.T) {
|
|||
|
||||
checkStorageClass := func() error {
|
||||
scl := storage.StorageClassList{}
|
||||
if err := kubectlRunner.RunCommandParseOutput([]string{"get", "storageclass"}, &scl); err != nil {
|
||||
if err := kr.RunCommandParseOutput([]string{"get", "storageclass"}, &scl); err != nil {
|
||||
return fmt.Errorf("get storageclass: %v", err)
|
||||
}
|
||||
|
||||
|
@ -88,14 +88,14 @@ func testProvisioning(t *testing.T) {
|
|||
|
||||
// Now create the PVC
|
||||
pvcPath := filepath.Join(*testdataDir, "pvc.yaml")
|
||||
if _, err := kubectlRunner.RunCommand([]string{"create", "-f", pvcPath}); err != nil {
|
||||
if _, err := kr.RunCommand([]string{"create", "-f", pvcPath}); err != nil {
|
||||
t.Fatalf("Error creating pvc: %v", err)
|
||||
}
|
||||
|
||||
// And check that it gets bound to a PV.
|
||||
checkStorage := func() error {
|
||||
pvc := core.PersistentVolumeClaim{}
|
||||
if err := kubectlRunner.RunCommandParseOutput(pvcCmd, &pvc); err != nil {
|
||||
if err := kr.RunCommandParseOutput(pvcCmd, &pvc); err != nil {
|
||||
return err
|
||||
}
|
||||
// The test passes if the volume claim gets bound.
|
||||
|
|
|
@ -83,8 +83,8 @@ func TestStartStop(t *testing.T) {
|
|||
}
|
||||
|
||||
// check for the current-context before and after the stop
|
||||
kubectlRunner := util.NewKubectlRunner(t)
|
||||
currentContext, err := kubectlRunner.RunCommand([]string{"config", "current-context"})
|
||||
kr := util.NewKubectlRunner(t)
|
||||
currentContext, err := kr.RunCommand([]string{"config", "current-context"})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to fetch current-context")
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ func testTunnel(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Log("starting tunnel test...")
|
||||
mk := NewMinikubeRunner(t, "--wait=false")
|
||||
mkNewMinikubeRunner(t, "--wait=false")
|
||||
go func() {
|
||||
output := mk.RunCommand("tunnel --alsologtostderr -v 8 --logtostderr", true)
|
||||
output := mkCommand("tunnel --alsologtostderr -v 8 --logtostderr", true)
|
||||
if t.Failed() {
|
||||
fmt.Println(output)
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func testTunnel(t *testing.T) {
|
|||
t.Fatal(errors.Wrap(err, "cleaning up tunnels"))
|
||||
}
|
||||
|
||||
kubectlRunner := util.NewKubectlRunner(t)
|
||||
kr := util.NewKubectlRunner(t)
|
||||
|
||||
t.Log("deploying nginx...")
|
||||
curdir, err := filepath.Abs("")
|
||||
|
@ -68,7 +68,7 @@ func testTunnel(t *testing.T) {
|
|||
t.Errorf("Error getting the file path for current directory: %s", curdir)
|
||||
}
|
||||
podPath := path.Join(curdir, "testdata", "testsvc.yaml")
|
||||
if _, err := kubectlRunner.RunCommand([]string{"apply", "-f", podPath}); err != nil {
|
||||
if _, err := kr.RunCommand([]string{"apply", "-f", podPath}); err != nil {
|
||||
t.Fatalf("creating nginx ingress resource: %s", err)
|
||||
}
|
||||
|
||||
|
@ -89,13 +89,13 @@ func testTunnel(t *testing.T) {
|
|||
|
||||
t.Log("getting nginx ingress...")
|
||||
|
||||
nginxIP, err := getIngress(kubectlRunner)
|
||||
nginxIP, err := getIngress(kr)
|
||||
if err != nil {
|
||||
t.Errorf("error getting ingress IP for nginx: %s", err)
|
||||
}
|
||||
|
||||
if len(nginxIP) == 0 {
|
||||
stdout, err := describeIngress(kubectlRunner)
|
||||
stdout, err := describeIngress(kr)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("error debugging nginx service: %s", err)
|
||||
|
@ -113,12 +113,12 @@ func testTunnel(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func getIngress(kubectlRunner *util.KubectlRunner) (string, error) {
|
||||
func getIngress(kr *util.KubectlRunner) (string, error) {
|
||||
nginxIP := ""
|
||||
var ret error
|
||||
err := wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
|
||||
cmd := []string{"get", "svc", "nginx-svc", "-o", "jsonpath={.status.loadBalancer.ingress[0].ip}"}
|
||||
stdout, err := kubectlRunner.RunCommand(cmd)
|
||||
stdout, err := kr.RunCommand(cmd)
|
||||
switch {
|
||||
case err == nil:
|
||||
nginxIP = string(stdout)
|
||||
|
@ -137,8 +137,8 @@ func getIngress(kubectlRunner *util.KubectlRunner) (string, error) {
|
|||
return nginxIP, ret
|
||||
}
|
||||
|
||||
func describeIngress(kubectlRunner *util.KubectlRunner) ([]byte, error) {
|
||||
return kubectlRunner.RunCommand([]string{"get", "svc", "nginx-svc", "-o", "jsonpath={.status}"})
|
||||
func describeIngress(kr *util.KubectlRunner) ([]byte, error) {
|
||||
return kr.RunCommand([]string{"get", "svc", "nginx-svc", "-o", "jsonpath={.status}"})
|
||||
}
|
||||
|
||||
// getResponseBody returns the contents of a URL
|
||||
|
|
Loading…
Reference in New Issue