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

Handle nil build spec when reading creation time #1053

Merged
merged 3 commits into from
Oct 31, 2022
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
3 changes: 2 additions & 1 deletion docs/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ The `source` field is a composition of a source code location and a `subpath`. I

### <a id='build-config'></a>Build Configuration

The `build` field on the `image` resource can be used to configure env variables required during the build process, to configure resource limits on `CPU` and `memory`, and to configure pod tolerations, node selector, build timout (specified in seconds), and affinity.
The `build` field on the `image` resource can be used to configure env variables required during the build process, to configure resource limits on `CPU` and `memory`, and to configure pod tolerations, node selector, build timout (specified in seconds), and affinity. To configure "Creation Time" of the built app image, pass in the "unix EPOCH timestamp" as a string or use "now" to use the current time.

```yaml
build:
Expand All @@ -142,6 +142,7 @@ build:
nodeSelector:
disktype: ssd
buildTimeout: 1600
creationTime: "now"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
Expand Down
10 changes: 9 additions & 1 deletion pkg/apis/build/v1alpha2/image_builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (im *Image) Build(sourceResolver *SourceResolver, builder BuilderResource,
SchedulerName: im.SchedulerName(),
PriorityClassName: priorityClass,
ActiveDeadlineSeconds: im.BuildTimeout(),
CreationTime: im.Spec.Build.CreationTime,
CreationTime: im.Spec.creationTime(),
},
}
}
Expand Down Expand Up @@ -295,3 +295,11 @@ func combine(map1, map2 map[string]string) map[string]string {
func (im *Image) disableAdditionalImageNames() bool {
return im.Spec.ImageTaggingStrategy == corev1alpha1.None
}

func (is *ImageSpec) creationTime() string {
if buildSpec := is.Build; buildSpec != nil {
return buildSpec.CreationTime
}

return ""
}
18 changes: 18 additions & 0 deletions pkg/apis/build/v1alpha2/image_builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) {
assert.Equal(t, image.Spec.Notary, build.Spec.Notary)
assert.Equal(t, image.Spec.Cosign, build.Spec.Cosign)
})

it("sets the creation time when present", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh snap assumed we at least had this one

image.Spec.Build = &ImageBuild{
CreationTime: "now",
}

build := image.Build(sourceResolver, builder, latestBuild, "", "", 1, "")
assert.Equal(t, "now", build.Spec.CreationTime)
})

it("handles a nil build spec", func() {
image.Spec.Build = nil

assert.NotPanics(t, func() {
image.Build(sourceResolver, builder, latestBuild, "", "", 1, "")
})
})

})
}

Expand Down