mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #84725 from liggitt/e2e-useragent
Set user agent for e2e consistently
This commit is contained in:
commit
e52df5bcc3
@ -159,14 +159,6 @@ func (f *Framework) BeforeEach() {
|
|||||||
ginkgo.By("Creating a kubernetes client")
|
ginkgo.By("Creating a kubernetes client")
|
||||||
config, err := LoadConfig()
|
config, err := LoadConfig()
|
||||||
ExpectNoError(err)
|
ExpectNoError(err)
|
||||||
testDesc := ginkgo.CurrentGinkgoTestDescription()
|
|
||||||
if len(testDesc.ComponentTexts) > 0 {
|
|
||||||
componentTexts := strings.Join(testDesc.ComponentTexts, " ")
|
|
||||||
config.UserAgent = fmt.Sprintf(
|
|
||||||
"%v -- %v",
|
|
||||||
rest.DefaultKubernetesUserAgent(),
|
|
||||||
componentTexts)
|
|
||||||
}
|
|
||||||
|
|
||||||
config.QPS = f.Options.ClientQPS
|
config.QPS = f.Options.ClientQPS
|
||||||
config.Burst = f.Options.ClientBurst
|
config.Burst = f.Options.ClientBurst
|
||||||
|
@ -62,6 +62,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/kubernetes/scheme"
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
|
"k8s.io/client-go/rest"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
scaleclient "k8s.io/client-go/scale"
|
scaleclient "k8s.io/client-go/scale"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
@ -841,8 +842,8 @@ func KubectlVersion() (*utilversion.Version, error) {
|
|||||||
return utilversion.ParseSemantic(matches[1])
|
return utilversion.ParseSemantic(matches[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestclientConfig returns a config holds the information needed to build connection to kubernetes clusters.
|
// restclientConfig returns a config holds the information needed to build connection to kubernetes clusters.
|
||||||
func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error) {
|
func restclientConfig(kubeContext string) (*clientcmdapi.Config, error) {
|
||||||
Logf(">>> kubeConfig: %s", TestContext.KubeConfig)
|
Logf(">>> kubeConfig: %s", TestContext.KubeConfig)
|
||||||
if TestContext.KubeConfig == "" {
|
if TestContext.KubeConfig == "" {
|
||||||
return nil, fmt.Errorf("KubeConfig must be specified to load client config")
|
return nil, fmt.Errorf("KubeConfig must be specified to load client config")
|
||||||
@ -861,13 +862,23 @@ func RestclientConfig(kubeContext string) (*clientcmdapi.Config, error) {
|
|||||||
// ClientConfigGetter is a func that returns getter to return a config.
|
// ClientConfigGetter is a func that returns getter to return a config.
|
||||||
type ClientConfigGetter func() (*restclient.Config, error)
|
type ClientConfigGetter func() (*restclient.Config, error)
|
||||||
|
|
||||||
// LoadConfig returns a config for a rest client.
|
// LoadConfig returns a config for a rest client with the UserAgent set to include the current test name.
|
||||||
func LoadConfig() (*restclient.Config, error) {
|
func LoadConfig() (config *restclient.Config, err error) {
|
||||||
|
defer func() {
|
||||||
|
if err == nil && config != nil {
|
||||||
|
testDesc := ginkgo.CurrentGinkgoTestDescription()
|
||||||
|
if len(testDesc.ComponentTexts) > 0 {
|
||||||
|
componentTexts := strings.Join(testDesc.ComponentTexts, " ")
|
||||||
|
config.UserAgent = fmt.Sprintf("%s -- %s", rest.DefaultKubernetesUserAgent(), componentTexts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if TestContext.NodeE2E {
|
if TestContext.NodeE2E {
|
||||||
// This is a node e2e test, apply the node e2e configuration
|
// This is a node e2e test, apply the node e2e configuration
|
||||||
return &restclient.Config{Host: TestContext.Host}, nil
|
return &restclient.Config{Host: TestContext.Host}, nil
|
||||||
}
|
}
|
||||||
c, err := RestclientConfig(TestContext.KubeContext)
|
c, err := restclientConfig(TestContext.KubeContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if TestContext.KubeConfig == "" {
|
if TestContext.KubeConfig == "" {
|
||||||
return restclient.InClusterConfig()
|
return restclient.InClusterConfig()
|
||||||
|
Loading…
Reference in New Issue
Block a user