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

fix: klog verbosity detection #1315

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
jimmidyson marked this conversation as resolved.
Show resolved Hide resolved

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