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

Adding activeDeadlineSeconds to build and pod spec #958

Merged
merged 15 commits into from
Aug 2, 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
2 changes: 2 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
ncarlson marked this conversation as resolved.
Show resolved Hide resolved
- `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.
Expand Down
3 changes: 2 additions & 1 deletion docs/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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, 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:
Expand All @@ -140,6 +140,7 @@ build:
effect: "NoSchedule"
nodeSelector:
disktype: ssd
buildTimeout: 1600
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
Expand Down
7 changes: 4 additions & 3 deletions pkg/apis/build/v1alpha2/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
13 changes: 7 additions & 6 deletions pkg/apis/build/v1alpha2/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions pkg/apis/build/v1alpha2/image_builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -79,6 +79,7 @@ func (im *Image) Build(sourceResolver *SourceResolver, builder BuilderResource,
RuntimeClassName: im.RuntimeClassName(),
SchedulerName: im.SchedulerName(),
PriorityClassName: priorityClass,
ActiveDeadlineSeconds: im.BuildTimeout(),
},
}
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/build/v1alpha2/image_builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/build/v1alpha2/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down