From 77a1b7e0a22aa0c75777424b7224ea0a55aa9c1a Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 29 May 2019 10:50:46 -0700 Subject: [PATCH] ref(*): expose klog flags Signed-off-by: Adam Reese --- Gopkg.lock | 2 +- cmd/helm/helm.go | 21 ++++++++++++++++++++- cmd/helm/rollback.go | 2 +- cmd/helm/search.go | 2 +- pkg/kube/log.go | 30 ------------------------------ 5 files changed, 23 insertions(+), 34 deletions(-) delete mode 100644 pkg/kube/log.go diff --git a/Gopkg.lock b/Gopkg.lock index f93bf58d3..9b02085ef 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1710,7 +1710,7 @@ "k8s.io/client-go/tools/clientcmd", "k8s.io/client-go/tools/watch", "k8s.io/client-go/util/homedir", - "k8s.io/kubernetes/pkg/api/legacyscheme", + "k8s.io/klog", "k8s.io/kubernetes/pkg/controller/deployment/util", "k8s.io/kubernetes/pkg/kubectl/cmd/testing", "k8s.io/kubernetes/pkg/kubectl/cmd/util", diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 8bd4dc45a..4dcb17617 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -17,13 +17,18 @@ limitations under the License. package main // import "helm.sh/helm/cmd/helm" import ( + "flag" "fmt" "log" "os" + "strings" "sync" - // Import to initialize client auth plugins. + "github.com/spf13/pflag" "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/klog" + + // Import to initialize client auth plugins. _ "k8s.io/client-go/plugin/pkg/client/auth" "helm.sh/helm/pkg/action" @@ -50,7 +55,16 @@ func logf(format string, v ...interface{}) { } } +func initKubeLogs() { + pflag.CommandLine.SetNormalizeFunc(wordSepNormalizeFunc) + gofs := flag.NewFlagSet("klog", flag.ExitOnError) + klog.InitFlags(gofs) + pflag.CommandLine.AddGoFlagSet(gofs) + pflag.CommandLine.Set("logtostderr", "true") +} + func main() { + initKubeLogs() cmd := newRootCmd(newActionConfig(false), os.Stdout, os.Args[1:]) if err := cmd.Execute(); err != nil { logf("%+v", err) @@ -111,3 +125,8 @@ func getNamespace() string { } return "default" } + +// wordSepNormalizeFunc changes all flags that contain "_" separators +func wordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName { + return pflag.NormalizedName(strings.ReplaceAll(name, "_", "-")) +} diff --git a/cmd/helm/rollback.go b/cmd/helm/rollback.go index ff2236cfa..9c97a4abd 100644 --- a/cmd/helm/rollback.go +++ b/cmd/helm/rollback.go @@ -56,7 +56,7 @@ func newRollbackCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } f := cmd.Flags() - f.IntVarP(&client.Version, "version", "v", 0, "revision number to rollback to (default: rollback to previous release)") + f.IntVar(&client.Version, "version", 0, "revision number to rollback to (default: rollback to previous release)") f.BoolVar(&client.DryRun, "dry-run", false, "simulate a rollback") f.BoolVar(&client.Recreate, "recreate-pods", false, "performs pods restart for the resource if applicable") f.BoolVar(&client.Force, "force", false, "force resource update through delete/recreate if needed") diff --git a/cmd/helm/search.go b/cmd/helm/search.go index 25228ee48..cf3861ef0 100644 --- a/cmd/helm/search.go +++ b/cmd/helm/search.go @@ -65,7 +65,7 @@ func newSearchCmd(out io.Writer) *cobra.Command { f := cmd.Flags() f.BoolVarP(&o.regexp, "regexp", "r", false, "use regular expressions for searching") f.BoolVarP(&o.versions, "versions", "l", false, "show the long listing, with each version of each chart on its own line") - f.StringVarP(&o.version, "version", "v", "", "search using semantic versioning constraints") + f.StringVar(&o.version, "version", "", "search using semantic versioning constraints") return cmd } diff --git a/pkg/kube/log.go b/pkg/kube/log.go deleted file mode 100644 index 24dafc9e0..000000000 --- a/pkg/kube/log.go +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright The Helm 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 kube - -import ( - "flag" - "fmt" - "os" -) - -func init() { - if level := os.Getenv("KUBE_LOG_LEVEL"); level != "" { - flag.Set("vmodule", fmt.Sprintf("loader=%[1]s,round_trippers=%[1]s,request=%[1]s", level)) - flag.Set("logtostderr", "true") - } -}