Adding in customized user-agent
Signed-off-by: Justin Nauman <justin.r.nauman@gmail.com>pull/69/head
parent
5405067a2e
commit
d76ed7b49e
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -34,12 +34,14 @@ type Factory interface {
|
|||
type factory struct {
|
||||
flags *pflag.FlagSet
|
||||
kubeconfig string
|
||||
baseName string
|
||||
}
|
||||
|
||||
// NewFactory returns a Factory.
|
||||
func NewFactory() Factory {
|
||||
func NewFactory(baseName string) Factory {
|
||||
f := &factory{
|
||||
flags: pflag.NewFlagSet("", pflag.ContinueOnError),
|
||||
flags: pflag.NewFlagSet("", pflag.ContinueOnError),
|
||||
baseName: baseName,
|
||||
}
|
||||
f.flags.StringVar(&f.kubeconfig, "kubeconfig", "", "Path to the kubeconfig file to use to talk to the Kubernetes apiserver. If unset, try the environment variable KUBECONFIG, as well as in-cluster configuration")
|
||||
|
||||
|
@ -51,7 +53,7 @@ func (f *factory) BindFlags(flags *pflag.FlagSet) {
|
|||
}
|
||||
|
||||
func (f *factory) Client() (clientset.Interface, error) {
|
||||
clientConfig, err := Config(f.kubeconfig)
|
||||
clientConfig, err := Config(f.kubeconfig, f.baseName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -39,14 +39,14 @@ and operationally robust way to back up your application state and
|
|||
associated data.`,
|
||||
}
|
||||
|
||||
f := client.NewFactory()
|
||||
f := client.NewFactory(name)
|
||||
f.BindFlags(c.PersistentFlags())
|
||||
|
||||
c.AddCommand(
|
||||
backup.NewCommand(f),
|
||||
schedule.NewCommand(f),
|
||||
restore.NewCommand(f),
|
||||
server.NewCommand(),
|
||||
server.NewCommand(name),
|
||||
version.NewCommand(),
|
||||
)
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ import (
|
|||
"github.com/heptio/ark/pkg/util/kube"
|
||||
)
|
||||
|
||||
func NewCommand() *cobra.Command {
|
||||
func NewCommand(baseName string) *cobra.Command {
|
||||
var kubeconfig string
|
||||
|
||||
var command = &cobra.Command{
|
||||
|
@ -65,7 +65,7 @@ func NewCommand() *cobra.Command {
|
|||
Short: "Run the ark server",
|
||||
Long: "Run the ark server",
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
s, err := newServer(kubeconfig)
|
||||
s, err := newServer(kubeconfig, baseName+"-server")
|
||||
cmd.CheckError(err)
|
||||
|
||||
cmd.CheckError(s.run())
|
||||
|
@ -89,8 +89,8 @@ type server struct {
|
|||
cancelFunc context.CancelFunc
|
||||
}
|
||||
|
||||
func newServer(kubeconfig string) (*server, error) {
|
||||
clientConfig, err := client.Config(kubeconfig)
|
||||
func newServer(kubeconfig, baseName string) (*server, error) {
|
||||
clientConfig, err := client.Config(kubeconfig, baseName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue