From f7003c4ec1533ddf7e31c6ae8a5ffbfc6b410935 Mon Sep 17 00:00:00 2001 From: George Jenkins Date: Wed, 29 Oct 2025 11:55:03 -0700 Subject: [PATCH] Remove klog flags Signed-off-by: George Jenkins --- go.mod | 2 +- pkg/cmd/flags.go | 24 ------------------------ pkg/cmd/root.go | 1 - 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 858c42fe4..bd1910895 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( k8s.io/apiserver v0.34.1 k8s.io/cli-runtime v0.34.1 k8s.io/client-go v0.34.1 - k8s.io/klog/v2 v2.130.1 + k8s.io/klog/v2 v2.130.1 // indirect k8s.io/kubectl v0.34.1 oras.land/oras-go/v2 v2.6.0 sigs.k8s.io/controller-runtime v0.22.3 diff --git a/pkg/cmd/flags.go b/pkg/cmd/flags.go index b20772ef9..ceeadb65a 100644 --- a/pkg/cmd/flags.go +++ b/pkg/cmd/flags.go @@ -17,7 +17,6 @@ limitations under the License. package cmd import ( - "flag" "fmt" "log" "log/slog" @@ -28,8 +27,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "k8s.io/klog/v2" - "helm.sh/helm/v4/pkg/action" "helm.sh/helm/v4/pkg/cli" "helm.sh/helm/v4/pkg/cli/output" @@ -284,24 +281,3 @@ func compVersionFlag(chartRef string, _ string) ([]string, cobra.ShellCompDirect return versions, cobra.ShellCompDirectiveNoFileComp } - -// addKlogFlags adds flags from k8s.io/klog -// marks the flags as hidden to avoid polluting the help text -func addKlogFlags(fs *pflag.FlagSet) { - local := flag.NewFlagSet("klog", flag.ExitOnError) - klog.InitFlags(local) - local.VisitAll(func(fl *flag.Flag) { - fl.Name = normalize(fl.Name) - if fs.Lookup(fl.Name) != nil { - return - } - newflag := pflag.PFlagFromGoFlag(fl) - newflag.Hidden = true - fs.AddFlag(newflag) - }) -} - -// normalize replaces underscores with hyphens -func normalize(s string) string { - return strings.ReplaceAll(s, "_", "-") -} diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index c23362628..e874e4e40 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -168,7 +168,6 @@ func newRootCmdWithConfig(actionConfig *action.Configuration, out io.Writer, arg flags := cmd.PersistentFlags() settings.AddFlags(flags) - addKlogFlags(flags) // We can safely ignore any errors that flags.Parse encounters since // those errors will be caught later during the call to cmd.Execution.