mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-10 17:35:44 -04:00
client-go clientcmd: exclude from structured, contextual logging
The only log output is for error messages which should normally not occur. It's also likely that users expect to see exactly those messages, so it's better to not touch them.
This commit is contained in:
parent
99a2c5c634
commit
8701f481ff
5 changed files with 10 additions and 0 deletions
|
|
@ -679,11 +679,13 @@ func (config *inClusterClientConfig) Possible() bool {
|
|||
// to the default config.
|
||||
func BuildConfigFromFlags(masterUrl, kubeconfigPath string) (*restclient.Config, error) {
|
||||
if kubeconfigPath == "" && masterUrl == "" {
|
||||
//nolint:logcheck // A helper function like this should not log. But this is probably part of the the established client-go API and not worth changing.
|
||||
klog.Warning("Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.")
|
||||
kubeconfig, err := restclient.InClusterConfig()
|
||||
if err == nil {
|
||||
return kubeconfig, nil
|
||||
}
|
||||
//nolint:logcheck // A helper function like this should not log. But this is probably part of the the established client-go API and not worth changing.
|
||||
klog.Warning("error creating inClusterConfig, falling back to default config: ", err)
|
||||
}
|
||||
return NewNonInteractiveDeferredLoadingClientConfig(
|
||||
|
|
|
|||
|
|
@ -492,6 +492,7 @@ func getConfigFromFile(filename string) (*clientcmdapi.Config, error) {
|
|||
func GetConfigFromFileOrDie(filename string) *clientcmdapi.Config {
|
||||
config, err := getConfigFromFile(filename)
|
||||
if err != nil {
|
||||
//nolint:logcheck // A helper function like this should not log. But this is probably part of the the established client-go API and not worth changing.
|
||||
klog.FatalDepth(1, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ type WarningHandler func(error)
|
|||
|
||||
func (handler WarningHandler) Warn(err error) {
|
||||
if handler == nil {
|
||||
//nolint:logcheck // This is the fallback when logging is not initialized. With nothing provided, using the global logger is the only option.
|
||||
klog.V(1).Info(err)
|
||||
} else {
|
||||
handler(err)
|
||||
|
|
@ -402,6 +403,7 @@ func LoadFromFile(filename string) (*clientcmdapi.Config, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//nolint:logcheck // A helper function like this should not log. But this is probably part of the the established client-go API and not worth changing.
|
||||
klog.V(6).Infoln("Config loaded from file: ", filename)
|
||||
|
||||
// set LocationOfOrigin on every Cluster, User, and Context
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ func TestNonExistentCommandLineFile(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//nolint:logcheck // Tests klog APIs.
|
||||
func TestToleratingMissingFiles(t *testing.T) {
|
||||
envVarValue := "bogus"
|
||||
loadingRules := ClientConfigLoadingRules{
|
||||
|
|
@ -146,6 +147,7 @@ func TestToleratingMissingFiles(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//nolint:logcheck // Tests klog APIs.
|
||||
func TestWarningMissingFiles(t *testing.T) {
|
||||
envVarValue := "bogus"
|
||||
t.Setenv(RecommendedConfigPathEnvVar, envVarValue)
|
||||
|
|
@ -171,6 +173,7 @@ func TestWarningMissingFiles(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//nolint:logcheck // Tests klog APIs.
|
||||
func TestNoWarningMissingFiles(t *testing.T) {
|
||||
envVarValue := "bogus"
|
||||
t.Setenv(RecommendedConfigPathEnvVar, envVarValue)
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ func (config *DeferredLoadingClientConfig) ClientConfig() (*restclient.Config, e
|
|||
|
||||
// check for in-cluster configuration and use it
|
||||
if config.icc.Possible() {
|
||||
//nolint:logcheck // A helper function like this should not log. But this is probably part of the the established client-go API and not worth changing.
|
||||
klog.V(4).Infof("Using in-cluster configuration")
|
||||
return config.icc.ClientConfig()
|
||||
}
|
||||
|
|
@ -160,6 +161,7 @@ func (config *DeferredLoadingClientConfig) Namespace() (string, bool, error) {
|
|||
}
|
||||
}
|
||||
|
||||
//nolint:logcheck // A helper function like this should not log. But this is probably part of the the established client-go API and not worth changing.
|
||||
klog.V(4).Infof("Using in-cluster namespace")
|
||||
|
||||
// allow the namespace from the service account token directory to be used.
|
||||
|
|
|
|||
Loading…
Reference in a new issue