From d55c463965416f5c9db2e1e19f765e60a81c5b90 Mon Sep 17 00:00:00 2001 From: Aatman Date: Wed, 20 Jul 2022 23:11:10 +0530 Subject: [PATCH] feat: log format option for wait and init containers. Fixes #8986 (#9169) * feat: log format option for wait and init containers. Fixes #8986 (#1) related to: #7361 fixes #8986 Signed-off-by: Hunter-Thompson * fix: use log-format arg instead of creating executor-log-format Signed-off-by: Hunter-Thompson Signed-off-by: Reddy --- cmd/workflow-controller/main.go | 2 +- workflow/controller/config.go | 4 ++++ workflow/controller/controller.go | 13 ++++++++++--- workflow/controller/workflowpod.go | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cmd/workflow-controller/main.go b/cmd/workflow-controller/main.go index 88c6c1cec1dc..9b8a3964c53a 100644 --- a/cmd/workflow-controller/main.go +++ b/cmd/workflow-controller/main.go @@ -110,7 +110,7 @@ func NewRootCommand() *cobra.Command { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - wfController, err := controller.NewWorkflowController(ctx, config, kubeclientset, wfclientset, namespace, managedNamespace, executorImage, executorImagePullPolicy, containerRuntimeExecutor, configMap, executorPlugins) + wfController, err := controller.NewWorkflowController(ctx, config, kubeclientset, wfclientset, namespace, managedNamespace, executorImage, executorImagePullPolicy, logFormat, containerRuntimeExecutor, configMap, executorPlugins) errors.CheckError(err) leaderElectionOff := os.Getenv("LEADER_ELECTION_DISABLE") diff --git a/workflow/controller/config.go b/workflow/controller/config.go index 698995197fe5..51494e302488 100644 --- a/workflow/controller/config.go +++ b/workflow/controller/config.go @@ -96,6 +96,10 @@ func (wfc *WorkflowController) executorImage() string { return fmt.Sprintf("quay.io/argoproj/argoexec:" + argo.ImageTag()) } +func (wfc *WorkflowController) executorLogFormat() string { + return wfc.cliExecutorLogFormat +} + // executorImagePullPolicy returns the imagePullPolicy to use for the workflow executor func (wfc *WorkflowController) executorImagePullPolicy() apiv1.PullPolicy { if wfc.cliExecutorImagePullPolicy != "" { diff --git a/workflow/controller/controller.go b/workflow/controller/controller.go index df063d6c400b..317c4129375a 100644 --- a/workflow/controller/controller.go +++ b/workflow/controller/controller.go @@ -86,6 +86,10 @@ type WorkflowController struct { cliExecutorImagePullPolicy string containerRuntimeExecutor string + // cliExecutorLogFormat is the format in which argoexec will log + // possible options are json/text + cliExecutorLogFormat string + // restConfig is used by controller to send a SIGUSR1 to the wait sidecar using remotecommand.NewSPDYExecutor(). restConfig *rest.Config kubeclientset kubernetes.Interface @@ -143,7 +147,7 @@ func init() { } // NewWorkflowController instantiates a new WorkflowController -func NewWorkflowController(ctx context.Context, restConfig *rest.Config, kubeclientset kubernetes.Interface, wfclientset wfclientset.Interface, namespace, managedNamespace, executorImage, executorImagePullPolicy, containerRuntimeExecutor, configMap string, executorPlugins bool) (*WorkflowController, error) { +func NewWorkflowController(ctx context.Context, restConfig *rest.Config, kubeclientset kubernetes.Interface, wfclientset wfclientset.Interface, namespace, managedNamespace, executorImage, executorImagePullPolicy, executorLogFormat, containerRuntimeExecutor, configMap string, executorPlugins bool) (*WorkflowController, error) { dynamicInterface, err := dynamic.NewForConfig(restConfig) if err != nil { return nil, err @@ -158,6 +162,7 @@ func NewWorkflowController(ctx context.Context, restConfig *rest.Config, kubecli managedNamespace: managedNamespace, cliExecutorImage: executorImage, cliExecutorImagePullPolicy: executorImagePullPolicy, + cliExecutorLogFormat: executorLogFormat, containerRuntimeExecutor: containerRuntimeExecutor, configController: config.NewController(namespace, configMap, kubeclientset), workflowKeyLock: syncpkg.NewKeyLock(), @@ -924,8 +929,10 @@ func (wfc *WorkflowController) archiveWorkflowAux(ctx context.Context, obj inter return nil } -var incompleteReq, _ = labels.NewRequirement(common.LabelKeyCompleted, selection.Equals, []string{"false"}) -var workflowReq, _ = labels.NewRequirement(common.LabelKeyWorkflow, selection.Exists, nil) +var ( + incompleteReq, _ = labels.NewRequirement(common.LabelKeyCompleted, selection.Equals, []string{"false"}) + workflowReq, _ = labels.NewRequirement(common.LabelKeyWorkflow, selection.Exists, nil) +) func (wfc *WorkflowController) instanceIDReq() labels.Requirement { return util.InstanceIDRequirement(wfc.Config.InstanceID) diff --git a/workflow/controller/workflowpod.go b/workflow/controller/workflowpod.go index ac8155970a91..fc82ecdde596 100644 --- a/workflow/controller/workflowpod.go +++ b/workflow/controller/workflowpod.go @@ -506,13 +506,13 @@ func substitutePodParams(pod *apiv1.Pod, globalParams common.Parameters, tmpl *w func (woc *wfOperationCtx) newInitContainer(tmpl *wfv1.Template) apiv1.Container { ctr := woc.newExecContainer(common.InitContainerName, tmpl) - ctr.Command = []string{"argoexec", "init", "--loglevel", getExecutorLogLevel()} + ctr.Command = []string{"argoexec", "init", "--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.executorLogFormat()} return *ctr } func (woc *wfOperationCtx) newWaitContainer(tmpl *wfv1.Template) *apiv1.Container { ctr := woc.newExecContainer(common.WaitContainerName, tmpl) - ctr.Command = []string{"argoexec", "wait", "--loglevel", getExecutorLogLevel()} + ctr.Command = []string{"argoexec", "wait", "--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.executorLogFormat()} return ctr }