From ecaa42598493a6ca8f2e946aa9a0297cb8198d2d Mon Sep 17 00:00:00 2001 From: Sergey Dudoladov <sergey.dudoladov@zalando.de> Date: Mon, 12 Nov 2018 17:59:05 +0100 Subject: [PATCH] Correctly bump up default memory request during Sync --- pkg/cluster/k8sres.go | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 642ee425..b775ee63 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -647,19 +647,46 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State if c.OpConfig.SetMemoryRequestToLimit { - isSmaller, err := util.RequestIsSmallerThanLimit(spec.Resources.ResourceRequests.Memory, spec.Resources.ResourceLimits.Memory) + // controller adjusts the default memory request at operator startup + + request := spec.Resources.ResourceRequests.Memory + if request == "" { + request = c.OpConfig.DefaultMemoryRequest + } + + limit := spec.Resources.ResourceLimits.Memory + if limit == "" { + limit = c.OpConfig.DefaultMemoryLimit + } + + isSmaller, err := util.RequestIsSmallerThanLimit(request, limit) if err != nil { return nil, err } if isSmaller { - c.logger.Warningf("The memory request of %v for the Postgres container is increased to match the memory limit of %v.", spec.Resources.ResourceRequests.Memory, spec.Resources.ResourceLimits.Memory) - spec.Resources.ResourceRequests.Memory = spec.Resources.ResourceLimits.Memory + c.logger.Warningf("The memory request of %v for the Postgres container is increased to match the memory limit of %v.", request, limit) + spec.Resources.ResourceRequests.Memory = limit } + // controller adjusts the Scalyr sidecar request at operator startup + // as this sidecar is managed separately + // adjust sidecar containers defined for that particular cluster for _, sidecar := range spec.Sidecars { - isSmaller, err := util.RequestIsSmallerThanLimit(sidecar.Resources.ResourceRequests.Memory, sidecar.Resources.ResourceLimits.Memory) + + // TODO #413 + sidecarRequest := sidecar.Resources.ResourceRequests.Memory + if request == "" { + request = c.OpConfig.DefaultMemoryRequest + } + + sidecarLimit := sidecar.Resources.ResourceLimits.Memory + if limit == "" { + limit = c.OpConfig.DefaultMemoryLimit + } + + isSmaller, err := util.RequestIsSmallerThanLimit(sidecarRequest, sidecarLimit) if err != nil { return nil, err } @@ -669,9 +696,6 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State } } - // controller adjusts default memory request and Scalyr sidecar container's request - // as those do not need to be synced - } defaultResources := c.makeDefaultResources() -- GitLab