From a4b7dd906d25527abb200289d02c4a66d01fa6b1 Mon Sep 17 00:00:00 2001 From: Tom Kennedy Date: Fri, 28 Oct 2022 12:18:09 -0400 Subject: [PATCH 1/3] Handle nil build spec when reading creation time --- pkg/apis/build/v1alpha2/image_builds.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/apis/build/v1alpha2/image_builds.go b/pkg/apis/build/v1alpha2/image_builds.go index e24979009..786bf06f6 100644 --- a/pkg/apis/build/v1alpha2/image_builds.go +++ b/pkg/apis/build/v1alpha2/image_builds.go @@ -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(), }, } } @@ -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 "" +} From 54fbca0a9c73547a85173b6ac0f15aab822ffda0 Mon Sep 17 00:00:00 2001 From: Tom Kennedy Date: Fri, 28 Oct 2022 12:33:22 -0400 Subject: [PATCH 2/3] Add tests for image build creation time --- pkg/apis/build/v1alpha2/image_builds_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/apis/build/v1alpha2/image_builds_test.go b/pkg/apis/build/v1alpha2/image_builds_test.go index ac6f810f7..3ff1e4c8a 100644 --- a/pkg/apis/build/v1alpha2/image_builds_test.go +++ b/pkg/apis/build/v1alpha2/image_builds_test.go @@ -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() { + 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, "") + }) + }) + }) } From 5564c362ff02edf3c221a4bcdfb7b1915451f188 Mon Sep 17 00:00:00 2001 From: Tom Kennedy Date: Mon, 31 Oct 2022 14:34:27 -0400 Subject: [PATCH 3/3] Add docs for creation time --- docs/image.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/image.md b/docs/image.md index cec6aa5b1..ceb695eca 100644 --- a/docs/image.md +++ b/docs/image.md @@ -121,7 +121,7 @@ The `source` field is a composition of a source code location and a `subpath`. I ### 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: @@ -142,6 +142,7 @@ build: nodeSelector: disktype: ssd buildTimeout: 1600 + creationTime: "now" affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: