From 57618d86372e46966d095dd3dbe1b0d22ca9af65 Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:50:55 +0100 Subject: [PATCH] cleanup uninstall flags Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- pkg/install/helm/flags.go | 31 +++++++++++++++++++++++++++++++ pkg/install/install.go | 2 +- pkg/install/util.go | 11 +---------- pkg/uninstall/uninstall.go | 16 +++++++--------- 4 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 pkg/install/helm/flags.go diff --git a/pkg/install/helm/flags.go b/pkg/install/helm/flags.go new file mode 100644 index 0000000..42157d0 --- /dev/null +++ b/pkg/install/helm/flags.go @@ -0,0 +1,31 @@ +/* +Copyright 2021 The cert-manager Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package helm + +import ( + "time" + + "github.com/spf13/pflag" +) + +// Flags that are shared between the Install and the Uninstall command +func AddInstallUninstallFlags(f *pflag.FlagSet, timeout *time.Duration, wait *bool) { + f.DurationVar(timeout, "timeout", 300*time.Second, "Time to wait for any individual Kubernetes operation (like Jobs for hooks)") + f.MarkHidden("timeout") + f.BoolVar(wait, "wait", true, "If set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful. It will wait for as long as --timeout") + f.MarkHidden("wait") +} diff --git a/pkg/install/install.go b/pkg/install/install.go index 12d0d70..d34a2ad 100644 --- a/pkg/install/install.go +++ b/pkg/install/install.go @@ -112,7 +112,7 @@ func NewCmdInstall(ctx context.Context, ioStreams genericclioptions.IOStreams) * settings.Setup(ctx, cmd) - addInstallUninstallFlags(cmd.Flags(), &options.client.Timeout, &options.Wait) + helm.AddInstallUninstallFlags(cmd.Flags(), &options.client.Timeout, &options.Wait) addInstallFlags(cmd.Flags(), options.client) addValueOptionsFlags(cmd.Flags(), options.valueOpts) diff --git a/pkg/install/util.go b/pkg/install/util.go index 9ad04e8..4b8dd1b 100644 --- a/pkg/install/util.go +++ b/pkg/install/util.go @@ -19,7 +19,6 @@ package install import ( "os" "path/filepath" - "time" "github.com/spf13/pflag" "helm.sh/helm/v3/pkg/action" @@ -27,14 +26,6 @@ import ( "k8s.io/client-go/util/homedir" ) -// Flags that are shared between the Install and the Uninstall command -func addInstallUninstallFlags(f *pflag.FlagSet, timeout *time.Duration, wait *bool) { - f.DurationVar(timeout, "timeout", 300*time.Second, "Time to wait for any individual Kubernetes operation (like Jobs for hooks)") - f.MarkHidden("timeout") - f.BoolVar(wait, "wait", true, "If set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful. It will wait for as long as --timeout") - f.MarkHidden("wait") -} - func addInstallFlags(f *pflag.FlagSet, client *action.Install) { f.StringVar(&client.ReleaseName, "release-name", "cert-manager", "Name of the helm release") f.MarkHidden("release-name") @@ -42,7 +33,7 @@ func addInstallFlags(f *pflag.FlagSet, client *action.Install) { f.MarkHidden("generate-name") f.StringVar(&client.NameTemplate, "name-template", "", "Specify template used to name the release") f.MarkHidden("name-template") - f.StringVar(&client.Description, "description", "Cert-manager was installed using the cert-manager CLI", "Add a custom description") + f.StringVar(&client.Description, "description", "cert-manager was installed using the cert-manager CLI", "Add a custom description") f.MarkHidden("description") } diff --git a/pkg/uninstall/uninstall.go b/pkg/uninstall/uninstall.go index 270591f..6705026 100644 --- a/pkg/uninstall/uninstall.go +++ b/pkg/uninstall/uninstall.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "time" "github.com/spf13/cobra" "helm.sh/helm/v3/pkg/action" @@ -36,10 +35,9 @@ type options struct { settings *helm.NormalisedEnvSettings client *action.Uninstall - releaseName string - disableHooks bool - dryRun bool - wait bool + releaseName string + dryRun bool + wait bool genericclioptions.IOStreams } @@ -100,11 +98,10 @@ func NewCmd(ctx context.Context, ioStreams genericclioptions.IOStreams) *cobra.C settings.Setup(ctx, cmd) - cmd.Flags().DurationVar(&options.client.Timeout, "timeout", 5*time.Minute, "time to wait for any individual Kubernetes operation (like Jobs for hooks)") + helm.AddInstallUninstallFlags(cmd.Flags(), &options.client.Timeout, &options.wait) + cmd.Flags().StringVar(&options.releaseName, "release-name", releaseName, "name of the helm release to uninstall") - cmd.Flags().BoolVar(&options.wait, "wait", true, "if set, will wait until all the resources are deleted before returning. It will wait for as long as --timeout") cmd.Flags().BoolVar(&options.dryRun, "dry-run", false, "simulate uninstall and output manifests to be deleted") - cmd.Flags().BoolVar(&options.disableHooks, "no-hooks", false, "prevent hooks from running during uninstallation (pre- and post-uninstall hooks)") return cmd } @@ -112,7 +109,8 @@ func NewCmd(ctx context.Context, ioStreams genericclioptions.IOStreams) *cobra.C // run assumes cert-manager was installed as a Helm release named cert-manager. // this is not configurable to avoid uninstalling non-cert-manager releases. func run(ctx context.Context, o options) (*release.UninstallReleaseResponse, error) { - o.client.DisableHooks = o.disableHooks + // The cert-manager Helm chart currently does not have any uninstall hooks. + o.client.DisableHooks = false o.client.DryRun = o.dryRun o.client.Wait = o.wait