...
1 package dtest
2
3 import (
4 "context"
5 "os"
6 "time"
7
8 "github.com/datawire/ambassador/v2/pkg/k8s"
9 "github.com/datawire/ambassador/v2/pkg/kubeapply"
10 "github.com/datawire/dlib/dexec"
11 "github.com/datawire/dlib/dlog"
12 )
13
14
15
16 func K8sApply(ctx context.Context, ver KubeVersion, files ...string) {
17 if os.Getenv("DOCKER_REGISTRY") == "" {
18 os.Setenv("DOCKER_REGISTRY", DockerRegistry(ctx))
19 }
20 kubeconfig := KubeVersionConfig(ctx, ver)
21 err := kubeapply.Kubeapply(ctx, k8s.NewKubeInfo(kubeconfig, "", ""), 300*time.Second, false, false, files...)
22 if err != nil {
23 dlog.Println(ctx)
24 dlog.Println(ctx, err)
25 dlog.Printf(ctx,
26 "Please note, if this is a timeout, then your kubernetes cluster may not "+
27 "exist or may be unreachable. Check access to your cluster with \"kubectl --kubeconfig %s\".",
28 kubeconfig)
29 dlog.Println(ctx)
30 cmd := dexec.CommandContext(ctx,
31 "kubectl", "--kubeconfig", kubeconfig,
32 "get", "--all-namespaces", "ns,svc,deploy,po",
33 )
34 _ = cmd.Run()
35
36 os.Exit(1)
37 }
38 }
39
View as plain text