Skip to content

Commit 64a236a

Browse files
committed
test: load worker image into kind
1 parent bbb873f commit 64a236a

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

test/integration/kubernetes/kubernetes_cli_test.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestKubernetesBackendCLIComplexLifecycle(t *testing.T) {
3131
name := "k8s-cli-" + suffix
3232
fixture := e2e.WriteFixture(t, filepath.Join(t.TempDir(), "scroll"), name, port, routePort)
3333
workerImage := e2e.BuildDockerImage(t, "druid-cli-e2e:"+name)
34-
importImageIntoK3DIfCurrentContext(t, workerImage)
34+
importImageIntoCurrentCluster(t, workerImage)
3535
pushArtifact := fmt.Sprintf("127.0.0.1:%d/druid-e2e/%s:v1", registryPort, name)
3636
runtimeArtifact := fmt.Sprintf("%s:%d/druid-e2e/%s:v1", containerHost, registryPort, name)
3737
e2e.RunEnv(t, []string{"DRUID_REGISTRY_PLAIN_HTTP=true", "HOME=" + bins.Home}, bins.Druid, "push", pushArtifact, fixture.Dir)
@@ -143,14 +143,33 @@ func requireKubernetes(t *testing.T) {
143143
}
144144
}
145145

146-
func importImageIntoK3DIfCurrentContext(t *testing.T, image string) {
146+
func importImageIntoCurrentCluster(t *testing.T, image string) {
147147
t.Helper()
148148
contextName := strings.TrimSpace(e2e.Run(t, "kubectl", "config", "current-context"))
149-
if !strings.HasPrefix(contextName, "k3d-") {
150-
return
149+
switch {
150+
case strings.HasPrefix(contextName, "k3d-"):
151+
cluster := strings.TrimPrefix(contextName, "k3d-")
152+
e2e.Run(t, "k3d", "image", "import", image, "--cluster", cluster)
153+
case strings.HasPrefix(contextName, "kind-"):
154+
cluster := strings.TrimPrefix(contextName, "kind-")
155+
e2e.Run(t, kindBinary(t), "load", "docker-image", image, "--name", cluster)
151156
}
152-
cluster := strings.TrimPrefix(contextName, "k3d-")
153-
e2e.Run(t, "k3d", "image", "import", image, "--cluster", cluster)
157+
}
158+
159+
func kindBinary(t *testing.T) string {
160+
t.Helper()
161+
if path, err := exec.LookPath("kind"); err == nil {
162+
return path
163+
}
164+
out, err := exec.Command("go", "env", "GOPATH").Output()
165+
if err != nil {
166+
t.Fatalf("find kind binary: kind is not in PATH and go env GOPATH failed: %v", err)
167+
}
168+
path := filepath.Join(strings.TrimSpace(string(out)), "bin", "kind")
169+
if _, err := os.Stat(path); err != nil {
170+
t.Fatalf("find kind binary: %v", err)
171+
}
172+
return path
154173
}
155174

156175
func applyManifest(t *testing.T, manifest string) {

0 commit comments

Comments
 (0)