Skip to content

Commit

Permalink
Adds support for img labels and anno. in buildrun create cmd
Browse files Browse the repository at this point in the history
This adds support to specify labels and annotation for
output image.
There are 2 flags added for the build create command

    output-image-label
    output-image-annotation

Signed-off-by: Shivam Mukhade <[email protected]>
  • Loading branch information
Shivam Mukhade committed Dec 13, 2021
1 parent a129b41 commit 642c6ee
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/shp/flags/buildrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func BuildRunSpecFromFlags(flags *pflag.FlagSet) *buildv1alpha1.BuildRunSpec {
Timeout: &metav1.Duration{},
Output: &buildv1alpha1.Image{
Credentials: &corev1.LocalObjectReference{},
Labels: map[string]string{},
Annotations: map[string]string{},
},
Env: []corev1.EnvVar{},
}
Expand All @@ -28,6 +30,8 @@ func BuildRunSpecFromFlags(flags *pflag.FlagSet) *buildv1alpha1.BuildRunSpec {
timeoutFlags(flags, spec.Timeout)
imageFlags(flags, "output", spec.Output)
envFlags(flags, &spec.Env)
imageLabelsFlags(flags, spec.Output.Labels)
imageAnnotationsFlags(flags, spec.Output.Annotations)

return spec
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/shp/flags/buildrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestBuildRunSpecFromFlags(t *testing.T) {
Output: &buildv1alpha1.Image{
Credentials: &corev1.LocalObjectReference{Name: "name"},
Image: str,
Labels: map[string]string{},
Annotations: map[string]string{},
},
}

Expand Down
1 change: 0 additions & 1 deletion pkg/shp/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ func imageLabelsFlags(flags *pflag.FlagSet, labels map[string]string) {
"",
"specify a set of key-value pairs that correspond to labels to set on the output image",
)

}

// imageLabelsFlags registers flags for output image annotations.
Expand Down
29 changes: 29 additions & 0 deletions test/e2e/output-image-labels-annotations.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,33 @@ teardown() {
# ensure that the label and annotation were inserted into the Build object
assert_output --partial "foo: bar"
assert_output --partial "created-by: shipwright"

# create a BuildRun with two environment variables
run shp buildrun create ${buildrun_name} --buildref-name=${build_name} --output-image=my-image --output-image-label=foo=bar123 --output-image-annotation=owned-by=shipwright
assert_success

# ensure that the build was successfully created
assert_output --partial "BuildRun created \"${buildrun_name}\" for Build \"${build_name}\""

# get the yaml for the BuildRun object
run kubectl get buildruns.shipwright.io/${buildrun_name} -o yaml
assert_success

# ensure that the label and annotation were inserted into the BuildRun object
assert_output --partial "foo: bar123"
assert_output --partial "owned-by: shipwright"

# get the taskrun that we created
run kubectl get taskruns.tekton.dev --selector=buildrun.shipwright.io/name=${buildrun_name} -o name
assert_success

run kubectl get ${output} -o yaml
assert_success

# ensure that the annotation was inserted into the TaskRun from the Build object which is not in BuildRun
assert_output --partial "created-by=shipwright"
# ensure that the labels and annotations where inserted into the TaskRun from the BuildRun Object
# and that the value from BuildRun override the ones defined in Build
assert_output --partial "owned-by=shipwright"
assert_output --partial "foo=bar123"
}

0 comments on commit 642c6ee

Please sign in to comment.