Skip to content

Commit

Permalink
Merge pull request #30 from inteon/uninstall_flags
Browse files Browse the repository at this point in the history
Cleanup uninstall flags
  • Loading branch information
jetstack-bot authored Mar 4, 2024
2 parents b8a5bdf + 57618d8 commit 9ab4727
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
31 changes: 31 additions & 0 deletions pkg/install/helm/flags.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 1 addition & 1 deletion pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions pkg/install/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,21 @@ package install
import (
"os"
"path/filepath"
"time"

"github.com/spf13/pflag"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli/values"
"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")
f.BoolVarP(&client.GenerateName, "generate-name", "g", false, "Generate the name (instead of using the default 'cert-manager' value)")
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")
}

Expand Down
16 changes: 7 additions & 9 deletions pkg/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action"
Expand All @@ -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
}
Expand Down Expand Up @@ -100,19 +98,19 @@ 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
}

// 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

Expand Down

0 comments on commit 9ab4727

Please sign in to comment.