From c7427d93098a009e6892180f866b64f0a4719533 Mon Sep 17 00:00:00 2001 From: Arthur Le Roux Date: Fri, 15 Dec 2023 11:02:47 +0100 Subject: [PATCH 1/2] feat(connection_pooler): add priorityclassname Signed-off-by: Arthur Le Roux --- charts/postgres-operator/crds/postgresqls.yaml | 2 ++ manifests/complete-postgres-manifest.yaml | 1 + manifests/configmap.yaml | 1 + manifests/postgresql.crd.yaml | 2 ++ pkg/apis/acid.zalan.do/v1/crds.go | 4 ++++ pkg/apis/acid.zalan.do/v1/operator_configuration_type.go | 1 + pkg/apis/acid.zalan.do/v1/postgresql_type.go | 1 + pkg/cluster/connection_pooler.go | 5 +++++ pkg/controller/operator_config.go | 2 ++ pkg/util/config/config.go | 1 + 10 files changed, 20 insertions(+) diff --git a/charts/postgres-operator/crds/postgresqls.yaml b/charts/postgres-operator/crds/postgresqls.yaml index c9fd30f87..1343b3911 100644 --- a/charts/postgres-operator/crds/postgresqls.yaml +++ b/charts/postgres-operator/crds/postgresqls.yaml @@ -148,6 +148,8 @@ spec: numberOfInstances: type: integer minimum: 1 + priorityClassName: + type: string resources: type: object properties: diff --git a/manifests/complete-postgres-manifest.yaml b/manifests/complete-postgres-manifest.yaml index aa94dab23..33a0e7fec 100644 --- a/manifests/complete-postgres-manifest.yaml +++ b/manifests/complete-postgres-manifest.yaml @@ -158,6 +158,7 @@ spec: # schema: "pooler" # user: "pooler" # maxDBConnections: 60 +# priorityClassName: "" # resources: # requests: # cpu: 300m diff --git a/manifests/configmap.yaml b/manifests/configmap.yaml index 3bba4c50e..edf949530 100644 --- a/manifests/configmap.yaml +++ b/manifests/configmap.yaml @@ -23,6 +23,7 @@ data: # connection_pooler_number_of_instances: 2 # connection_pooler_schema: "pooler" # connection_pooler_user: "pooler" + # connection_pooler_priority_class_name: "" crd_categories: "all" # custom_service_annotations: "keyx:valuez,keya:valuea" # custom_pod_annotations: "keya:valuea,keyb:valueb" diff --git a/manifests/postgresql.crd.yaml b/manifests/postgresql.crd.yaml index 5f5b6ff09..059bf9385 100644 --- a/manifests/postgresql.crd.yaml +++ b/manifests/postgresql.crd.yaml @@ -146,6 +146,8 @@ spec: numberOfInstances: type: integer minimum: 1 + priorityClassName: + type: string resources: type: object properties: diff --git a/pkg/apis/acid.zalan.do/v1/crds.go b/pkg/apis/acid.zalan.do/v1/crds.go index 3d9f4f08d..dbdd2a274 100644 --- a/pkg/apis/acid.zalan.do/v1/crds.go +++ b/pkg/apis/acid.zalan.do/v1/crds.go @@ -237,6 +237,10 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{ Type: "integer", Minimum: &min1, }, + + "priorityClassName": { + Type: "string", + }, "resources": { Type: "object", Properties: map[string]apiextv1.JSONSchemaProps{ diff --git a/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go b/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go index afc22cb5d..67e4e914d 100644 --- a/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go +++ b/pkg/apis/acid.zalan.do/v1/operator_configuration_type.go @@ -214,6 +214,7 @@ type ConnectionPoolerConfiguration struct { DefaultMemoryRequest string `json:"connection_pooler_default_memory_request,omitempty"` DefaultCPULimit string `json:"connection_pooler_default_cpu_limit,omitempty"` DefaultMemoryLimit string `json:"connection_pooler_default_memory_limit,omitempty"` + PriorityClassName string `json:"connection_pooler_priority_class_name,omitempty"` } // OperatorLogicalBackupConfiguration defines configuration for logical backup diff --git a/pkg/apis/acid.zalan.do/v1/postgresql_type.go b/pkg/apis/acid.zalan.do/v1/postgresql_type.go index 3504d615d..c3a32878b 100644 --- a/pkg/apis/acid.zalan.do/v1/postgresql_type.go +++ b/pkg/apis/acid.zalan.do/v1/postgresql_type.go @@ -241,6 +241,7 @@ type ConnectionPooler struct { Mode string `json:"mode,omitempty"` DockerImage string `json:"dockerImage,omitempty"` MaxDBConnections *int32 `json:"maxDBConnections,omitempty"` + PriorityClassName string `json:"priorityClassName,omitempty"` *Resources `json:"resources,omitempty"` } diff --git a/pkg/cluster/connection_pooler.go b/pkg/cluster/connection_pooler.go index c551f0a8f..8923dfc0b 100644 --- a/pkg/cluster/connection_pooler.go +++ b/pkg/cluster/connection_pooler.go @@ -394,6 +394,10 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) ( securityContext.FSGroup = effectiveFSGroup } + effectivePriorityClassName := util.Coalesce( + connectionPoolerSpec.PriorityClassName, + c.OpConfig.ConnectionPooler.ConnectionPoolerPriorityClassName) + podTemplate := &v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: c.connectionPoolerLabels(role, true).MatchLabels, @@ -407,6 +411,7 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) ( Volumes: poolerVolumes, SecurityContext: &securityContext, ServiceAccountName: c.OpConfig.PodServiceAccountName, + PriorityClassName: effectivePriorityClassName, }, } diff --git a/pkg/controller/operator_config.go b/pkg/controller/operator_config.go index 36c30d318..cef56bd9b 100644 --- a/pkg/controller/operator_config.go +++ b/pkg/controller/operator_config.go @@ -282,5 +282,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur fromCRD.ConnectionPooler.MaxDBConnections, k8sutil.Int32ToPointer(constants.ConnectionPoolerMaxDBConnections)) + result.ConnectionPooler.ConnectionPoolerPriorityClassName = fromCRD.ConnectionPooler.PriorityClassName + return result } diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 7553bdbf9..f3fef1f59 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -158,6 +158,7 @@ type ConnectionPooler struct { ConnectionPoolerDefaultMemoryRequest string `name:"connection_pooler_default_memory_request" default:"100Mi"` ConnectionPoolerDefaultCPULimit string `name:"connection_pooler_default_cpu_limit" default:"1"` ConnectionPoolerDefaultMemoryLimit string `name:"connection_pooler_default_memory_limit" default:"100Mi"` + ConnectionPoolerPriorityClassName string `name:"connection_pooler_priority_class_name"` } // Config describes operator config From 23da7e9721817e8d5b8b61192c33b31b491b9be7 Mon Sep 17 00:00:00 2001 From: Arthur Le Roux Date: Fri, 16 Feb 2024 11:31:59 +0100 Subject: [PATCH 2/2] fix(config): fix typo --- pkg/util/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 1b9e8db44..fd2358e4d 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -159,7 +159,7 @@ type ConnectionPooler struct { ConnectionPoolerDefaultMemoryRequest string `name:"connection_pooler_default_memory_request"` ConnectionPoolerDefaultCPULimit string `name:"connection_pooler_default_cpu_limit"` ConnectionPoolerDefaultMemoryLimit string `name:"connection_pooler_default_memory_limit"` - ConnectionPoolerPriorityClassName string `name:"connection_pooler_priority_class_name"` + ConnectionPoolerPriorityClassName string `name:"connection_pooler_priority_class_name"` } // Config describes operator config