Add timeout option to install/uninstall
This commit is contained in:
@@ -4,12 +4,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var installCmd = &cobra.Command{
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@@ -77,8 +76,8 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
fmt.Println(`✚`, "verifying installation...")
|
fmt.Println(`✚`, "verifying installation...")
|
||||||
for _, deployment := range []string{"source-controller", "kustomize-controller"} {
|
for _, deployment := range []string{"source-controller", "kustomize-controller"} {
|
||||||
command = fmt.Sprintf("kubectl -n %s rollout status deployment %s --timeout=2m",
|
command = fmt.Sprintf("kubectl -n %s rollout status deployment %s --timeout=%s",
|
||||||
namespace, deployment)
|
namespace, deployment, timeout.String())
|
||||||
c = exec.CommandContext(ctx, "/bin/sh", "-c", command)
|
c = exec.CommandContext(ctx, "/bin/sh", "-c", command)
|
||||||
c.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf)
|
c.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf)
|
||||||
c.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
|
c.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"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"
|
var VERSION = "0.0.1"
|
||||||
@@ -25,6 +27,7 @@ var rootCmd = &cobra.Command{
|
|||||||
var (
|
var (
|
||||||
kubeconfig string
|
kubeconfig string
|
||||||
namespace string
|
namespace string
|
||||||
|
timeout time.Duration
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -37,6 +40,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "", "gitops-system",
|
rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "", "gitops-system",
|
||||||
"the namespace scope for this operation")
|
"the namespace scope for this operation")
|
||||||
|
rootCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "", 5*time.Minute,
|
||||||
|
"timeout for this operation")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -38,7 +37,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
timeout := time.Minute * 5
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@@ -61,8 +59,8 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
kinds += ",crds"
|
kinds += ",crds"
|
||||||
}
|
}
|
||||||
|
|
||||||
command := fmt.Sprintf("kubectl delete %s -l app.kubernetes.io/instance=%s %s",
|
command := fmt.Sprintf("kubectl delete %s -l app.kubernetes.io/instance=%s --timeout=%s %s",
|
||||||
kinds, namespace, dryRun)
|
kinds, namespace, timeout.String(), dryRun)
|
||||||
c := exec.CommandContext(ctx, "/bin/sh", "-c", command)
|
c := exec.CommandContext(ctx, "/bin/sh", "-c", command)
|
||||||
|
|
||||||
var stdoutBuf, stderrBuf bytes.Buffer
|
var stdoutBuf, stderrBuf bytes.Buffer
|
||||||
|
|||||||
Reference in New Issue
Block a user