Skip to content

Commit

Permalink
Set default resource requests = 1/2 * limits (#653)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha authored Nov 12, 2020
1 parent fb8a454 commit ea20944
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apis/kubedb/v1alpha2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ const (

DBCustomConfigName = "custom-config"

DefaultCPULimit = ".25"
DefaultMemoryLimit = "512Mi"
DefaultCPULimit = ".250"
DefaultMemoryLimit = "512Mi"
DefaultCPURequest = ".100"
DefaultMemoryRequest = "256Mi"

// =========================== Database key Constants ============================
PostgresKey = ResourceSingularPostgres + "." + kubedb.GroupName
Expand Down
9 changes: 9 additions & 0 deletions apis/kubedb/v1alpha2/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ func setDefaultResourceLimits(req *core.ResourceRequirements) {
if req.Limits == nil {
req.Limits = core.ResourceList{}
}
if req.Requests == nil {
req.Requests = core.ResourceList{}
}
req.Limits[core.ResourceCPU] = fn(core.ResourceCPU, resource.MustParse(DefaultCPULimit))
if _, ok := req.Requests[core.ResourceCPU]; !ok {
req.Requests[core.ResourceCPU] = resource.MustParse(DefaultCPURequest)
}
req.Limits[core.ResourceMemory] = fn(core.ResourceMemory, resource.MustParse(DefaultMemoryLimit))
if _, ok := req.Requests[core.ResourceMemory]; !ok {
req.Requests[core.ResourceMemory] = resource.MustParse(DefaultMemoryRequest)
}
}

0 comments on commit ea20944

Please sign in to comment.