2020-11-10 13:48:42 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package plog
|
|
|
|
|
2020-11-10 16:23:42 +00:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
//nolint: gochecknoglobals
|
|
|
|
var removeKlogGlobalFlagsLock sync.Mutex
|
2020-11-10 13:48:42 +00:00
|
|
|
|
|
|
|
// RemoveKlogGlobalFlags attempts to "remove" flags that get unconditionally added by importing klog.
|
|
|
|
func RemoveKlogGlobalFlags() {
|
2020-11-10 16:23:42 +00:00
|
|
|
// since we mess with global state, we need a lock to synchronize us when called in parallel during tests
|
|
|
|
removeKlogGlobalFlagsLock.Lock()
|
|
|
|
defer removeKlogGlobalFlagsLock.Unlock()
|
|
|
|
|
2020-11-10 13:48:42 +00:00
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
}
|