Merge pull request #838 from denverdino/fix-cpu-limits-and-requests

Fix the cpu limits and requests in generated deployment file
This commit is contained in:
Charlie Drage 2017-10-10 12:27:20 -04:00 committed by GitHub
commit b2621194c6
5 changed files with 8 additions and 8 deletions

View File

@ -424,7 +424,7 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
}
if service.CPULimit != 0 {
resourceLimit[api.ResourceCPU] = *resource.NewQuantity(service.CPULimit, "RandomStringForFormat")
resourceLimit[api.ResourceCPU] = *resource.NewMilliQuantity(service.CPULimit, resource.DecimalSI)
}
template.Spec.Containers[0].Resources.Limits = resourceLimit
@ -439,7 +439,7 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
}
if service.CPUReservation != 0 {
resourceRequests[api.ResourceCPU] = *resource.NewQuantity(service.CPUReservation, "RandomStringForFormat")
resourceRequests[api.ResourceCPU] = *resource.NewMilliQuantity(service.CPUReservation, resource.DecimalSI)
}
template.Spec.Containers[0].Resources.Requests = resourceRequests

View File

@ -171,11 +171,11 @@ func TestCreateServiceWithCPULimit(t *testing.T) {
// Retrieve the deployment object and test that it matches the cpu value
for _, obj := range objects {
if deploy, ok := obj.(*extensions.Deployment); ok {
cpuLimit, _ := deploy.Spec.Template.Spec.Containers[0].Resources.Limits.Cpu().AsInt64()
cpuLimit := deploy.Spec.Template.Spec.Containers[0].Resources.Limits.Cpu().MilliValue()
if cpuLimit != 10 {
t.Errorf("Expected 10 for cpu limit check, got %v", cpuLimit)
}
cpuReservation, _ := deploy.Spec.Template.Spec.Containers[0].Resources.Requests.Cpu().AsInt64()
cpuReservation := deploy.Spec.Template.Spec.Containers[0].Resources.Requests.Cpu().MilliValue()
if cpuReservation != 1 {
t.Errorf("Expected 1 for cpu reservation check, got %v", cpuReservation)
}

View File

@ -155,7 +155,7 @@
],
"resources": {
"limits": {
"cpu": "1",
"cpu": "1m",
"memory": "52428800"
},
"requests": {

View File

@ -64,11 +64,11 @@
"image": "redis",
"resources": {
"limits": {
"cpu": "10",
"cpu": "10m",
"memory": "52428800"
},
"requests": {
"cpu": "1",
"cpu": "1m",
"memory": "20971520"
}
}

View File

@ -155,7 +155,7 @@
],
"resources": {
"limits": {
"cpu": "1",
"cpu": "1m",
"memory": "52428800"
},
"requests": {