From 4a615add71be03ac46d95c9d12acd4eb14db4223 Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Mon, 25 Nov 2019 14:02:52 +0800 Subject: [PATCH 1/2] feat: Add limit for suggestion pod Signed-off-by: Ce Gao --- .../suggestion/composer/composer.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/controller.v1alpha3/suggestion/composer/composer.go b/pkg/controller.v1alpha3/suggestion/composer/composer.go index 0a66ed90b07..03f59a849cf 100644 --- a/pkg/controller.v1alpha3/suggestion/composer/composer.go +++ b/pkg/controller.v1alpha3/suggestion/composer/composer.go @@ -3,6 +3,8 @@ package composer import ( "fmt" + "k8s.io/apimachinery/pkg/api/resource" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -24,6 +26,11 @@ const ( defaultFailureThreshold = 12 // Ref https://github.com/grpc-ecosystem/grpc-health-probe/ defaultGRPCHealthCheckProbe = "/bin/grpc_health_probe" + + cpuLimit = "500m" + cpuRequest = "50m" + memLimit = "100Mi" + memRequest = "10Mi" ) var log = logf.Log.WithName("suggestion-composer") @@ -123,6 +130,35 @@ func (g *General) desiredContainer(s *suggestionsv1alpha3.Suggestion) (*corev1.C ContainerPort: consts.DefaultSuggestionPort, }, } + + cpuLimitQuantity, err := resource.ParseQuantity(cpuLimit) + if err != nil { + return nil, err + } + cpuRequestQuantity, err := resource.ParseQuantity(cpuRequest) + if err != nil { + return nil, err + } + memLimitQuantity, err := resource.ParseQuantity(memLimit) + if err != nil { + return nil, err + } + memRequestQuantity, err := resource.ParseQuantity(memRequest) + if err != nil { + return nil, err + } + + c.Resources = corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: cpuLimitQuantity, + corev1.ResourceMemory: memLimitQuantity, + }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: cpuRequestQuantity, + corev1.ResourceMemory: memRequestQuantity, + }, + } + c.ReadinessProbe = &corev1.Probe{ Handler: corev1.Handler{ Exec: &corev1.ExecAction{ From a65c960e8215a159fdf7329fb084cd68fd25b31b Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Mon, 25 Nov 2019 14:08:05 +0800 Subject: [PATCH 2/2] fix: Format Signed-off-by: Ce Gao --- pkg/controller.v1alpha3/suggestion/composer/composer.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/controller.v1alpha3/suggestion/composer/composer.go b/pkg/controller.v1alpha3/suggestion/composer/composer.go index 03f59a849cf..e4dac0c6246 100644 --- a/pkg/controller.v1alpha3/suggestion/composer/composer.go +++ b/pkg/controller.v1alpha3/suggestion/composer/composer.go @@ -3,10 +3,9 @@ package composer import ( "fmt" - "k8s.io/apimachinery/pkg/api/resource" - appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client"