Adding in customized user-agent

Signed-off-by: Justin Nauman <justin.r.nauman@gmail.com>
This commit is contained in:
Justin Nauman
2017-09-06 23:10:31 -05:00
parent 5405067a2e
commit d76ed7b49e
4 changed files with 31 additions and 10 deletions

View File

@@ -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)
}