From 865373ef6c268e6e960db98f2352418adcbf55d1 Mon Sep 17 00:00:00 2001 From: Li Yi Date: Sat, 30 Sep 2017 10:40:05 +0800 Subject: [PATCH 1/3] Fix the cpu limits and requests in generated deployment file Signed-off-by: Li Yi --- pkg/transformer/kubernetes/k8sutils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/transformer/kubernetes/k8sutils.go b/pkg/transformer/kubernetes/k8sutils.go index 6a0d7621..3df9c42b 100644 --- a/pkg/transformer/kubernetes/k8sutils.go +++ b/pkg/transformer/kubernetes/k8sutils.go @@ -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 From fa5281d4405511babf889dcd42c4fec4ac635d32 Mon Sep 17 00:00:00 2001 From: Li Yi Date: Mon, 9 Oct 2017 19:22:31 +0800 Subject: [PATCH 2/3] Fix the cpu limits and requests in generated deployment file Signed-off-by: Li Yi --- pkg/transformer/kubernetes/k8sutils_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/transformer/kubernetes/k8sutils_test.go b/pkg/transformer/kubernetes/k8sutils_test.go index e586cfca..05001632 100644 --- a/pkg/transformer/kubernetes/k8sutils_test.go +++ b/pkg/transformer/kubernetes/k8sutils_test.go @@ -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) } From d283bbbcc26598c97c7e1d837ce46b24cba15084 Mon Sep 17 00:00:00 2001 From: Li Yi Date: Tue, 10 Oct 2017 10:04:34 +0800 Subject: [PATCH 3/3] Fix the cpu limits and requests in generated deployment file Signed-off-by: Li Yi --- script/test/fixtures/v3/output-k8s-full-example.json | 2 +- script/test/fixtures/v3/output-memcpu-k8s.json | 4 ++-- script/test/fixtures/v3/output-os-full-example.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/script/test/fixtures/v3/output-k8s-full-example.json b/script/test/fixtures/v3/output-k8s-full-example.json index a7dc8208..fce1c23f 100644 --- a/script/test/fixtures/v3/output-k8s-full-example.json +++ b/script/test/fixtures/v3/output-k8s-full-example.json @@ -155,7 +155,7 @@ ], "resources": { "limits": { - "cpu": "1", + "cpu": "1m", "memory": "52428800" }, "requests": { diff --git a/script/test/fixtures/v3/output-memcpu-k8s.json b/script/test/fixtures/v3/output-memcpu-k8s.json index 67c9ba7d..c6227b14 100644 --- a/script/test/fixtures/v3/output-memcpu-k8s.json +++ b/script/test/fixtures/v3/output-memcpu-k8s.json @@ -64,11 +64,11 @@ "image": "redis", "resources": { "limits": { - "cpu": "10", + "cpu": "10m", "memory": "52428800" }, "requests": { - "cpu": "1", + "cpu": "1m", "memory": "20971520" } } diff --git a/script/test/fixtures/v3/output-os-full-example.json b/script/test/fixtures/v3/output-os-full-example.json index a7dc8208..fce1c23f 100644 --- a/script/test/fixtures/v3/output-os-full-example.json +++ b/script/test/fixtures/v3/output-os-full-example.json @@ -155,7 +155,7 @@ ], "resources": { "limits": { - "cpu": "1", + "cpu": "1m", "memory": "52428800" }, "requests": {