Skip to content

Commit

Permalink
Use DurationVar for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Eckert committed Oct 27, 2022
1 parent 219a925 commit f5ced99
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions cli/cmd/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
defaultWipeData = false

flagTimeout = "timeout"
defaultTimeout = "10m"
defaultTimeout = 10 * time.Minute

flagContext = "context"
flagKubeconfig = "kubeconfig"
Expand All @@ -64,8 +64,7 @@ type Command struct {
flagReleaseName string
flagAutoApprove bool
flagWipeData bool
flagTimeout string
timeoutDuration time.Duration
flagTimeout time.Duration

flagKubeConfig string
flagKubeContext string
Expand Down Expand Up @@ -101,7 +100,7 @@ func (c *Command) init() {
Default: defaultAnyReleaseName,
Usage: "Name of the installation. This can be used to uninstall and/or delete the resources of a specific Helm release.",
})
f.StringVar(&flag.StringVar{
f.DurationVar(&flag.DurationVar{
Name: flagTimeout,
Target: &c.flagTimeout,
Default: defaultTimeout,
Expand Down Expand Up @@ -155,12 +154,6 @@ func (c *Command) Run(args []string) int {
c.UI.Output("Can't set -wipe-data alone. Omit this flag to interactively uninstall, or use it with -auto-approve to wipe all data during the uninstall.", terminal.WithErrorStyle())
return 1
}
duration, err := time.ParseDuration(c.flagTimeout)
if err != nil {
c.UI.Output("unable to parse -%s: %s", flagTimeout, err, terminal.WithErrorStyle())
return 1
}
c.timeoutDuration = duration

// helmCLI.New() will create a settings object which is used by the Helm Go SDK calls.
settings := helmCLI.New()
Expand All @@ -182,7 +175,7 @@ func (c *Command) Run(args []string) int {
}

actionConfig := new(action.Configuration)
actionConfig, err = helm.InitActionConfig(actionConfig, c.flagNamespace, settings, uiLogger)
actionConfig, err := helm.InitActionConfig(actionConfig, c.flagNamespace, settings, uiLogger)
if err != nil {
c.UI.Output(err.Error(), terminal.WithErrorStyle())
return 1
Expand Down Expand Up @@ -427,7 +420,7 @@ func (c *Command) uninstallHelmRelease(releaseName, namespace, releaseType strin
}

uninstall := action.NewUninstall(actionConfig)
uninstall.Timeout = c.timeoutDuration
uninstall.Timeout = c.flagTimeout

res, err := c.helmActionsRunner.Uninstall(uninstall, releaseName)
if err != nil {
Expand Down

0 comments on commit f5ced99

Please sign in to comment.