diff --git a/cmd/tk/install.go b/cmd/tk/install.go index f7244987..ee3df1b1 100644 --- a/cmd/tk/install.go +++ b/cmd/tk/install.go @@ -4,12 +4,12 @@ import ( "bytes" "context" "fmt" - "github.com/spf13/cobra" "io" "os" "os/exec" "strings" - "time" + + "github.com/spf13/cobra" ) var installCmd = &cobra.Command{ @@ -47,7 +47,6 @@ func installCmdRun(cmd *cobra.Command, args []string) error { } } - timeout := time.Minute * 5 ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -77,8 +76,8 @@ func installCmdRun(cmd *cobra.Command, args []string) error { fmt.Println(`✚`, "verifying installation...") for _, deployment := range []string{"source-controller", "kustomize-controller"} { - command = fmt.Sprintf("kubectl -n %s rollout status deployment %s --timeout=2m", - namespace, deployment) + command = fmt.Sprintf("kubectl -n %s rollout status deployment %s --timeout=%s", + namespace, deployment, timeout.String()) c = exec.CommandContext(ctx, "/bin/sh", "-c", command) c.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf) c.Stderr = io.MultiWriter(os.Stderr, &stderrBuf) diff --git a/cmd/tk/main.go b/cmd/tk/main.go index af1e8423..c0ceb44c 100644 --- a/cmd/tk/main.go +++ b/cmd/tk/main.go @@ -2,14 +2,16 @@ package main import ( "fmt" - "github.com/spf13/cobra" - "k8s.io/client-go/kubernetes" - _ "k8s.io/client-go/plugin/pkg/client/auth" - "k8s.io/client-go/tools/clientcmd" "log" "os" "os/exec" "path/filepath" + "time" + + "github.com/spf13/cobra" + "k8s.io/client-go/kubernetes" + _ "k8s.io/client-go/plugin/pkg/client/auth" + "k8s.io/client-go/tools/clientcmd" ) var VERSION = "0.0.1" @@ -25,6 +27,7 @@ var rootCmd = &cobra.Command{ var ( kubeconfig string namespace string + timeout time.Duration ) func init() { @@ -37,6 +40,8 @@ func init() { } rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "", "gitops-system", "the namespace scope for this operation") + rootCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "", 5*time.Minute, + "timeout for this operation") } func main() { diff --git a/cmd/tk/uninstall.go b/cmd/tk/uninstall.go index 9062bb2b..1459d011 100644 --- a/cmd/tk/uninstall.go +++ b/cmd/tk/uninstall.go @@ -7,7 +7,6 @@ import ( "io" "os" "os/exec" - "time" "github.com/manifoldco/promptui" "github.com/spf13/cobra" @@ -38,7 +37,6 @@ func init() { } func uninstallCmdRun(cmd *cobra.Command, args []string) error { - timeout := time.Minute * 5 ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -61,8 +59,8 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error { kinds += ",crds" } - command := fmt.Sprintf("kubectl delete %s -l app.kubernetes.io/instance=%s %s", - kinds, namespace, dryRun) + command := fmt.Sprintf("kubectl delete %s -l app.kubernetes.io/instance=%s --timeout=%s %s", + kinds, namespace, timeout.String(), dryRun) c := exec.CommandContext(ctx, "/bin/sh", "-c", command) var stdoutBuf, stderrBuf bytes.Buffer