Skip to content

Commit

Permalink
Reduce the number of imageDigestExporter step to one per Task
Browse files Browse the repository at this point in the history
Currently, if a `Task` uses one or more image output we add a
`imageDigestExporter` for each step defined in the `Task`. This is not
required as only one step/container can do the work and handle
multiple images.

This change reduce to one the number of `imageDigestExporter` to one
step, after the last user-defined step.

Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester authored and tekton-robot committed Jul 26, 2019
1 parent c5769af commit dc91bdc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 39 deletions.
10 changes: 4 additions & 6 deletions pkg/reconciler/v1alpha1/taskrun/resources/image_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ func AddOutputImageDigestExporter(
return xerrors.Errorf("Failed to format image resource data for output image exporter: %w", err)
}

for _, s := range taskSpec.Steps {
augmentedSteps = append(augmentedSteps, s)
augmentedSteps = append(augmentedSteps, imageDigestExporterContainer(s.Name, imagesJSON))
}
augmentedSteps = append(augmentedSteps, taskSpec.Steps...)
augmentedSteps = append(augmentedSteps, imageDigestExporterContainer(imagesJSON))

taskSpec.Steps = augmentedSteps
}
Expand All @@ -97,9 +95,9 @@ func UpdateTaskRunStatusWithResourceResult(taskRun *v1alpha1.TaskRun, logContent
return nil
}

func imageDigestExporterContainer(stepName string, imagesJSON []byte) corev1.Container {
func imageDigestExporterContainer(imagesJSON []byte) corev1.Container {
return corev1.Container{
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("image-digest-exporter-" + stepName),
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("image-digest-exporter"),
Image: *imageDigestExporterImage,
Command: []string{"/ko-app/imagedigestexporter"},
Args: []string{
Expand Down
12 changes: 2 additions & 10 deletions pkg/reconciler/v1alpha1/taskrun/resources/image_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestAddOutputImageDigestExporter(t *testing.T) {
Name: "step1",
},
{
Name: "image-digest-exporter-step1-9l9zj",
Name: "image-digest-exporter-9l9zj",
Image: "override-with-imagedigest-exporter-image:latest",
Command: []string{"/ko-app/imagedigestexporter"},
Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir),
Expand Down Expand Up @@ -154,17 +154,9 @@ func TestAddOutputImageDigestExporter(t *testing.T) {
Name: "step1",
},
{
Name: "image-digest-exporter-step1-9l9zj",
Image: "override-with-imagedigest-exporter-image:latest",
Command: []string{"/ko-app/imagedigestexporter"},
Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir),
"-terminationMessagePath", "/builder/home/image-outputs/termination-log"},
TerminationMessagePath: TerminationMessagePath,
TerminationMessagePolicy: "FallbackToLogsOnError",
}, {
Name: "step2",
}, {
Name: "image-digest-exporter-step2-mz4c7",
Name: "image-digest-exporter-9l9zj",
Image: "override-with-imagedigest-exporter-image:latest",
Command: []string{"/ko-app/imagedigestexporter"},
Args: []string{"-images", fmt.Sprintf("[{\"name\":\"source-image-1\",\"type\":\"image\",\"url\":\"gcr.io/some-image-1\",\"digest\":\"\",\"OutputImageDir\":\"%s\"}]", currentDir),
Expand Down
28 changes: 5 additions & 23 deletions pkg/reconciler/v1alpha1/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ func TestReconcile(t *testing.T) {
},
}, toolsVolume, downward, workspaceVolume, homeVolume),
tb.PodRestartPolicy(corev1.RestartPolicyNever),
getCredentialsInitContainer("78c5n"),
getCredentialsInitContainer("mssqb"),
getPlaceToolsInitContainer(),
tb.PodContainer("step-git-source-git-resource-mssqb", "override-with-git:latest",
tb.PodContainer("step-git-source-git-resource-mz4c7", "override-with-git:latest",
tb.Command(entrypointLocation),
tb.Args("-wait_file", "/builder/downward/ready", "-post_file", "/builder/tools/0", "-wait_file_content", "-entrypoint", "/ko-app/git-init", "--",
"-url", "https://foo.git", "-revision", "master", "-path", "/workspace/workspace"),
Expand Down Expand Up @@ -501,27 +501,9 @@ func TestReconcile(t *testing.T) {
tb.EphemeralStorage("0"),
)),
),
tb.PodContainer("step-image-digest-exporter-mycontainer-9l9zj", "override-with-imagedigest-exporter-image:latest",
tb.Command("/builder/tools/entrypoint"),
tb.Args("-wait_file", "/builder/tools/1", "-post_file", "/builder/tools/2", "-entrypoint", "/ko-app/imagedigestexporter", "--",
"-images", "[{\"name\":\"image-resource\",\"type\":\"image\",\"url\":\"gcr.io/kristoff/sven\",\"digest\":\"\",\"OutputImageDir\":\"\"}]",
"-terminationMessagePath", "/builder/home/image-outputs/termination-log"),
tb.WorkingDir(workspaceDir),
tb.EnvVar("HOME", "/builder/home"),
tb.VolumeMount("tools", "/builder/tools"),
tb.VolumeMount("workspace", workspaceDir),
tb.VolumeMount("home", "/builder/home"),
tb.Resources(tb.Requests(
tb.CPU("0"),
tb.Memory("0"),
tb.EphemeralStorage("0"),
)),
tb.TerminationMessagePath("/builder/home/image-outputs/termination-log"),
tb.TerminationMessagePolicy(corev1.TerminationMessageFallbackToLogsOnError),
),
tb.PodContainer("step-myothercontainer", "myotherimage",
tb.Command(entrypointLocation),
tb.Args("-wait_file", "/builder/tools/2", "-post_file", "/builder/tools/3", "-entrypoint", "/mycmd", "--",
tb.Args("-wait_file", "/builder/tools/1", "-post_file", "/builder/tools/2", "-entrypoint", "/mycmd", "--",
"--my-other-arg=https://foo.git"),
tb.WorkingDir(workspaceDir),
tb.EnvVar("HOME", "/builder/home"),
Expand All @@ -534,9 +516,9 @@ func TestReconcile(t *testing.T) {
tb.EphemeralStorage("0"),
)),
),
tb.PodContainer("step-image-digest-exporter-myothercontainer-mz4c7", "override-with-imagedigest-exporter-image:latest",
tb.PodContainer("step-image-digest-exporter-9l9zj", "override-with-imagedigest-exporter-image:latest",
tb.Command(entrypointLocation),
tb.Args("-wait_file", "/builder/tools/3", "-post_file", "/builder/tools/4", "-entrypoint", "/ko-app/imagedigestexporter", "--",
tb.Args("-wait_file", "/builder/tools/2", "-post_file", "/builder/tools/3", "-entrypoint", "/ko-app/imagedigestexporter", "--",
"-images", "[{\"name\":\"image-resource\",\"type\":\"image\",\"url\":\"gcr.io/kristoff/sven\",\"digest\":\"\",\"OutputImageDir\":\"\"}]",
"-terminationMessagePath", "/builder/home/image-outputs/termination-log"),
tb.WorkingDir(workspaceDir),
Expand Down

0 comments on commit dc91bdc

Please sign in to comment.