Skip to content

Commit d2dc0e5

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 <charly.molter@konghq.com>
1 parent 28c0f43 commit d2dc0e5

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

modules/k8s/client.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
// See: https://github.com/kubernetes/client-go/issues/242
99
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
1010

11-
"github.com/gruntwork-io/terratest/modules/logger"
1211
"github.com/gruntwork-io/terratest/modules/testing"
1312
)
1413

@@ -33,25 +32,25 @@ func GetKubernetesClientFromOptionsE(t testing.TestingT, options *KubectlOptions
3332
if err != nil {
3433
return nil, err
3534
}
36-
logger.Log(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")
3736
} else if options.RestConfig != nil {
3837
config = options.RestConfig
39-
logger.Log(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)
4039
} else {
4140
kubeConfigPath, err := options.GetConfigPath(t)
4241
if err != nil {
4342
return nil, err
4443
}
45-
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)
4645
// Load API config (instead of more low level ClientConfig)
4746
config, err = LoadApiClientConfigE(kubeConfigPath, options.ContextName)
4847
if err != nil {
49-
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)
5049
config, err = rest.InClusterConfig()
5150
if err != nil {
5251
return nil, err
5352
}
54-
logger.Log(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")
5554
}
5655
}
5756

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)