*-controller-manager: fix missing global flags for --help
Kubernetes-commit: 10dd5d663197abae40374c3eaa5c0ec2b638a234
This commit is contained in:
parent
8d90f74522
commit
70d40a2bc9
|
|
@ -19,7 +19,6 @@ package globalflag
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
@ -28,7 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddGlobalFlags explicitly registers flags that libraries (klog, verflag, etc.) register
|
// AddGlobalFlags explicitly registers flags that libraries (klog, verflag, etc.) register
|
||||||
// against the global flagsets from "flag" and "github.com/spf13/pflag".
|
// against the global flagsets from "flag" and "k8s.io/klog".
|
||||||
// We do this in order to prevent unwanted flags from leaking into the component's flagset.
|
// We do this in order to prevent unwanted flags from leaking into the component's flagset.
|
||||||
func AddGlobalFlags(fs *pflag.FlagSet, name string) {
|
func AddGlobalFlags(fs *pflag.FlagSet, name string) {
|
||||||
addGlogFlags(fs)
|
addGlogFlags(fs)
|
||||||
|
|
@ -39,21 +38,16 @@ func AddGlobalFlags(fs *pflag.FlagSet, name string) {
|
||||||
|
|
||||||
// addGlogFlags explicitly registers flags that klog libraries(k8s.io/klog) register.
|
// addGlogFlags explicitly registers flags that klog libraries(k8s.io/klog) register.
|
||||||
func addGlogFlags(fs *pflag.FlagSet) {
|
func addGlogFlags(fs *pflag.FlagSet) {
|
||||||
// lookup flags in global flag set and re-register the values with our flagset
|
// lookup flags of klog libraries in global flag set and re-register the values with our flagset
|
||||||
global := flag.CommandLine
|
Register(fs, "logtostderr")
|
||||||
local := pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)
|
Register(fs, "alsologtostderr")
|
||||||
|
Register(fs, "v")
|
||||||
register(global, local, "logtostderr")
|
Register(fs, "skip_headers")
|
||||||
register(global, local, "alsologtostderr")
|
Register(fs, "stderrthreshold")
|
||||||
register(global, local, "v")
|
Register(fs, "vmodule")
|
||||||
register(global, local, "skip_headers")
|
Register(fs, "log_backtrace_at")
|
||||||
register(global, local, "stderrthreshold")
|
Register(fs, "log_dir")
|
||||||
register(global, local, "vmodule")
|
Register(fs, "log_file")
|
||||||
register(global, local, "log_backtrace_at")
|
|
||||||
register(global, local, "log_dir")
|
|
||||||
register(global, local, "log_file")
|
|
||||||
|
|
||||||
fs.AddFlagSet(local)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize replaces underscores with hyphens
|
// normalize replaces underscores with hyphens
|
||||||
|
|
@ -62,9 +56,9 @@ func normalize(s string) string {
|
||||||
return strings.Replace(s, "_", "-", -1)
|
return strings.Replace(s, "_", "-", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// register adds a flag to local that targets the Value associated with the Flag named globalName in global
|
// Register adds a flag to local that targets the Value associated with the Flag named globalName in flag.CommandLine.
|
||||||
func register(global *flag.FlagSet, local *pflag.FlagSet, globalName string) {
|
func Register(local *pflag.FlagSet, globalName string) {
|
||||||
if f := global.Lookup(globalName); f != nil {
|
if f := flag.CommandLine.Lookup(globalName); f != nil {
|
||||||
pflagFlag := pflag.PFlagFromGoFlag(f)
|
pflagFlag := pflag.PFlagFromGoFlag(f)
|
||||||
pflagFlag.Name = normalize(pflagFlag.Name)
|
pflagFlag.Name = normalize(pflagFlag.Name)
|
||||||
local.AddFlag(pflagFlag)
|
local.AddFlag(pflagFlag)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue