Adding optional set kubecontext
parent
59fd6df393
commit
d47d51d8ab
|
@ -40,7 +40,8 @@ import (
|
|||
|
||||
func testAddons(t *testing.T) {
|
||||
t.Parallel()
|
||||
client, err := pkgutil.GetClient()
|
||||
p := "minikube"
|
||||
client, err := pkgutil.GetClient(p)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not get kubernetes client: %v", err)
|
||||
}
|
||||
|
@ -76,7 +77,8 @@ func readLineWithTimeout(b *bufio.Reader, timeout time.Duration) (string, error)
|
|||
|
||||
func testDashboard(t *testing.T) {
|
||||
t.Parallel()
|
||||
mk := NewMinikubeRunner(t, "--wait=false")
|
||||
p := "minikube"
|
||||
mk := NewMinikubeRunner(t, p, "--wait=false")
|
||||
cmd, out := mk.RunDaemon("dashboard --url")
|
||||
defer func() {
|
||||
err := cmd.Process.Kill()
|
||||
|
|
|
@ -39,7 +39,7 @@ func testClusterDNS(t *testing.T) {
|
|||
}
|
||||
|
||||
kr := util.NewKubectlRunner(t, p)
|
||||
busybox := busyBoxPod(t, client, kr)
|
||||
busybox := busyBoxPod(t, client, kr, p)
|
||||
defer func() {
|
||||
if _, err := kr.RunCommand([]string{"delete", "po", busybox}); err != nil {
|
||||
t.Errorf("delete failed: %v", err)
|
||||
|
@ -62,12 +62,12 @@ func testClusterDNS(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func busyBoxPod(t *testing.T, c kubernetes.Interface, kr *util.KubectlRunner) string {
|
||||
func busyBoxPod(t *testing.T, c kubernetes.Interface, kr *util.KubectlRunner, profile string) string {
|
||||
if _, err := kr.RunCommand([]string{"create", "-f", filepath.Join(*testdataDir, "busybox.yaml")}); err != nil {
|
||||
t.Fatalf("creating busybox pod: %s", err)
|
||||
}
|
||||
// TODO(tstromberg): Refactor WaitForBusyboxRunning to return name of pod.
|
||||
if err := util.WaitForBusyboxRunning(t, "default", "minikube"); err != nil {
|
||||
if err := util.WaitForBusyboxRunning(t, "default", profile); err != nil {
|
||||
t.Fatalf("Waiting for busybox pod to be up: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ func testMounting(t *testing.T) {
|
|||
t.Fatal("mountTest failed with error:", err)
|
||||
}
|
||||
|
||||
if err := waitForPods(map[string]string{"integration-test": "busybox-mount"}); err != nil {
|
||||
if err := waitForPods(map[string]string{"integration-test": "busybox-mount"}, p); err != nil {
|
||||
t.Fatalf("Error waiting for busybox mount pod to be up: %v", err)
|
||||
}
|
||||
t.Logf("Pods appear to be running")
|
||||
|
@ -133,8 +133,8 @@ func writeFilesFromHost(mountedDir string, files []string, content string) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func waitForPods(s map[string]string) error {
|
||||
client, err := pkgutil.GetClient()
|
||||
func waitForPods(s map[string]string, profile string) error {
|
||||
client, err := pkgutil.GetClient(profile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting kubernetes client: %v", err)
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func testProvisioning(t *testing.T) {
|
|||
// Check that the storage provisioner pod is running
|
||||
|
||||
checkPodRunning := func() error {
|
||||
client, err := commonutil.GetClient()
|
||||
client, err := commonutil.GetClient(p)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting kubernetes client")
|
||||
}
|
||||
|
|
|
@ -85,12 +85,12 @@ func TestStartStop(t *testing.T) {
|
|||
|
||||
// check for the current-context before and after the stop
|
||||
kr := util.NewKubectlRunner(t, p)
|
||||
currentContext, err := kr.RunCommand([]string{"config", "current-context"})
|
||||
currentContext, err := kr.RunCommand([]string{"config", "current-context"}, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to fetch current-context")
|
||||
}
|
||||
if strings.TrimRight(string(currentContext), "\n") != "minikube" {
|
||||
t.Fatalf("got current-context - %q, want current-context %q", string(currentContext), "minikube")
|
||||
if strings.TrimRight(string(currentContext), "\n") != p {
|
||||
t.Fatalf("got current-context - %q, want current-context %q", string(currentContext), p)
|
||||
}
|
||||
|
||||
checkStop := func() error {
|
||||
|
|
|
@ -73,7 +73,7 @@ func testTunnel(t *testing.T) {
|
|||
t.Fatalf("creating nginx ingress resource: %s", err)
|
||||
}
|
||||
|
||||
client, err := commonutil.GetClient()
|
||||
client, err := commonutil.GetClient(p)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, "getting kubernetes client"))
|
||||
|
|
|
@ -51,12 +51,9 @@ func NewKubectlRunner(t *testing.T, profile ...string) *KubectlRunner {
|
|||
}
|
||||
|
||||
// RunCommandParseOutput runs a command and parses the JSON output
|
||||
func (k *KubectlRunner) RunCommandParseOutput(args []string, outputObj interface{}, setKubeContext ...bool) error {
|
||||
kubecContextArg := fmt.Sprintf(" --context=%s", k.Profile)
|
||||
args = append([]string{kubecContextArg}, args...) // prepending --context so it can be with with -- space
|
||||
|
||||
func (k *KubectlRunner) RunCommandParseOutput(args []string, outputObj interface{}, useKubeContext ...bool) error {
|
||||
args = append(args, "-o=json")
|
||||
output, err := k.RunCommand(args)
|
||||
output, err := k.RunCommand(args, useKubeContext...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -68,9 +65,15 @@ func (k *KubectlRunner) RunCommandParseOutput(args []string, outputObj interface
|
|||
}
|
||||
|
||||
// RunCommand runs a command, returning stdout
|
||||
func (k *KubectlRunner) RunCommand(args []string) (stdout []byte, err error) {
|
||||
kubecContextArg := fmt.Sprintf(" --context=%s", k.Profile)
|
||||
args = append([]string{kubecContextArg}, args...) // prepending --context so it can be with with -- space
|
||||
func (k *KubectlRunner) RunCommand(args []string, useKubeContext ...bool) (stdout []byte, err error) {
|
||||
|
||||
if useKubeContext == nil {
|
||||
useKubeContext = []bool{true}
|
||||
}
|
||||
if useKubeContext[0] {
|
||||
kubecContextArg := fmt.Sprintf("--context=%s", k.Profile)
|
||||
args = append([]string{kubecContextArg}, args...) // prepending --context so it can be with with -- space
|
||||
}
|
||||
|
||||
inner := func() error {
|
||||
cmd := exec.Command(k.BinaryPath, args...)
|
||||
|
|
Loading…
Reference in New Issue