@@ -64,6 +64,7 @@ import (
64
64
"k8s.io/client-go/dynamic"
65
65
clientset "k8s.io/client-go/kubernetes"
66
66
"k8s.io/client-go/kubernetes/scheme"
67
+ "k8s.io/client-go/rest"
67
68
restclient "k8s.io/client-go/rest"
68
69
scaleclient "k8s.io/client-go/scale"
69
70
"k8s.io/client-go/tools/clientcmd"
@@ -881,8 +882,8 @@ func KubectlVersion() (*utilversion.Version, error) {
881
882
return utilversion .ParseSemantic (matches [1 ])
882
883
}
883
884
884
- // RestclientConfig returns a config holds the information needed to build connection to kubernetes clusters.
885
- func RestclientConfig (kubeContext string ) (* clientcmdapi.Config , error ) {
885
+ // restclientConfig returns a config holds the information needed to build connection to kubernetes clusters.
886
+ func restclientConfig (kubeContext string ) (* clientcmdapi.Config , error ) {
886
887
Logf (">>> kubeConfig: %s" , TestContext .KubeConfig )
887
888
if TestContext .KubeConfig == "" {
888
889
return nil , fmt .Errorf ("KubeConfig must be specified to load client config" )
@@ -901,13 +902,23 @@ func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error) {
901
902
// ClientConfigGetter is a func that returns getter to return a config.
902
903
type ClientConfigGetter func () (* restclient.Config , error )
903
904
904
- // LoadConfig returns a config for a rest client.
905
- func LoadConfig () (* restclient.Config , error ) {
905
+ // LoadConfig returns a config for a rest client with the UserAgent set to include the current test name.
906
+ func LoadConfig () (config * restclient.Config , err error ) {
907
+ defer func () {
908
+ if err == nil && config != nil {
909
+ testDesc := ginkgo .CurrentGinkgoTestDescription ()
910
+ if len (testDesc .ComponentTexts ) > 0 {
911
+ componentTexts := strings .Join (testDesc .ComponentTexts , " " )
912
+ config .UserAgent = fmt .Sprintf ("%s -- %s" , rest .DefaultKubernetesUserAgent (), componentTexts )
913
+ }
914
+ }
915
+ }()
916
+
906
917
if TestContext .NodeE2E {
907
918
// This is a node e2e test, apply the node e2e configuration
908
919
return & restclient.Config {Host : TestContext .Host }, nil
909
920
}
910
- c , err := RestclientConfig (TestContext .KubeContext )
921
+ c , err := restclientConfig (TestContext .KubeContext )
911
922
if err != nil {
912
923
if TestContext .KubeConfig == "" {
913
924
return restclient .InClusterConfig ()
0 commit comments