Skip to content

Commit

Permalink
feat: log format option for main containers (#9468)
Browse files Browse the repository at this point in the history
* feat: log format option for main containers

adds --log-format and --loglevel flags to "argoexec emissary" for
consistent logging output.

related to: #8986 #9169 #7361

Signed-off-by: Thomas Bonfort <thomas.bonfort@airbus.com>

* update tests

Signed-off-by: Thomas Bonfort <thomas.bonfort@airbus.com>

* update tests

Signed-off-by: Thomas Bonfort <thomas.bonfort@airbus.com>

Signed-off-by: Thomas Bonfort <thomas.bonfort@airbus.com>
  • Loading branch information
tbonfort authored Sep 2, 2022
1 parent 1696fb2 commit 06d2957
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions workflow/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func newController(options ...interface{}) (context.CancelFunc, *WorkflowControl
S3Bucket: wfv1.S3Bucket{Endpoint: "my-endpoint", Bucket: "my-bucket"},
},
}),
cliExecutorLogFormat: "text",
kubeclientset: kube,
dynamicInterface: dynamicClient,
wfclientset: wfclientset,
Expand Down
4 changes: 3 additions & 1 deletion workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2818,7 +2818,9 @@ func TestResolveIOPathPlaceholders(t *testing.T) {
assert.NoError(t, err)
assert.True(t, len(pods.Items) > 0, "pod was not created successfully")

assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary", "--", "sh", "-c", "head -n 3 <\"/inputs/text/data\" | tee \"/outputs/text/data\" | wc -l > \"/outputs/actual-lines-count/data\""}, pods.Items[0].Spec.Containers[1].Command)
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary",
"--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.cliExecutorLogFormat,
"--", "sh", "-c", "head -n 3 <\"/inputs/text/data\" | tee \"/outputs/text/data\" | wc -l > \"/outputs/actual-lines-count/data\""}, pods.Items[0].Spec.Containers[1].Command)
}

var outputValuePlaceholders = `
Expand Down
4 changes: 3 additions & 1 deletion workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
c.Args = x.Cmd
}
}
c.Command = append([]string{common.VarRunArgoPath + "/argoexec", "emissary", "--"}, c.Command...)
c.Command = append([]string{common.VarRunArgoPath + "/argoexec", "emissary",
"--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.executorLogFormat(),
"--"}, c.Command...)
}
if c.Image == woc.controller.executorImage() {
// mount tmp dir to wait container
Expand Down
20 changes: 15 additions & 5 deletions workflow/controller/workflowpod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,21 +660,27 @@ func Test_createWorkflowPod_emissary(t *testing.T) {
woc := newWoc()
pod, err := woc.createWorkflowPod(context.Background(), "", []apiv1.Container{{Command: []string{"foo"}}}, &wfv1.Template{}, &createWorkflowPodOpts{})
assert.NoError(t, err)
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary", "--", "foo"}, pod.Spec.Containers[1].Command)
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary",
"--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.cliExecutorLogFormat,
"--", "foo"}, pod.Spec.Containers[1].Command)
})
t.Run("NoCommandWithImageIndex", func(t *testing.T) {
woc := newWoc()
pod, err := woc.createWorkflowPod(context.Background(), "", []apiv1.Container{{Image: "my-image"}}, &wfv1.Template{}, &createWorkflowPodOpts{})
if assert.NoError(t, err) {
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary", "--", "my-entrypoint"}, pod.Spec.Containers[1].Command)
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary",
"--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.cliExecutorLogFormat,
"--", "my-entrypoint"}, pod.Spec.Containers[1].Command)
assert.Equal(t, []string{"my-cmd"}, pod.Spec.Containers[1].Args)
}
})
t.Run("NoCommandWithArgsWithImageIndex", func(t *testing.T) {
woc := newWoc()
pod, err := woc.createWorkflowPod(context.Background(), "", []apiv1.Container{{Image: "my-image", Args: []string{"foo"}}}, &wfv1.Template{}, &createWorkflowPodOpts{})
if assert.NoError(t, err) {
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary", "--", "my-entrypoint"}, pod.Spec.Containers[1].Command)
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary",
"--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.cliExecutorLogFormat,
"--", "my-entrypoint"}, pod.Spec.Containers[1].Command)
assert.Equal(t, []string{"foo"}, pod.Spec.Containers[1].Args)
}
})
Expand All @@ -689,7 +695,9 @@ func Test_createWorkflowPod_emissary(t *testing.T) {
assert.NoError(t, err)
pod, err := woc.createWorkflowPod(context.Background(), "", []apiv1.Container{{Command: []string{"foo"}}}, &wfv1.Template{PodSpecPatch: string(podSpecPatch)}, &createWorkflowPodOpts{})
assert.NoError(t, err)
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary", "--", "bar"}, pod.Spec.Containers[1].Command)
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary",
"--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.cliExecutorLogFormat,
"--", "bar"}, pod.Spec.Containers[1].Command)
})
}

Expand Down Expand Up @@ -745,7 +753,9 @@ func TestVolumeAndVolumeMounts(t *testing.T) {
assert.Equal(t, "var-run-argo", wait.VolumeMounts[2].Name)
}
main := containers[1]
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary", "--", "cowsay"}, main.Command)
assert.Equal(t, []string{"/var/run/argo/argoexec", "emissary",
"--loglevel", getExecutorLogLevel(), "--log-format", woc.controller.cliExecutorLogFormat,
"--", "cowsay"}, main.Command)
if assert.Len(t, main.VolumeMounts, 2) {
assert.Equal(t, "volume-name", main.VolumeMounts[0].Name)
assert.Equal(t, "var-run-argo", main.VolumeMounts[1].Name)
Expand Down

0 comments on commit 06d2957

Please sign in to comment.