Skip to content

Commit 79770e2

Browse files
authored
Add validation check between isolated and offlined CPUs (openshift#363)
Isolated and offlined can not share any CPUs. If there is an overlap, it fails. Signed-off-by: Mario Fernandez <mariofer@redhat.com>
1 parent 9cc5863 commit 79770e2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/apis/performanceprofile/v2/performanceprofile_validation.go

+3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ func (r *PerformanceProfile) validateCPUs() field.ErrorList {
155155
if overlap := components.Intersect(cpuLists.GetReserved(), cpuLists.GetOfflined()); len(overlap) != 0 {
156156
allErrs = append(allErrs, field.Invalid(field.NewPath("spec.cpu"), r.Spec.CPU, fmt.Sprintf("reserved and offlined cpus overlap: %v", overlap)))
157157
}
158+
if overlap := components.Intersect(cpuLists.GetIsolated(), cpuLists.GetOfflined()); len(overlap) != 0 {
159+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec.cpu"), r.Spec.CPU, fmt.Sprintf("isolated and offlined cpus overlap: %v", overlap)))
160+
}
158161
}
159162
}
160163
}

pkg/apis/performanceprofile/v2/performanceprofile_validation_test.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,21 @@ var _ = Describe("PerformanceProfile", func() {
191191
profile.Spec.CPU.Isolated = &isolatedCPUs
192192
profile.Spec.CPU.Offlined = &offlinedCPUs
193193
errors := profile.validateCPUs()
194-
Expect(errors).NotTo(BeEmpty(), "should have validation error when reserved and isolation CPUs have overlap")
194+
Expect(errors).NotTo(BeEmpty(), "should have validation error when reserved and offlined CPUs have overlap")
195195
Expect(errors[0].Error()).To(ContainSubstring("reserved and offlined cpus overlap"))
196196
})
197+
198+
It("should reject cpus allocation with overlapping sets between isolated and offlined", func() {
199+
reservedCPUs := CPUSet("0-7")
200+
isolatedCPUs := CPUSet("8-11")
201+
offlinedCPUs := CPUSet("10-15")
202+
profile.Spec.CPU.Reserved = &reservedCPUs
203+
profile.Spec.CPU.Isolated = &isolatedCPUs
204+
profile.Spec.CPU.Offlined = &offlinedCPUs
205+
errors := profile.validateCPUs()
206+
Expect(errors).NotTo(BeEmpty(), "should have validation error when isolated and offlined CPUs have overlap")
207+
Expect(errors[0].Error()).To(ContainSubstring("isolated and offlined cpus overlap"))
208+
})
197209
})
198210

199211
Describe("Label selectors validation", func() {

0 commit comments

Comments
 (0)