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

Update TestSkaffold to use unique profile names, more debuggable #9064

Merged
merged 3 commits into from
Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions test/integration/skaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ import (
"testing"
"time"

"github.com/docker/machine/libmachine/mcnutils"
"github.com/hashicorp/go-getter"
"github.com/otiai10/copy"
"k8s.io/minikube/pkg/util/retry"
)

func TestSkaffold(t *testing.T) {
if NoneDriver() {
t.Skip("none driver doesn't support `minikube docker-env`; skaffold depends on this command")
}
// can't use a unique profile, as skaffold only recognizes the
// profile name 'minikube' as a local cluster
profile := "minikube"

profile := UniqueProfileName("skaffold")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(5))
defer CleanupWithLogs(t, profile, cancel)

Expand All @@ -51,32 +50,48 @@ func TestSkaffold(t *testing.T) {
}
defer os.Remove(tf.Name())

// start minikube cluster
args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...)
rr, err := Run(t, exec.CommandContext(ctx, Target(), args...))
rr, err := Run(t, exec.CommandContext(ctx, tf.Name(), "version"))
if err != nil {
t.Fatalf("error running skaffold version: %v\n%s", err, rr.Output())
}
t.Logf("skaffold version: %s", rr.Stdout.Bytes())

args := append([]string{"start", "-p", profile, "--memory=2600"}, StartArgs()...)
rr, err = Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Fatalf("starting minikube: %v\n%s", err, rr.Output())
}

// make sure minikube binary is in path so that skaffold can access it
abs, err := filepath.Abs(Target())
// copy minikube binary to minikube
if err := mcnutils.CopyFile(Target(), filepath.Join(filepath.Dir(abs), "minikube")); err != nil {
t.Fatalf("error copying to minikube")
}
if err != nil {
t.Fatalf("absolute path to minikube binary: %v", err)
t.Fatalf("unable to determine abs path: %v", err)
}
os.Setenv("PATH", fmt.Sprintf("%s:%s", filepath.Dir(abs), os.Getenv("PATH")))

if filepath.Base(Target()) != "minikube" {
tstromberg marked this conversation as resolved.
Show resolved Hide resolved
new := filepath.Join(filepath.Dir(abs), "minikube")
t.Logf("copying %s to %s", Target(), new)
if err := copy.Copy(Target(), new); err != nil {
t.Fatalf("error copying to minikube")
}
}

// make sure 'docker' and 'minikube' are on PATH
for _, binary := range []string{"minikube", "docker"} {
rr, err := Run(t, exec.CommandContext(ctx, "which", binary))
_, err := exec.LookPath(binary)
if err != nil {
t.Fatalf("'which %v' failed: check if %v is on PATH\n%v", binary, binary, rr.Output())
t.Fatalf("%q is not in path", binary)
}
}

oldPath := os.Getenv("PATH")
os.Setenv("PATH", fmt.Sprintf("%s:%s", filepath.Dir(abs), os.Getenv("PATH")))
defer func() {
os.Setenv("PATH", oldPath)
}()

// make sure "skaffold run" exits without failure
cmd := exec.CommandContext(ctx, tf.Name(), "run", "--kube-context", profile, "--status-check=true", "--port-forward=false")
cmd := exec.CommandContext(ctx, tf.Name(), "run", "--minikube-profile", profile, "--kube-context", profile, "--status-check=true", "--port-forward=false")
cmd.Dir = "testdata/skaffold"
rr, err = Run(t, cmd)
if err != nil {
Expand Down