Skip to content

Commit

Permalink
Add Custom Scheduler Name to Build and BuildRun objects
Browse files Browse the repository at this point in the history
Signed-off-by: Dylan Orzel <dorzel@redhat.com>
  • Loading branch information
dorzel committed Jan 30, 2025
1 parent 9b50706 commit a013b72
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 1 deletion.
12 changes: 12 additions & 0 deletions deploy/crds/shipwright.io_buildruns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7439,6 +7439,10 @@ spec:
format: duration
type: string
type: object
schedulerName:
description: SchedulerName specifies the scheduler to be used
to dispatch the Pod
type: string
source:
description: |-
Source refers to the location where the source code is,
Expand Down Expand Up @@ -9753,6 +9757,10 @@ spec:
format: duration
type: string
type: object
schedulerName:
description: SchedulerName specifies the scheduler to be used to dispatch
the Pod
type: string
serviceAccount:
description: |-
ServiceAccount refers to the kubernetes serviceaccount
Expand Down Expand Up @@ -11941,6 +11949,10 @@ spec:
format: duration
type: string
type: object
schedulerName:
description: SchedulerName specifies the scheduler to be used
to dispatch the Pod
type: string
source:
description: |-
Source refers to the location where the source code is,
Expand Down
4 changes: 4 additions & 0 deletions deploy/crds/shipwright.io_builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,10 @@ spec:
format: duration
type: string
type: object
schedulerName:
description: SchedulerName specifies the scheduler to be used to dispatch
the Pod
type: string
source:
description: |-
Source refers to the location where the source code is,
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/build/v1beta1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const (
NodeSelectorNotValid BuildReason = "NodeSelectorNotValid"
// TolerationNotValid indicates that the Toleration value is not valid
TolerationNotValid BuildReason = "TolerationNotValid"

// SchedulerNameNotValid indicates that the Scheduler name is not valid
SchedulerNameNotValid BuildReason = "SchedulerNameNotValid"
// AllValidationsSucceeded indicates a Build was successfully validated
AllValidationsSucceeded = "all validations succeeded"
)
Expand Down Expand Up @@ -191,6 +192,10 @@ type BuildSpec struct {
// +patchMergeKey=Key
// +patchStrategy=merge
Tolerations []corev1.Toleration `json:"tolerations,omitempty" patchStrategy:"merge" patchMergeKey:"Key"`

// SchedulerName specifies the scheduler to be used to dispatch the Pod
// +optional
SchedulerName string `json:"schedulerName,omitempty"`
}

// BuildVolume is a volume that will be mounted in build pod during build step
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/build/v1beta1/buildrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ type BuildRunSpec struct {
// +patchMergeKey=Key
// +patchStrategy=merge
Tolerations []corev1.Toleration `json:"tolerations,omitempty" patchStrategy:"merge" patchMergeKey:"Key"`

// SchedulerName specifies the scheduler to be used to dispatch the Pod
// +optional
SchedulerName string `json:"schedulerName,omitempty"`
}

// BuildRunRequestedState defines the buildrun state the user can provide to override whatever is the current state.
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var validationTypes = [...]string{
validate.Triggers,
validate.NodeSelector,
validate.Tolerations,
validate.SchedulerName,
}

// ReconcileBuild reconciles a Build object
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/buildrun/buildrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req
validate.NewEnv(build),
validate.NewNodeSelector(build),
validate.NewTolerations(build),
validate.NewSchedulerName(build),
)

// an internal/technical error during validation happened
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/buildrun/resources/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1
// explicitly setting them here is required for validation to happen.
build.Spec.NodeSelector = buildRun.Spec.NodeSelector
build.Spec.Tolerations = buildRun.Spec.Tolerations
build.Spec.SchedulerName = buildRun.Spec.SchedulerName
return nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/buildrun/resources/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,15 @@ func GenerateTaskRun(
taskRunPodTemplate.Tolerations = taskRunTolerations
}

// Set custom scheduler name if specified, giving preference to BuildRun values
if buildRun.Spec.SchedulerName != "" {
taskRunPodTemplate.SchedulerName = buildRun.Spec.SchedulerName
} else {
if build.Spec.SchedulerName != "" {
taskRunPodTemplate.SchedulerName = build.Spec.SchedulerName
}
}

if !(taskRunPodTemplate.Equals(&pod.PodTemplate{})) {
expectedTaskRun.Spec.PodTemplate = taskRunPodTemplate
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const (
NodeSelector = "nodeselector"
// Tolerations for validating `spec.tolerations` entry
Tolerations = "tolerations"
// SchedulerName for validating `spec.schedulerName` entry
SchedulerName = "schedulername"
)

const (
Expand Down Expand Up @@ -83,6 +85,8 @@ func NewValidation(
return &NodeSelectorRef{Build: build}, nil
case Tolerations:
return &TolerationsRef{Build: build}, nil
case SchedulerName:
return &SchedulerNameRef{Build: build}, nil
default:
return nil, fmt.Errorf("unknown validation type")
}
Expand Down

0 comments on commit a013b72

Please sign in to comment.