Skip to content

Commit 5dc6fc0

Browse files
committed
add possibility to setup a custom logger for kubectl configuration
This enables users to not log messages like: "Configuring Kubernetes client using config file" Fix #1383 Signed-off-by: Charly Molter <[email protected]>
1 parent d54ee08 commit 5dc6fc0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

modules/k8s/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ func GetKubernetesClientFromOptionsE(t testing.TestingT, options *KubectlOptions
3232
if err != nil {
3333
return nil, err
3434
}
35-
options.Logger.Logf(t, "Configuring Kubernetes client to use the in-cluster serviceaccount token")
35+
options.ConfigLogger.Logf(t, "Configuring Kubernetes client to use the in-cluster serviceaccount token")
3636
} else if options.RestConfig != nil {
3737
config = options.RestConfig
38-
options.Logger.Logf(t, "Configuring Kubernetes client to use provided rest config object set with API server address: %s", config.Host)
38+
options.ConfigLogger.Logf(t, "Configuring Kubernetes client to use provided rest config object set with API server address: %s", config.Host)
3939
} else {
4040
kubeConfigPath, err := options.GetConfigPath(t)
4141
if err != nil {
4242
return nil, err
4343
}
44-
options.Logger.Logf(t, "Configuring Kubernetes client using config file %s with context %s", kubeConfigPath, options.ContextName)
44+
options.ConfigLogger.Logf(t, "Configuring Kubernetes client using config file %s with context %s", kubeConfigPath, options.ContextName)
4545
// Load API config (instead of more low level ClientConfig)
4646
config, err = LoadApiClientConfigE(kubeConfigPath, options.ContextName)
4747
if err != nil {
48-
options.Logger.Logf(t, "Error loading api client config, falling back to in-cluster authentication via serviceaccount token: %s", err)
48+
options.ConfigLogger.Logf(t, "Error loading api client config, falling back to in-cluster authentication via serviceaccount token: %s", err)
4949
config, err = rest.InClusterConfig()
5050
if err != nil {
5151
return nil, err
5252
}
53-
options.Logger.Logf(t, "Configuring Kubernetes client to use the in-cluster serviceaccount token")
53+
options.ConfigLogger.Logf(t, "Configuring Kubernetes client to use the in-cluster serviceaccount token")
5454
}
5555
}
5656

modules/k8s/kubectl_options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type KubectlOptions struct {
1515
InClusterAuth bool
1616
RestConfig *rest.Config
1717
Logger *logger.Logger
18+
// ConfigLogger is useful to set a different logger when configuring kubectl with a config. This can significantly reduce verbosity of tests
19+
ConfigLogger *logger.Logger
1820
}
1921

2022
// NewKubectlOptions will return a pointer to new instance of KubectlOptions with the configured options

0 commit comments

Comments
 (0)