From 19a34b1fa5c99d9bdfc51b73630c0605a198b8c1 Mon Sep 17 00:00:00 2001 From: Yuan Tang Date: Wed, 10 Feb 2021 14:40:37 -0500 Subject: [PATCH] feat(executor): Add user agent to workflow executor (#5014) Signed-off-by: terrytangyuan --- cmd/argoexec/commands/root.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/argoexec/commands/root.go b/cmd/argoexec/commands/root.go index 207458bb088f..d3e98715f4ef 100644 --- a/cmd/argoexec/commands/root.go +++ b/cmd/argoexec/commands/root.go @@ -2,6 +2,7 @@ package commands import ( "encoding/json" + "fmt" "os" "github.com/argoproj/pkg/cli" @@ -9,6 +10,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "k8s.io/client-go/kubernetes" + restclient "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "github.com/argoproj/argo-workflows/v3" @@ -71,8 +73,11 @@ func NewRootCommand() *cobra.Command { } func initExecutor() *executor.WorkflowExecutor { - log.WithField("version", argo.GetVersion().Version).Info("Starting Workflow Executor") + version := argo.GetVersion() + log.WithField("version", version).Info("Starting Workflow Executor") config, err := clientConfig.ClientConfig() + executorType := os.Getenv(common.EnvVarContainerRuntimeExecutor) + config = restclient.AddUserAgent(config, fmt.Sprintf("argo-workflows/%s executor/%s", version.Version, executorType)) checkErr(err) logs.AddK8SLogTransportWrapper(config) // lets log all request as we should typically do < 5 per pod, so this is will show up problems @@ -92,7 +97,7 @@ func initExecutor() *executor.WorkflowExecutor { checkErr(err) var cre executor.ContainerRuntimeExecutor - switch os.Getenv(common.EnvVarContainerRuntimeExecutor) { + switch executorType { case common.ContainerRuntimeExecutorK8sAPI: cre, err = k8sapi.NewK8sAPIExecutor(clientset, config, podName, namespace) case common.ContainerRuntimeExecutorKubelet: @@ -106,8 +111,7 @@ func initExecutor() *executor.WorkflowExecutor { wfExecutor := executor.NewExecutor(clientset, podName, namespace, podAnnotationsPath, cre, *tmpl) yamlBytes, _ := json.Marshal(&wfExecutor.Template) - vers := argo.GetVersion() - log.Infof("Executor (version: %s, build_date: %s) initialized (pod: %s/%s) with template:\n%s", vers.Version, vers.BuildDate, namespace, podName, string(yamlBytes)) + log.Infof("Executor (version: %s, build_date: %s) initialized (pod: %s/%s) with template:\n%s", version.Version, version.BuildDate, namespace, podName, string(yamlBytes)) return &wfExecutor }