adjust client-go User-Agent

This commit is contained in:
Andy Xie 2018-06-25 17:02:24 +08:00
parent bdcb2eb490
commit e025e06707
2 changed files with 9 additions and 0 deletions

View File

@ -116,6 +116,7 @@ func createKubeClient(apiserver string, kubeconfig string) (clientset.Interface,
return nil, err return nil, err
} }
config.UserAgent = version.GetVersion().String()
config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json" config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
config.ContentType = "application/vnd.kubernetes.protobuf" config.ContentType = "application/vnd.kubernetes.protobuf"

View File

@ -15,6 +15,8 @@ package version
import ( import (
"fmt" "fmt"
"os"
"path/filepath"
"runtime" "runtime"
) )
@ -36,6 +38,12 @@ type Version struct {
Platform string Platform string
} }
func (v Version) String() string {
return fmt.Sprintf("%s/%s (%s/%s) kube-state-metrics/%s",
filepath.Base(os.Args[0]), v.Release,
runtime.GOOS, runtime.GOARCH, v.GitCommit)
}
// GetVersion returns kube-state-metrics version // GetVersion returns kube-state-metrics version
func GetVersion() Version { func GetVersion() Version {
return Version{ return Version{