1) Handle per-cluster sidecars 2) Add this option to operator CRD 3) ad parsing for proepr comparison
This commit is contained in:
		
							parent
							
								
									047368b612
								
							
						
					
					
						commit
						c6df079d2b
					
				|  | @ -131,6 +131,7 @@ type OperatorConfigurationData struct { | |||
| 	PostgresUsersConfiguration PostgresUsersConfiguration   `json:"users"` | ||||
| 	Kubernetes                 KubernetesMetaConfiguration  `json:"kubernetes"` | ||||
| 	PostgresPodResources       PostgresPodResourcesDefaults `json:"postgres_pod_resources"` | ||||
| 	SetMemoryRequestToLimit    bool                         `json:"set_memory_request_to_limit,omitempty"` | ||||
| 	Timeouts                   OperatorTimeouts             `json:"timeouts"` | ||||
| 	LoadBalancer               LoadBalancerConfiguration    `json:"load_balancer"` | ||||
| 	AWSGCP                     AWSGCPConfiguration          `json:"aws_or_gcp"` | ||||
|  |  | |||
|  | @ -647,12 +647,22 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State | |||
| 
 | ||||
| 	if c.OpConfig.SetMemoryRequestToLimit { | ||||
| 
 | ||||
| 		if spec.Resources.ResourceLimits.Memory > spec.Resources.ResourceRequests.Memory { | ||||
| 		if util.RequestIsSmallerThanLimit(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.", spec.Resources.ResourceRequests.Memory, spec.Resources.ResourceLimits.Memory) | ||||
| 			spec.Resources.ResourceRequests.Memory = spec.Resources.ResourceLimits.Memory | ||||
| 
 | ||||
| 		} | ||||
| 
 | ||||
| 		// controller adjusts default and Spilo sidecar container requests (those do not need Sync)
 | ||||
| 		// adjust sidecar containers defined for that particular cluster
 | ||||
| 		for _, sidecar := range spec.Sidecars { | ||||
| 			if util.RequestIsSmallerThanLimit(sidecar.Resources.ResourceRequests.Memory, sidecar.Resources.ResourceLimits.Memory) { | ||||
| 				c.logger.Warningf("The memory request of %v for the %v sidecar container is increased to match the memory limit of %v.", sidecar.Resources.ResourceRequests.Memory, sidecar.Name, sidecar.Resources.ResourceLimits.Memory) | ||||
| 				sidecar.Resources.ResourceRequests.Memory = sidecar.Resources.ResourceLimits.Memory | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		// controller adjusts default memory request and Scalyr sidecar container's request
 | ||||
| 		// as those do not need to be synced
 | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -112,12 +112,12 @@ func (c *Controller) initOperatorConfig() { | |||
| 
 | ||||
| 	if c.opConfig.SetMemoryRequestToLimit { | ||||
| 
 | ||||
| 		if c.opConfig.DefaultMemoryLimit > c.opConfig.DefaultMemoryRequest { | ||||
| 		if util.RequestIsSmallerThanLimit(c.opConfig.DefaultMemoryRequest, c.opConfig.DefaultMemoryLimit) { | ||||
| 			c.logger.Warningf("The default memory request of %v for Postgres containers is increased to match the default memory limit of %v.", c.opConfig.DefaultMemoryRequest, c.opConfig.DefaultMemoryLimit) | ||||
| 			c.opConfig.DefaultMemoryRequest = c.opConfig.DefaultMemoryLimit | ||||
| 		} | ||||
| 
 | ||||
| 		if c.opConfig.ScalyrMemoryLimit > c.opConfig.ScalyrMemoryRequest { | ||||
| 		if util.RequestIsSmallerThanLimit(c.opConfig.ScalyrMemoryRequest, c.opConfig.ScalyrMemoryLimit) { | ||||
| 			c.logger.Warningf("The memory request of %v for the Scalyr sidecar container is increased to match the memory limit of %v.", c.opConfig.ScalyrMemoryRequest, c.opConfig.ScalyrMemoryLimit) | ||||
| 			c.opConfig.ScalyrMemoryRequest = c.opConfig.ScalyrMemoryLimit | ||||
| 		} | ||||
|  |  | |||
|  | @ -55,6 +55,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur | |||
| 	result.DefaultMemoryRequest = fromCRD.PostgresPodResources.DefaultMemoryRequest | ||||
| 	result.DefaultCPULimit = fromCRD.PostgresPodResources.DefaultCPULimit | ||||
| 	result.DefaultMemoryLimit = fromCRD.PostgresPodResources.DefaultMemoryLimit | ||||
| 	result.SetMemoryRequestToLimit = fromCRD.SetMemoryRequestToLimit | ||||
| 
 | ||||
| 	result.ResourceCheckInterval = time.Duration(fromCRD.Timeouts.ResourceCheckInterval) | ||||
| 	result.ResourceCheckTimeout = time.Duration(fromCRD.Timeouts.ResourceCheckTimeout) | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ import ( | |||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/motomux/pretty" | ||||
| 	resource "k8s.io/apimachinery/pkg/api/resource" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 
 | ||||
| 	"github.com/zalando-incubator/postgres-operator/pkg/spec" | ||||
|  | @ -127,3 +128,19 @@ func Coalesce(val, defaultVal string) string { | |||
| 	} | ||||
| 	return val | ||||
| } | ||||
| 
 | ||||
| // RequestIsSmallerThanLimit
 | ||||
| func RequestIsSmallerThanLimit(requestStr, limitStr string) bool { | ||||
| 
 | ||||
| 	request, err := resource.ParseQuantity(requestStr) | ||||
| 	if err != nil { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	limit, err2 := resource.ParseQuantity(requestStr) | ||||
| 	if err2 != nil { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	return request.Cmp(limit) == -1 | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue