Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1315 from hectorj2f/hectorj2f/fixes_klog_verbosity
Browse files Browse the repository at this point in the history
fix: klog verbosity detection
  • Loading branch information
k8s-ci-robot authored Nov 11, 2020
2 parents 0668bc0 + 1cdc967 commit ac176c4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
22 changes: 12 additions & 10 deletions cmd/controller-manager/app/controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,18 @@ member clusters and do the necessary reconciliation`,
},
}

// Add the command line flags from other dependencies(klog, kubebuilder, etc.)
cmd.Flags().AddGoFlagSet(flag.CommandLine)

opts.AddFlags(cmd.Flags())
cmd.Flags().StringVar(&healthzAddr, "healthz-addr", healthzDefaultBindAddress, "The address the healthz endpoint binds to.")
cmd.Flags().StringVar(&metricsAddr, "metrics-addr", metricsDefaultBindAddress, "The address the metric endpoint binds to.")
cmd.Flags().BoolVar(&verFlag, "version", false, "Prints the Version info of controller-manager.")
cmd.Flags().StringVar(&kubeFedConfig, "kubefed-config", "", "Path to a KubeFedConfig yaml file. Test only.")
cmd.Flags().StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
cmd.Flags().StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
flags := cmd.Flags()
opts.AddFlags(flags)
flags.StringVar(&healthzAddr, "healthz-addr", healthzDefaultBindAddress, "The address the healthz endpoint binds to.")
flags.StringVar(&metricsAddr, "metrics-addr", metricsDefaultBindAddress, "The address the metric endpoint binds to.")
flags.BoolVar(&verFlag, "version", false, "Prints the Version info of controller-manager.")
flags.StringVar(&kubeFedConfig, "kubefed-config", "", "Path to a KubeFedConfig yaml file. Test only.")
flags.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flags.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")

local := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
klog.InitFlags(local)
flags.AddGoFlagSet(local)

return cmd
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/hyperfed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import (
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

genericapiserver "k8s.io/apiserver/pkg/server"
_ "k8s.io/client-go/plugin/pkg/client/auth" // Load all client auth plugins for GCP, Azure, Openstack, etc
utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"k8s.io/klog"

ctrlapp "sigs.k8s.io/kubefed/cmd/controller-manager/app"
webhookapp "sigs.k8s.io/kubefed/cmd/webhook/app"
Expand All @@ -47,8 +47,11 @@ func main() {

hyperfedCommand, allCommandFns := NewHyperFedCommand()

pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
flags := hyperfedCommand.Flags()
local := goflag.NewFlagSet(os.Args[0], goflag.ExitOnError)
klog.InitFlags(local)
flags.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
flags.AddGoFlagSet(local)

logs.InitLogs()
defer logs.FlushLogs()
Expand Down
12 changes: 8 additions & 4 deletions pkg/kubefedctl/kubefedctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ package kubefedctl
import (
"flag"
"io"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/client-go/tools/clientcmd"
apiserverflag "k8s.io/component-base/cli/flag"
"k8s.io/klog"

"sigs.k8s.io/kubefed/pkg/kubefedctl/enable"
"sigs.k8s.io/kubefed/pkg/kubefedctl/federate"
Expand All @@ -45,9 +46,12 @@ func NewKubeFedCtlCommand(out io.Writer) *cobra.Command {

// Add the command line flags from other dependencies (e.g., klog), but do not
// warn if they contain underscores.
pflag.CommandLine.SetNormalizeFunc(apiserverflag.WordSepNormalizeFunc)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
rootCmd.PersistentFlags().AddFlagSet(pflag.CommandLine)
flags := rootCmd.Flags()
local := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
klog.InitFlags(local)
flags.SetNormalizeFunc(apiserverflag.WordSepNormalizeFunc)
flags.AddGoFlagSet(local)
rootCmd.PersistentFlags().AddFlagSet(flags)

// From this point and forward we get warnings on flags that contain "_" separators
rootCmd.SetGlobalNormalizationFunc(apiserverflag.WarnWordSepNormalizeFunc)
Expand Down

0 comments on commit ac176c4

Please sign in to comment.