mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
add normalize function to global FlagSet
This commit is contained in:
parent
9657dd77a3
commit
e2020f62ac
@ -48,6 +48,8 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
|
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
||||||
|
|
||||||
ccmOptions, err := options.NewCloudControllerManagerOptions()
|
ccmOptions, err := options.NewCloudControllerManagerOptions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Fatalf("unable to initialize command options: %v", err)
|
klog.Fatalf("unable to initialize command options: %v", err)
|
||||||
@ -70,12 +72,6 @@ func main() {
|
|||||||
|
|
||||||
command := app.NewCloudControllerManagerCommand(ccmOptions, cloudInitializer, controllerInitializers, fss, wait.NeverStop)
|
command := app.NewCloudControllerManagerCommand(ccmOptions, cloudInitializer, controllerInitializers, fss, wait.NeverStop)
|
||||||
|
|
||||||
// TODO: once we switch everything over to Cobra commands, we can go back to calling
|
|
||||||
// utilflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the
|
|
||||||
// normalize func and add the go flag set by hand.
|
|
||||||
// Here is an sample
|
|
||||||
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
|
||||||
// utilflag.InitFlags()
|
|
||||||
logs.InitLogs()
|
logs.InitLogs()
|
||||||
defer logs.FlushLogs()
|
defer logs.FlushLogs()
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
|
cliflag "k8s.io/component-base/cli/flag"
|
||||||
"k8s.io/component-base/logs"
|
"k8s.io/component-base/logs"
|
||||||
_ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugins
|
_ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugins
|
||||||
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
|
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
|
||||||
@ -32,12 +35,10 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
|
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
||||||
|
|
||||||
command := app.NewAPIServerCommand()
|
command := app.NewAPIServerCommand()
|
||||||
|
|
||||||
// TODO: once we switch everything over to Cobra commands, we can go back to calling
|
|
||||||
// utilflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the
|
|
||||||
// normalize func and add the go flag set by hand.
|
|
||||||
// utilflag.InitFlags()
|
|
||||||
logs.InitLogs()
|
logs.InitLogs()
|
||||||
defer logs.FlushLogs()
|
defer logs.FlushLogs()
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
|
cliflag "k8s.io/component-base/cli/flag"
|
||||||
"k8s.io/component-base/logs"
|
"k8s.io/component-base/logs"
|
||||||
_ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugin
|
_ "k8s.io/component-base/metrics/prometheus/clientgo" // load all the prometheus client-go plugin
|
||||||
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
|
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
|
||||||
@ -34,12 +37,10 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
|
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
||||||
|
|
||||||
command := app.NewControllerManagerCommand()
|
command := app.NewControllerManagerCommand()
|
||||||
|
|
||||||
// TODO: once we switch everything over to Cobra commands, we can go back to calling
|
|
||||||
// utilflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the
|
|
||||||
// normalize func and add the go flag set by hand.
|
|
||||||
// utilflag.InitFlags()
|
|
||||||
logs.InitLogs()
|
logs.InitLogs()
|
||||||
defer logs.FlushLogs()
|
defer logs.FlushLogs()
|
||||||
|
|
||||||
|
@ -33,13 +33,10 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
|
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
||||||
|
|
||||||
command := app.NewSchedulerCommand()
|
command := app.NewSchedulerCommand()
|
||||||
|
|
||||||
// TODO: once we switch everything over to Cobra commands, we can go back to calling
|
|
||||||
// utilflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the
|
|
||||||
// normalize func and add the go flag set by hand.
|
|
||||||
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
|
||||||
// utilflag.InitFlags()
|
|
||||||
logs.InitLogs()
|
logs.InitLogs()
|
||||||
defer logs.FlushLogs()
|
defer logs.FlushLogs()
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@ type NamedFlagSets struct {
|
|||||||
Order []string
|
Order []string
|
||||||
// FlagSets stores the flag sets by name.
|
// FlagSets stores the flag sets by name.
|
||||||
FlagSets map[string]*pflag.FlagSet
|
FlagSets map[string]*pflag.FlagSet
|
||||||
|
// NormalizeNameFunc is the normalize function which used to initialize FlagSets created by NamedFlagSets.
|
||||||
|
NormalizeNameFunc func(f *pflag.FlagSet, name string) pflag.NormalizedName
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlagSet returns the flag set with the given name and adds it to the
|
// FlagSet returns the flag set with the given name and adds it to the
|
||||||
@ -40,7 +42,12 @@ func (nfs *NamedFlagSets) FlagSet(name string) *pflag.FlagSet {
|
|||||||
nfs.FlagSets = map[string]*pflag.FlagSet{}
|
nfs.FlagSets = map[string]*pflag.FlagSet{}
|
||||||
}
|
}
|
||||||
if _, ok := nfs.FlagSets[name]; !ok {
|
if _, ok := nfs.FlagSets[name]; !ok {
|
||||||
nfs.FlagSets[name] = pflag.NewFlagSet(name, pflag.ExitOnError)
|
flagSet := pflag.NewFlagSet(name, pflag.ExitOnError)
|
||||||
|
flagSet.SetNormalizeFunc(pflag.CommandLine.GetNormalizeFunc())
|
||||||
|
if nfs.NormalizeNameFunc != nil {
|
||||||
|
flagSet.SetNormalizeFunc(nfs.NormalizeNameFunc)
|
||||||
|
}
|
||||||
|
nfs.FlagSets[name] = flagSet
|
||||||
nfs.Order = append(nfs.Order, name)
|
nfs.Order = append(nfs.Order, name)
|
||||||
}
|
}
|
||||||
return nfs.FlagSets[name]
|
return nfs.FlagSets[name]
|
||||||
|
Loading…
Reference in New Issue
Block a user