@@ -62,6 +62,7 @@ import (
62
62
"k8s.io/apimachinery/pkg/watch"
63
63
clientset "k8s.io/client-go/kubernetes"
64
64
"k8s.io/client-go/kubernetes/scheme"
65
+ "k8s.io/client-go/rest"
65
66
restclient "k8s.io/client-go/rest"
66
67
scaleclient "k8s.io/client-go/scale"
67
68
"k8s.io/client-go/tools/clientcmd"
@@ -841,8 +842,8 @@ func KubectlVersion() (*utilversion.Version, error) {
841
842
return utilversion .ParseSemantic (matches [1 ])
842
843
}
843
844
844
- // RestclientConfig returns a config holds the information needed to build connection to kubernetes clusters.
845
- func RestclientConfig (kubeContext string ) (* clientcmdapi.Config , error ) {
845
+ // restclientConfig returns a config holds the information needed to build connection to kubernetes clusters.
846
+ func restclientConfig (kubeContext string ) (* clientcmdapi.Config , error ) {
846
847
Logf (">>> kubeConfig: %s" , TestContext .KubeConfig )
847
848
if TestContext .KubeConfig == "" {
848
849
return nil , fmt .Errorf ("KubeConfig must be specified to load client config" )
@@ -861,13 +862,23 @@ func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error) {
861
862
// ClientConfigGetter is a func that returns getter to return a config.
862
863
type ClientConfigGetter func () (* restclient.Config , error )
863
864
864
- // LoadConfig returns a config for a rest client.
865
- func LoadConfig () (* restclient.Config , error ) {
865
+ // LoadConfig returns a config for a rest client with the UserAgent set to include the current test name.
866
+ func LoadConfig () (config * restclient.Config , err error ) {
867
+ defer func () {
868
+ if err == nil && config != nil {
869
+ testDesc := ginkgo .CurrentGinkgoTestDescription ()
870
+ if len (testDesc .ComponentTexts ) > 0 {
871
+ componentTexts := strings .Join (testDesc .ComponentTexts , " " )
872
+ config .UserAgent = fmt .Sprintf ("%s -- %s" , rest .DefaultKubernetesUserAgent (), componentTexts )
873
+ }
874
+ }
875
+ }()
876
+
866
877
if TestContext .NodeE2E {
867
878
// This is a node e2e test, apply the node e2e configuration
868
879
return & restclient.Config {Host : TestContext .Host }, nil
869
880
}
870
- c , err := RestclientConfig (TestContext .KubeContext )
881
+ c , err := restclientConfig (TestContext .KubeContext )
871
882
if err != nil {
872
883
if TestContext .KubeConfig == "" {
873
884
return restclient .InClusterConfig ()
0 commit comments