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

[release-4.17] OCPBUGS-45964: performanceprofile cpuset input validation #1247

Open
wants to merge 2 commits into
base: release-4.17
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func (r *PerformanceProfile) validateCPUs() field.ErrorList {
cpuLists, err := components.NewCPULists(string(*cpus.Reserved), string(*cpus.Isolated), offlined, shared)
if err != nil {
allErrs = append(allErrs, field.InternalError(field.NewPath("spec.cpu"), err))
// If err != nil then the cpuList is nil and we can't continue with the function logic
return allErrs
}

if cpuLists.GetReserved().IsEmpty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ var _ = Describe("PerformanceProfile", func() {
Expect(errors).NotTo(BeEmpty(), "should have validation error when isolated and shared CPUs have overlap")
Expect(errors[0].Error()).To(Or(ContainSubstring("isolated and shared cpus overlap"), ContainSubstring("shared and isolated cpus overlap")))
})
DescribeTable("should reject invalid input that does not represent CPU sets",
func(fieldSetter func(*PerformanceProfile, CPUSet), cpusField string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, this is a backport, but still: are we guaranteed mutations made by each table item does not leak to other items?
e.g. are items fully isolated from each other?

garbageInput := CPUSet("garbage")
fieldSetter(profile, garbageInput)
errors := profile.validateCPUs()
Expect(errors).NotTo(BeEmpty(), "should have error when "+cpusField+" is filled with garbage input")
Expect(errors[0].Error()).To(Or(ContainSubstring("Internal error: strconv.Atoi: parsing")))
},
Entry("reserved CPUs", func(p *PerformanceProfile, input CPUSet) { p.Spec.CPU.Reserved = &input }, "reserved CPUs"),
Entry("isolated CPUs", func(p *PerformanceProfile, input CPUSet) { p.Spec.CPU.Isolated = &input }, "isolated CPUs"),
Entry("shared CPUs", func(p *PerformanceProfile, input CPUSet) { p.Spec.CPU.Shared = &input }, "shared CPUs"),
Entry("offline CPUs", func(p *PerformanceProfile, input CPUSet) { p.Spec.CPU.Offlined = &input }, "offline CPUs"),
)
})

Describe("CPU Frequency validation", func() {
Expand Down