fix(helm): report User-Agent to kubernetes calls

Close #7719

Signed-off-by: Dong Gang <dong.gang@daocloud.io>
pull/7732/head
Dong Gang 6 years ago
parent 16024dc19a
commit 430474db74

@ -19,8 +19,8 @@ package kube // import "helm.sh/helm/v3/pkg/kube"
import "k8s.io/cli-runtime/pkg/genericclioptions" import "k8s.io/cli-runtime/pkg/genericclioptions"
// GetConfig returns a Kubernetes client config. // GetConfig returns a Kubernetes client config.
func GetConfig(kubeconfig, context, namespace string) *genericclioptions.ConfigFlags { func GetConfig(kubeconfig, context, namespace string) *ConfigFlags {
cf := genericclioptions.NewConfigFlags(true) cf := &ConfigFlags{*genericclioptions.NewConfigFlags(true)}
cf.Namespace = &namespace cf.Namespace = &namespace
cf.Context = &context cf.Context = &context
cf.KubeConfig = &kubeconfig cf.KubeConfig = &kubeconfig

@ -0,0 +1,40 @@
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kube
import (
"helm.sh/helm/v3/internal/version"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/rest"
)
type ConfigFlags struct {
genericclioptions.ConfigFlags
}
// ToRESTConfig implements RESTClientGetter.
// Returns a REST client configuration based on a provided path
// to a .kubeconfig file, loading rules, and config flag overrides.
// Expects the AddFlags method to have been called.
func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
config, err := f.ToRawKubeConfigLoader().ClientConfig()
if err != nil {
return nil, err
}
config.UserAgent = version.GetUserAgent()
return config, err
}
Loading…
Cancel
Save