Skip to content

Commit cc350f6

Browse files
committed
Propagate SchedulingGates in RunWithPodSetsInfo
1 parent 537bfcf commit cc350f6

File tree

7 files changed

+64
-8
lines changed

7 files changed

+64
-8
lines changed

api/v1beta2/appwrapper_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ type AppWrapperPodSetInfo struct {
8080
// Tolerations to be added to the PodSpecTemplate
8181
//+optional
8282
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
83+
// SchedulingGates to be added to the PodSpecTemplate
84+
//+optional
85+
SchedulingGates []corev1.PodSchedulingGate `json:"schedulingGates,omitempty"`
8386
}
8487

8588
// AppWrapperStatus defines the observed state of the appwrapper

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/workload.codeflare.dev_appwrappers.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ spec:
9292
type: string
9393
description: NodeSelectors to be added to the PodSpecTemplate
9494
type: object
95+
schedulingGates:
96+
description: SchedulingGates to be added to the PodSpecTemplate
97+
items:
98+
description: PodSchedulingGate is associated to a Pod
99+
to guard its scheduling.
100+
properties:
101+
name:
102+
description: |-
103+
Name of the scheduling gate.
104+
Each scheduling gate must have a unique name field.
105+
type: string
106+
required:
107+
- name
108+
type: object
109+
type: array
95110
tolerations:
96111
description: Tolerations to be added to the PodSpecTemplate
97112
items:

internal/controller/appwrapper/appwrapper_controller_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ var _ = Describe("AppWrapper Controller", func() {
4343
var awReconciler *AppWrapperReconciler
4444
var awName types.NamespacedName
4545
markerPodSet := podset.PodSetInfo{
46-
Labels: map[string]string{"testkey1": "value1"},
47-
Annotations: map[string]string{"test2": "test2"},
48-
NodeSelector: map[string]string{"nodeName": "myNode"},
49-
Tolerations: []v1.Toleration{{Key: "aKey", Operator: "Exists", Effect: "NoSchedule"}},
46+
Labels: map[string]string{"testkey1": "value1"},
47+
Annotations: map[string]string{"test2": "test2"},
48+
NodeSelector: map[string]string{"nodeName": "myNode"},
49+
Tolerations: []v1.Toleration{{Key: "aKey", Operator: "Exists", Effect: "NoSchedule"}},
50+
SchedulingGates: []v1.PodSchedulingGate{{Name: "aGate"}},
5051
}
5152
var kueuePodSets []kueue.PodSet
5253

@@ -172,6 +173,9 @@ var _ = Describe("AppWrapper Controller", func() {
172173
for k, v := range markerPodSet.NodeSelector {
173174
Expect(p.Spec.NodeSelector).Should(HaveKeyWithValue(k, v))
174175
}
176+
for _, v := range markerPodSet.SchedulingGates {
177+
Expect(p.Spec.SchedulingGates).Should(ContainElement(v))
178+
}
175179
}
176180

177181
validateAutopilot := func(p *v1.Pod) {
@@ -393,6 +397,7 @@ var _ = Describe("AppWrapper Controller", func() {
393397
Expect(p.Annotations).Should(HaveKeyWithValue("myComplexAnnotation", "myComplexValue"))
394398
Expect(p.Spec.NodeSelector).Should(HaveKeyWithValue("myComplexSelector", "myComplexValue"))
395399
Expect(p.Spec.Tolerations).Should(ContainElement(v1.Toleration{Key: "myComplexKey", Value: "myComplexValue", Operator: v1.TolerationOpEqual, Effect: v1.TaintEffectNoSchedule}))
400+
Expect(p.Spec.SchedulingGates).Should(ContainElement(v1.PodSchedulingGate{Name: "myComplexGate"}))
396401
mes := p.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0].MatchExpressions
397402
found := false
398403
for _, me := range mes {

internal/controller/appwrapper/fixtures_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ spec:
163163
operator: NotIn
164164
values:
165165
- badHost1
166+
schedulingGates:
167+
- name: myComplexGate
166168
tolerations:
167169
- key: myComplexKey
168170
value: myComplexValue

internal/controller/appwrapper/resource_management.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,31 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
258258
spec["tolerations"] = tolerations
259259
}
260260

261+
// SchedulingGates
262+
if len(toInject.SchedulingGates) > 0 {
263+
if _, ok := spec["schedulingGates"]; !ok {
264+
spec["schedulingGates"] = []interface{}{}
265+
}
266+
schedulingGates := spec["schedulingGates"].([]interface{})
267+
for _, addition := range toInject.SchedulingGates {
268+
duplicate := false
269+
for _, existing := range schedulingGates {
270+
if imap, ok := existing.(map[string]interface{}); ok {
271+
if iName, ok := imap["name"]; ok {
272+
if sName, ok := iName.(string); ok && sName == addition.Name {
273+
duplicate = true
274+
break
275+
}
276+
}
277+
}
278+
}
279+
if !duplicate {
280+
schedulingGates = append(schedulingGates, map[string]interface{}{"name": addition.Name})
281+
}
282+
}
283+
spec["schedulingGates"] = schedulingGates
284+
}
285+
261286
// Scheduler Name
262287
if r.Config.SchedulerName != "" {
263288
if existing, _ := spec["schedulerName"].(string); existing == "" {

pkg/utils/utils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,11 @@ func SetPodSetInfos(aw *workloadv1beta2.AppWrapper, podSetsInfo []podset.PodSetI
374374
continue // we will return an error below...continuing to get an accurate count for the error message
375375
}
376376
aw.Spec.Components[idx].PodSetInfos[podSetIdx] = workloadv1beta2.AppWrapperPodSetInfo{
377-
Annotations: podSetsInfo[podSetsInfoIndex-1].Annotations,
378-
Labels: podSetsInfo[podSetsInfoIndex-1].Labels,
379-
NodeSelector: podSetsInfo[podSetsInfoIndex-1].NodeSelector,
380-
Tolerations: podSetsInfo[podSetsInfoIndex-1].Tolerations,
377+
Annotations: podSetsInfo[podSetsInfoIndex-1].Annotations,
378+
Labels: podSetsInfo[podSetsInfoIndex-1].Labels,
379+
NodeSelector: podSetsInfo[podSetsInfoIndex-1].NodeSelector,
380+
Tolerations: podSetsInfo[podSetsInfoIndex-1].Tolerations,
381+
SchedulingGates: podSetsInfo[podSetsInfoIndex-1].SchedulingGates,
381382
}
382383
}
383384
}

0 commit comments

Comments
 (0)