diff --git a/docs/build.md b/docs/build.md index 7c960a963..cb65d06e8 100644 --- a/docs/build.md +++ b/docs/build.md @@ -29,6 +29,7 @@ spec: git: url: https://github.com/buildpack/sample-java-app.git revision: main + activeDeadlineSeconds: 1800 env: - name: "JAVA_BP_ENV" value: "value" @@ -62,6 +63,7 @@ spec: - `builder.image`: This is the tag to the [Cloud Native Buildpacks builder image](https://buildpacks.io/docs/using-pack/working-with-builders/) to use in the build. Unlike on the Image resource, this is an image not a reference to a Builder resource. - `builder.imagePullSecrets`: An optional list of pull secrets if the builder is in a private registry. [To create this secret please reference this link](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#registry-secret-existing-credentials) - `source`: The source location that will be the input to the build. See the [Source Configuration](#source-config) section below. +- `activeDeadlineSeconds`: Optional configurable max active time that the pod can run for - `cache`: Caching configuration, two variants are available: - `volume.persistentVolumeClaimName`: Optional name of a persistent volume claim used for a build cache across builds. - `registry.tag`: Optional name of a tag used for a build cache across builds. diff --git a/docs/image.md b/docs/image.md index 896e7dc16..f25ce570b 100644 --- a/docs/image.md +++ b/docs/image.md @@ -120,7 +120,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, 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. ```yaml build: @@ -140,6 +140,7 @@ build: effect: "NoSchedule" nodeSelector: disktype: ssd + buildTimeout: 1600 affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: diff --git a/pkg/apis/build/v1alpha2/build_pod.go b/pkg/apis/build/v1alpha2/build_pod.go index 62e2c8aa2..89f5ed93e 100644 --- a/pkg/apis/build/v1alpha2/build_pod.go +++ b/pkg/apis/build/v1alpha2/build_pod.go @@ -355,8 +355,9 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor }, Spec: corev1.PodSpec{ // If the build fails, don't restart it. - RestartPolicy: corev1.RestartPolicyNever, - PriorityClassName: b.PriorityClassName(), + RestartPolicy: corev1.RestartPolicyNever, + ActiveDeadlineSeconds: b.Spec.ActiveDeadlineSeconds, + PriorityClassName: b.PriorityClassName(), Containers: steps(func(step func(corev1.Container, ...stepModifier)) { step( corev1.Container{ @@ -425,7 +426,7 @@ func (b *Build) BuildPod(images BuildPodImages, buildContext BuildContext) (*cor Value: b.builderName(), }, corev1.EnvVar{ - Name: "BUILDER_KIND", + Name: "BUILDER_KIND", Value: b.builderKind(), }, corev1.EnvVar{ diff --git a/pkg/apis/build/v1alpha2/build_types.go b/pkg/apis/build/v1alpha2/build_types.go index 33f4fbc6f..053fb2e8e 100644 --- a/pkg/apis/build/v1alpha2/build_types.go +++ b/pkg/apis/build/v1alpha2/build_types.go @@ -51,12 +51,13 @@ var ( // +k8s:openapi-gen=true type BuildSpec struct { // +listType - Tags []string `json:"tags,omitempty"` - Builder corev1alpha1.BuildBuilderSpec `json:"builder,omitempty"` - ServiceAccountName string `json:"serviceAccountName,omitempty"` - Source corev1alpha1.SourceConfig `json:"source"` - Cache *BuildCacheConfig `json:"cache,omitempty"` - RunImage BuildSpecImage `json:"runImage,omitempty"` + Tags []string `json:"tags,omitempty"` + Builder corev1alpha1.BuildBuilderSpec `json:"builder,omitempty"` + ServiceAccountName string `json:"serviceAccountName,omitempty"` + Source corev1alpha1.SourceConfig `json:"source"` + Cache *BuildCacheConfig `json:"cache,omitempty"` + RunImage BuildSpecImage `json:"runImage,omitempty"` + ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty"` // +listType Services Services `json:"services,omitempty"` // +listType diff --git a/pkg/apis/build/v1alpha2/image_builds.go b/pkg/apis/build/v1alpha2/image_builds.go index ef7451a90..73756486e 100644 --- a/pkg/apis/build/v1alpha2/image_builds.go +++ b/pkg/apis/build/v1alpha2/image_builds.go @@ -22,8 +22,8 @@ const ( BuildChangesAnnotation = "image.kpack.io/buildChanges" BuildNeededAnnotation = "image.kpack.io/additionalBuildNeeded" - BuilderNameAnnotation = "image.kpack.io/builderName" - BuilderKindAnnotation = "image.kpack.io/builderKind" + BuilderNameAnnotation = "image.kpack.io/builderName" + BuilderKindAnnotation = "image.kpack.io/builderKind" BuildReasonConfig = "CONFIG" BuildReasonCommit = "COMMIT" @@ -51,8 +51,8 @@ func (im *Image) Build(sourceResolver *SourceResolver, builder BuilderResource, Annotations: combine(im.Annotations, map[string]string{ BuildReasonAnnotation: reasons, BuildChangesAnnotation: changes, - BuilderNameAnnotation: builder.GetName(), - BuilderKindAnnotation: builder.GetKind(), + BuilderNameAnnotation: builder.GetName(), + BuilderKindAnnotation: builder.GetKind(), }), }, Spec: BuildSpec{ @@ -79,6 +79,7 @@ func (im *Image) Build(sourceResolver *SourceResolver, builder BuilderResource, RuntimeClassName: im.RuntimeClassName(), SchedulerName: im.SchedulerName(), PriorityClassName: priorityClass, + ActiveDeadlineSeconds: im.BuildTimeout(), }, } } @@ -178,6 +179,13 @@ func (im *Image) Affinity() *corev1.Affinity { return im.Spec.Build.Affinity } +func (im *Image) BuildTimeout() *int64 { + if im.Spec.Build == nil { + return nil + } + return im.Spec.Build.BuildTimeout +} + func (im *Image) RuntimeClassName() *string { if im.Spec.Build == nil { return nil diff --git a/pkg/apis/build/v1alpha2/image_builds_test.go b/pkg/apis/build/v1alpha2/image_builds_test.go index 647a01fc3..7b6ddf982 100644 --- a/pkg/apis/build/v1alpha2/image_builds_test.go +++ b/pkg/apis/build/v1alpha2/image_builds_test.go @@ -276,18 +276,21 @@ func testImageBuilds(t *testing.T, when spec.G, it spec.S) { }) it("adds pod configuration", func() { + buildTimeout := int64(1800) image.Spec.Build = &ImageBuild{ Tolerations: []corev1.Toleration{{Key: "some-key"}}, NodeSelector: map[string]string{"foo": "bar"}, Affinity: &corev1.Affinity{ NodeAffinity: &corev1.NodeAffinity{}, }, + BuildTimeout: &buildTimeout, } build := image.Build(sourceResolver, builder, latestBuild, "", "", 1, "") assert.Equal(t, image.Spec.Build.Tolerations, build.Spec.Tolerations) assert.Equal(t, image.Spec.Build.NodeSelector, build.Spec.NodeSelector) assert.Equal(t, image.Spec.Build.Affinity, build.Spec.Affinity) + assert.Equal(t, image.Spec.Build.BuildTimeout, build.Spec.ActiveDeadlineSeconds) }) it("sets the notary config when present", func() { diff --git a/pkg/apis/build/v1alpha2/image_types.go b/pkg/apis/build/v1alpha2/image_types.go index be47e10b8..81b202743 100644 --- a/pkg/apis/build/v1alpha2/image_types.go +++ b/pkg/apis/build/v1alpha2/image_types.go @@ -77,6 +77,7 @@ type ImageBuild struct { Affinity *corev1.Affinity `json:"affinity,omitempty"` RuntimeClassName *string `json:"runtimeClassName,omitempty"` SchedulerName string `json:"schedulerName,omitempty"` + BuildTimeout *int64 `json:"buildTimeout,omitempty"` } // +k8s:openapi-gen=true