mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-06 13:26:26 +00:00
Adding in customized user-agent
Signed-off-by: Justin Nauman <justin.r.nauman@gmail.com>
This commit is contained in:
@@ -17,18 +17,37 @@ limitations under the License.
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
||||
"github.com/heptio/ark/pkg/buildinfo"
|
||||
)
|
||||
|
||||
// Config returns a *rest.Config, using either the kubeconfig (if specified) or an in-cluster
|
||||
// configuration.
|
||||
func Config(kubeconfig string) (*rest.Config, error) {
|
||||
func Config(kubeconfig, baseName string) (*rest.Config, error) {
|
||||
loader := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
loader.ExplicitPath = kubeconfig
|
||||
clientConfig, err := clientcmd.BuildConfigFromKubeconfigGetter("", loader.Load)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clientConfig.UserAgent = buildUserAgent(
|
||||
baseName,
|
||||
buildinfo.Version,
|
||||
runtime.GOOS,
|
||||
runtime.GOARCH,
|
||||
buildinfo.GitSHA)
|
||||
|
||||
return clientConfig, nil
|
||||
}
|
||||
|
||||
// buildUserAgent builds a User-Agent string from given args.
|
||||
func buildUserAgent(command, version, os, arch, commit string) string {
|
||||
return fmt.Sprintf(
|
||||
"%s/%s (%s/%s) %s", command, version, os, arch, commit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user