Add pooler for replica
This commit is contained in:
		
							parent
							
								
									248ce9fc78
								
							
						
					
					
						commit
						3a906aba93
					
				| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
apiVersion: "acid.zalan.do/v1"
 | 
					apiVersion: "acid.zalan.do/v1"
 | 
				
			||||||
kind: postgresql
 | 
					kind: postgresql
 | 
				
			||||||
metadata:
 | 
					metadata:
 | 
				
			||||||
  name: acid-test-cluster
 | 
					  name: acid-test-cluster2
 | 
				
			||||||
#  labels:
 | 
					#  labels:
 | 
				
			||||||
#    environment: demo
 | 
					#    environment: demo
 | 
				
			||||||
#  annotations:
 | 
					#  annotations:
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,8 @@ spec:
 | 
				
			||||||
    - createdb
 | 
					    - createdb
 | 
				
			||||||
  enableMasterLoadBalancer: false
 | 
					  enableMasterLoadBalancer: false
 | 
				
			||||||
  enableReplicaLoadBalancer: false
 | 
					  enableReplicaLoadBalancer: false
 | 
				
			||||||
#  enableConnectionPooler: true  # not needed when connectionPooler section is present (see below)
 | 
					  #enableConnectionPooler: true  # not needed when connectionPooler section is present (see below)
 | 
				
			||||||
 | 
					  enableReplicaConnectionPooler: true # set to enable connectionPooler for replica endpoints
 | 
				
			||||||
  allowedSourceRanges:  # load balancers' source ranges for both master and replica services
 | 
					  allowedSourceRanges:  # load balancers' source ranges for both master and replica services
 | 
				
			||||||
  - 127.0.0.1/32
 | 
					  - 127.0.0.1/32
 | 
				
			||||||
  databases:
 | 
					  databases:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -262,6 +262,9 @@ var PostgresCRDResourceValidation = apiextv1beta1.CustomResourceValidation{
 | 
				
			||||||
					"enableConnectionPooler": {
 | 
										"enableConnectionPooler": {
 | 
				
			||||||
						Type: "boolean",
 | 
											Type: "boolean",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
 | 
										"enableReplicaConnectionPooler": {
 | 
				
			||||||
 | 
											Type: "boolean",
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
					"enableLogicalBackup": {
 | 
										"enableLogicalBackup": {
 | 
				
			||||||
						Type: "boolean",
 | 
											Type: "boolean",
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,7 @@ type PostgresSpec struct {
 | 
				
			||||||
	Resources       `json:"resources,omitempty"`
 | 
						Resources       `json:"resources,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	EnableConnectionPooler        *bool             `json:"enableConnectionPooler,omitempty"`
 | 
						EnableConnectionPooler        *bool             `json:"enableConnectionPooler,omitempty"`
 | 
				
			||||||
 | 
						EnableReplicaConnectionPooler *bool             `json:"enableReplicaConnectionPooler,omitempty"`
 | 
				
			||||||
	ConnectionPooler              *ConnectionPooler `json:"connectionPooler,omitempty"`
 | 
						ConnectionPooler              *ConnectionPooler `json:"connectionPooler,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	TeamID      string `json:"teamId"`
 | 
						TeamID      string `json:"teamId"`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2085,9 +2085,13 @@ func (c *Cluster) getConnectionPoolerEnvVars(spec *acidv1.PostgresSpec) []v1.Env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return []v1.EnvVar{
 | 
						return []v1.EnvVar{
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Name:  "CONNECTION_POOLER_PORT",
 | 
								Name:  "CONNECTION_POOLER_MASTER_PORT",
 | 
				
			||||||
			Value: fmt.Sprint(pgPort),
 | 
								Value: fmt.Sprint(pgPort),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Name:  "CONNECTION_POOLER_REPLICA_PORT",
 | 
				
			||||||
 | 
								Value: fmt.Sprint(5433),
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Name:  "CONNECTION_POOLER_MODE",
 | 
								Name:  "CONNECTION_POOLER_MODE",
 | 
				
			||||||
			Value: effectiveMode,
 | 
								Value: effectiveMode,
 | 
				
			||||||
| 
						 | 
					@ -2304,8 +2308,10 @@ func (c *Cluster) generateConnectionPoolerService(spec *acidv1.PostgresSpec) *v1
 | 
				
			||||||
	if spec.ConnectionPooler == nil {
 | 
						if spec.ConnectionPooler == nil {
 | 
				
			||||||
		spec.ConnectionPooler = &acidv1.ConnectionPooler{}
 | 
							spec.ConnectionPooler = &acidv1.ConnectionPooler{}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						var serviceSpec = v1.ServiceSpec{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	serviceSpec := v1.ServiceSpec{
 | 
						if *spec.EnableReplicaConnectionPooler == false {
 | 
				
			||||||
 | 
							serviceSpec = v1.ServiceSpec{
 | 
				
			||||||
			Ports: []v1.ServicePort{
 | 
								Ports: []v1.ServicePort{
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Name:       c.connectionPoolerName(),
 | 
										Name:       c.connectionPoolerName(),
 | 
				
			||||||
| 
						 | 
					@ -2318,6 +2324,26 @@ func (c *Cluster) generateConnectionPoolerService(spec *acidv1.PostgresSpec) *v1
 | 
				
			||||||
				"connection-pooler": c.connectionPoolerName(),
 | 
									"connection-pooler": c.connectionPoolerName(),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							serviceSpec = v1.ServiceSpec{
 | 
				
			||||||
 | 
								Ports: []v1.ServicePort{
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										Name:       c.connectionPoolerName(),
 | 
				
			||||||
 | 
										Port:       pgPort,
 | 
				
			||||||
 | 
										TargetPort: intstr.IntOrString{StrVal: c.servicePort(Master)},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										Name:       c.connectionPoolerName() + "-repl",
 | 
				
			||||||
 | 
										Port:       5433,
 | 
				
			||||||
 | 
										TargetPort: intstr.IntOrString{StrVal: c.servicePort(Replica)},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								Type: v1.ServiceTypeClusterIP,
 | 
				
			||||||
 | 
								Selector: map[string]string{
 | 
				
			||||||
 | 
									"connection-pooler": c.connectionPoolerName(),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	service := &v1.Service{
 | 
						service := &v1.Service{
 | 
				
			||||||
		ObjectMeta: metav1.ObjectMeta{
 | 
							ObjectMeta: metav1.ObjectMeta{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue