github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/cmd/chore/e2e/run/kubectl.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 "os/exec" 8 "time" 9 ) 10 11 type newKubectlCommandFunc func(context.Context) *exec.Cmd 12 13 func configureKubectl(kubeconfig string) newKubectlCommandFunc { 14 return func(ctx context.Context) *exec.Cmd { 15 return exec.CommandContext(ctx, "kubectl", "--kubeconfig", kubeconfig) 16 } 17 } 18 19 type downloadKubeconfig func(context.Context, newOrbctlCommandFunc) (err error) 20 21 func downloadKubeconfigFunc(settings programSettings, to string) (downloadKubeconfig, func() error) { 22 return func(ctx context.Context, orbctl newOrbctlCommandFunc) (err error) { 23 24 readsecretCtx, readsecretCancel := context.WithTimeout(ctx, 10*time.Second) 25 defer readsecretCancel() 26 27 file, err := os.Create(to) 28 if err != nil { 29 return err 30 } 31 defer file.Close() 32 33 return runCommand(settings, nil, file, nil, orbctl(readsecretCtx), "--gitops", "readsecret", fmt.Sprintf("orbiter.%s.kubeconfig.encrypted", settings.orbID)) 34 35 }, func() error { 36 return os.Remove(to) 37 } 38 }