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

Fixed function AreCPUResourcesWholeUnits(). #1631

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
17 changes: 8 additions & 9 deletions pkg/provider/isolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,20 @@ func AreCPUResourcesWholeUnits(p *Pod) bool {
// Pods may contain more than one container. All containers must conform to the CPU isolation requirements.
for _, cut := range p.Containers {
// Resources must be specified
if len(cut.Resources.Requests) == 0 || len(cut.Resources.Limits) == 0 {
cpuRequestsMillis := cut.Resources.Requests.Cpu().MilliValue()
cpuLimitsMillis := cut.Resources.Limits.Cpu().MilliValue()

if cpuRequestsMillis == 0 || cpuLimitsMillis == 0 {
logrus.Debugf("%s has been found with undefined requests or limits.", cut.String())
return false
}

// Gather the values
cpuRequests := cut.Resources.Requests.Cpu().MilliValue()
cpuLimits := cut.Resources.Limits.Cpu().MilliValue()

if !isInteger(cpuRequests) {
logrus.Debugf("%s has CPU requests %d (milli) that has to be a whole unit.", cut.String(), cpuRequests)
if !isInteger(cpuRequestsMillis) {
logrus.Debugf("%s has CPU requests %d (milli) that has to be a whole unit.", cut.String(), cpuRequestsMillis)
return false
}
if !isInteger(cpuLimits) {
logrus.Debugf("%s has CPU limits %d (milli) that has to be a whole unit.", cut.String(), cpuLimits)
if !isInteger(cpuLimitsMillis) {
logrus.Debugf("%s has CPU limits %d (milli) that has to be a whole unit.", cut.String(), cpuLimitsMillis)
return false
}
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/provider/isolation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,39 @@ func TestCPUIsolation(t *testing.T) {
runtimeClassNameResult: true,
loadBalancingResult: false,
},
{ // Test Case #6 - Mem reqs/limit set, but no Cpu limits/reqs set.
testPod: &Pod{
Containers: []*Container{
{
Container: &corev1.Container{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
"memory": resource.MustParse(validMemLimit),
},
Limits: corev1.ResourceList{
"memory": resource.MustParse(validMemLimit),
},
},
},
},
},
Pod: &corev1.Pod{
Spec: corev1.PodSpec{
RuntimeClassName: &testClassName,
},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"cpu-load-balancing.crio.io": "disable",
"irq-load-balancing.crio.io": "disable",
},
},
},
},
resourcesIdenticalResult: true,
wholeUnitsResult: false,
runtimeClassNameResult: true,
loadBalancingResult: true,
},
}

for _, tc := range testCases {
Expand Down
Loading