Skip to content

Commit

Permalink
Passed StepOutputConfig to entrypoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
chhsia0 committed Nov 6, 2020
1 parent 8d22815 commit 8bd1736
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/pod/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,16 @@ func orderContainers(entrypointImage string, commonExtraEntrypointArgs []string,
}
argsForEntrypoint = append(argsForEntrypoint, commonExtraEntrypointArgs...)
if taskSpec != nil {
if taskSpec.Steps != nil && len(taskSpec.Steps) >= i+1 && taskSpec.Steps[i].Timeout != nil {
argsForEntrypoint = append(argsForEntrypoint, "-timeout", taskSpec.Steps[i].Timeout.Duration.String())
if taskSpec.Steps != nil && len(taskSpec.Steps) >= i+1 {
if taskSpec.Steps[i].Timeout != nil {
argsForEntrypoint = append(argsForEntrypoint, "-timeout", taskSpec.Steps[i].Timeout.Duration.String())
}
if taskSpec.Steps[i].StdoutConfig != nil {
argsForEntrypoint = append(argsForEntrypoint, "-stdout_path", taskSpec.Steps[i].StdoutConfig.Path)
}
if taskSpec.Steps[i].StderrConfig != nil {
argsForEntrypoint = append(argsForEntrypoint, "-stderr_path", taskSpec.Steps[i].StderrConfig.Path)
}
}
argsForEntrypoint = append(argsForEntrypoint, resultArgument(steps, taskSpec.Results)...)
}
Expand Down
87 changes: 87 additions & 0 deletions pkg/pod/entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,93 @@ func TestEntryPointSingleResultsSingleStep(t *testing.T) {
t.Errorf("Diff %s", diff.PrintWantGot(d))
}
}

func TestEntryPointStepOutputConfigs(t *testing.T) {
taskSpec := v1beta1.TaskSpec{
Steps: []v1beta1.Step{{
StdoutConfig: &v1beta1.StepOutputConfig{
Path: "step-1-out",
},
}, {
StderrConfig: &v1beta1.StepOutputConfig{
Path: "step-2-err",
},
}, {
StdoutConfig: &v1beta1.StepOutputConfig{
Path: "step-3-out",
},
StderrConfig: &v1beta1.StepOutputConfig{
Path: "step-3-err",
},
}},
}

steps := []corev1.Container{{
Image: "step-1",
Command: []string{"cmd"},
Args: []string{"arg1", "arg2"},
}, {
Image: "step-2",
Command: []string{"cmd1", "cmd2", "cmd3"}, // multiple cmd elements
Args: []string{"arg1", "arg2"},
VolumeMounts: []corev1.VolumeMount{volumeMount}, // pre-existing volumeMount
}, {
Image: "step-3",
Command: []string{"cmd"},
Args: []string{"arg1", "arg2"},
}}
want := []corev1.Container{{
Image: "step-1",
Command: []string{entrypointBinary},
Args: []string{
"-wait_file", "/tekton/downward/ready",
"-wait_file_content",
"-post_file", "/tekton/tools/0",
"-termination_path", "/tekton/termination",
"-stdout_path", "step-1-out",
"-entrypoint", "cmd", "--",
"arg1", "arg2",
},
VolumeMounts: []corev1.VolumeMount{toolsMount, downwardMount},
TerminationMessagePath: "/tekton/termination",
}, {
Image: "step-2",
Command: []string{entrypointBinary},
Args: []string{
"-wait_file", "/tekton/tools/0",
"-post_file", "/tekton/tools/1",
"-termination_path", "/tekton/termination",
"-stderr_path", "step-2-err",
"-entrypoint", "cmd1", "--",
"cmd2", "cmd3",
"arg1", "arg2",
},
VolumeMounts: []corev1.VolumeMount{volumeMount, toolsMount},
TerminationMessagePath: "/tekton/termination",
}, {
Image: "step-3",
Command: []string{entrypointBinary},
Args: []string{
"-wait_file", "/tekton/tools/1",
"-post_file", "/tekton/tools/2",
"-termination_path", "/tekton/termination",
"-stdout_path", "step-3-out",
"-stderr_path", "step-3-err",
"-entrypoint", "cmd", "--",
"arg1", "arg2",
},
VolumeMounts: []corev1.VolumeMount{toolsMount},
TerminationMessagePath: "/tekton/termination",
}}
_, got, err := orderContainers(images.EntrypointImage, []string{}, steps, &taskSpec)
if err != nil {
t.Fatalf("orderContainers: %v", err)
}
if d := cmp.Diff(want, got); d != "" {
t.Errorf("Diff %s", diff.PrintWantGot(d))
}
}

func TestUpdateReady(t *testing.T) {
for _, c := range []struct {
desc string
Expand Down

0 comments on commit 8bd1736

Please sign in to comment.