Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the number of imageDigestExporter step to one per Task #1126

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point we probably don't even need augmentedSteps ? could use taskSpec.Steps directly


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