diff --git a/cmd/pinniped-supervisor/main.go b/cmd/pinniped-supervisor/main.go index dd89c1e0..1ed2ac18 100644 --- a/cmd/pinniped-supervisor/main.go +++ b/cmd/pinniped-supervisor/main.go @@ -32,6 +32,7 @@ import ( "go.pinniped.dev/internal/oidc/jwks" "go.pinniped.dev/internal/oidc/provider" "go.pinniped.dev/internal/oidc/provider/manager" + "go.pinniped.dev/internal/plog" ) const ( @@ -242,6 +243,7 @@ func run(serverInstallationNamespace string, cfg *supervisor.Config) error { func main() { logs.InitLogs() defer logs.FlushLogs() + plog.RemoveKlogGlobalFlags() // move this whenever the below code gets refactored to use cobra klog.Infof("Running %s at %#v", rest.DefaultKubernetesUserAgent(), version.Get()) klog.Infof("Command-line arguments were: %s %s %s", os.Args[0], os.Args[1], os.Args[2]) diff --git a/internal/concierge/server/server.go b/internal/concierge/server/server.go index 62afbb57..bf8e0586 100644 --- a/internal/concierge/server/server.go +++ b/internal/concierge/server/server.go @@ -23,6 +23,7 @@ import ( "go.pinniped.dev/internal/downward" "go.pinniped.dev/internal/dynamiccert" "go.pinniped.dev/internal/here" + "go.pinniped.dev/internal/plog" "go.pinniped.dev/internal/registry/credentialrequest" ) @@ -87,6 +88,8 @@ func addCommandlineFlagsToCommand(cmd *cobra.Command, app *App) { "/etc/podinfo", "path to Downward API volume mount", ) + + plog.RemoveKlogGlobalFlags() } // Boot the aggregated API server, which will in turn boot the controllers. diff --git a/internal/concierge/server/server_test.go b/internal/concierge/server/server_test.go index 790e493e..e61fefbe 100644 --- a/internal/concierge/server/server_test.go +++ b/internal/concierge/server/server_test.go @@ -23,10 +23,9 @@ Usage: pinniped-concierge [flags] Flags: - -c, --config string path to configuration file (default "pinniped.yaml") - --downward-api-path string path to Downward API volume mount (default "/etc/podinfo") - -h, --help help for pinniped-concierge - --log-flush-frequency duration Maximum number of seconds between log flushes (default 5s) + -c, --config string path to configuration file (default "pinniped.yaml") + --downward-api-path string path to Downward API volume mount (default "/etc/podinfo") + -h, --help help for pinniped-concierge ` func TestCommand(t *testing.T) { diff --git a/internal/plog/klog.go b/internal/plog/klog.go new file mode 100644 index 00000000..50f0cfd6 --- /dev/null +++ b/internal/plog/klog.go @@ -0,0 +1,21 @@ +// Copyright 2020 the Pinniped contributors. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package plog + +import "github.com/spf13/pflag" + +// RemoveKlogGlobalFlags attempts to "remove" flags that get unconditionally added by importing klog. +func RemoveKlogGlobalFlags() { + // if this function starts to panic, it likely means that klog stopped mucking with global flags + const globalLogFlushFlag = "log-flush-frequency" + if err := pflag.CommandLine.MarkHidden(globalLogFlushFlag); err != nil { + panic(err) + } + if err := pflag.CommandLine.MarkDeprecated(globalLogFlushFlag, "unsupported"); err != nil { + panic(err) + } + if pflag.CommandLine.Changed(globalLogFlushFlag) { + panic("unsupported global klog flag set") + } +}