Skip to content

Commit

Permalink
feat: Add limit for suggestion pod (#932)
Browse files Browse the repository at this point in the history
* feat: Add limit for suggestion pod

Signed-off-by: Ce Gao <gaoce@caicloud.io>

* fix: Format

Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege authored and k8s-ci-robot committed Nov 25, 2019
1 parent 40f55b4 commit 29b3bc0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/controller.v1alpha3/suggestion/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

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"
Expand All @@ -24,6 +25,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")
Expand Down Expand Up @@ -123,6 +129,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{
Expand Down

0 comments on commit 29b3bc0

Please sign in to comment.