Skip to content

Propagate SchedulingGates in RunWithPodSetsInfo #301

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

Merged
merged 1 commit into from
Jan 14, 2025
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: 3 additions & 0 deletions api/v1beta2/appwrapper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type AppWrapperPodSetInfo struct {
// Tolerations to be added to the PodSpecTemplate
//+optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// SchedulingGates to be added to the PodSpecTemplate
//+optional
SchedulingGates []corev1.PodSchedulingGate `json:"schedulingGates,omitempty"`
}

// AppWrapperStatus defines the observed state of the appwrapper
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions config/crd/bases/workload.codeflare.dev_appwrappers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ spec:
type: string
description: NodeSelectors to be added to the PodSpecTemplate
type: object
schedulingGates:
description: SchedulingGates to be added to the PodSpecTemplate
items:
description: PodSchedulingGate is associated to a Pod
to guard its scheduling.
properties:
name:
description: |-
Name of the scheduling gate.
Each scheduling gate must have a unique name field.
type: string
required:
- name
type: object
type: array
tolerations:
description: Tolerations to be added to the PodSpecTemplate
items:
Expand Down
13 changes: 9 additions & 4 deletions internal/controller/appwrapper/appwrapper_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ var _ = Describe("AppWrapper Controller", func() {
var awReconciler *AppWrapperReconciler
var awName types.NamespacedName
markerPodSet := podset.PodSetInfo{
Labels: map[string]string{"testkey1": "value1"},
Annotations: map[string]string{"test2": "test2"},
NodeSelector: map[string]string{"nodeName": "myNode"},
Tolerations: []v1.Toleration{{Key: "aKey", Operator: "Exists", Effect: "NoSchedule"}},
Labels: map[string]string{"testkey1": "value1"},
Annotations: map[string]string{"test2": "test2"},
NodeSelector: map[string]string{"nodeName": "myNode"},
Tolerations: []v1.Toleration{{Key: "aKey", Operator: "Exists", Effect: "NoSchedule"}},
SchedulingGates: []v1.PodSchedulingGate{{Name: "aGate"}},
}
var kueuePodSets []kueue.PodSet

Expand Down Expand Up @@ -172,6 +173,9 @@ var _ = Describe("AppWrapper Controller", func() {
for k, v := range markerPodSet.NodeSelector {
Expect(p.Spec.NodeSelector).Should(HaveKeyWithValue(k, v))
}
for _, v := range markerPodSet.SchedulingGates {
Expect(p.Spec.SchedulingGates).Should(ContainElement(v))
}
}

validateAutopilot := func(p *v1.Pod) {
Expand Down Expand Up @@ -393,6 +397,7 @@ var _ = Describe("AppWrapper Controller", func() {
Expect(p.Annotations).Should(HaveKeyWithValue("myComplexAnnotation", "myComplexValue"))
Expect(p.Spec.NodeSelector).Should(HaveKeyWithValue("myComplexSelector", "myComplexValue"))
Expect(p.Spec.Tolerations).Should(ContainElement(v1.Toleration{Key: "myComplexKey", Value: "myComplexValue", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}))
Expect(p.Spec.SchedulingGates).Should(ContainElement(v1.PodSchedulingGate{Name: "myComplexGate"}))
mes := p.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions
found := false
for _, me := range mes {
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/appwrapper/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ spec:
operator: NotIn
values:
- badHost1
schedulingGates:
- name: myComplexGate
tolerations:
- key: myComplexKey
value: myComplexValue
Expand Down
25 changes: 25 additions & 0 deletions internal/controller/appwrapper/resource_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
spec["tolerations"] = tolerations
}

// SchedulingGates
if len(toInject.SchedulingGates) > 0 {
if _, ok := spec["schedulingGates"]; !ok {
spec["schedulingGates"] = []interface{}{}
}
schedulingGates := spec["schedulingGates"].([]interface{})
for _, addition := range toInject.SchedulingGates {
duplicate := false
for _, existing := range schedulingGates {
if imap, ok := existing.(map[string]interface{}); ok {
if iName, ok := imap["name"]; ok {
if sName, ok := iName.(string); ok && sName == addition.Name {
duplicate = true
break
}
}
}
}
if !duplicate {
schedulingGates = append(schedulingGates, map[string]interface{}{"name": addition.Name})
}
}
spec["schedulingGates"] = schedulingGates
}

// Scheduler Name
if r.Config.SchedulerName != "" {
if existing, _ := spec["schedulerName"].(string); existing == "" {
Expand Down
9 changes: 5 additions & 4 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,11 @@ func SetPodSetInfos(aw *workloadv1beta2.AppWrapper, podSetsInfo []podset.PodSetI
continue // we will return an error below...continuing to get an accurate count for the error message
}
aw.Spec.Components[idx].PodSetInfos[podSetIdx] = workloadv1beta2.AppWrapperPodSetInfo{
Annotations: podSetsInfo[podSetsInfoIndex-1].Annotations,
Labels: podSetsInfo[podSetsInfoIndex-1].Labels,
NodeSelector: podSetsInfo[podSetsInfoIndex-1].NodeSelector,
Tolerations: podSetsInfo[podSetsInfoIndex-1].Tolerations,
Annotations: podSetsInfo[podSetsInfoIndex-1].Annotations,
Labels: podSetsInfo[podSetsInfoIndex-1].Labels,
NodeSelector: podSetsInfo[podSetsInfoIndex-1].NodeSelector,
Tolerations: podSetsInfo[podSetsInfoIndex-1].Tolerations,
SchedulingGates: podSetsInfo[podSetsInfoIndex-1].SchedulingGates,
}
}
}
Expand Down
Loading