Update the method for deciding about load balancers
This commit is contained in:
parent
0986e56226
commit
20f30d3739
|
|
@ -671,15 +671,27 @@ func (c *Cluster) generateSingleUserSecret(namespace string, pgUser spec.PgUser)
|
||||||
|
|
||||||
func (c *Cluster) shouldCreateLoadBalancerForService(role PostgresRole, spec *spec.PostgresSpec) bool {
|
func (c *Cluster) shouldCreateLoadBalancerForService(role PostgresRole, spec *spec.PostgresSpec) bool {
|
||||||
|
|
||||||
// handle LB for the replica service separately if ReplicaLoadBalancer is set in the Postgres manifest
|
switch role {
|
||||||
if role == Replica && spec.EnableReplicaLoadBalancer != nil {
|
|
||||||
return *spec.EnableReplicaLoadBalancer
|
|
||||||
}
|
|
||||||
|
|
||||||
// create a load balancer for the master service if either Postgres or operator manifests tell to do so
|
case Replica:
|
||||||
// if ReplicaLoadBalancer is unset and LB for master service is created, also create a balancer for replicas
|
|
||||||
return (spec.EnableMasterLoadBalancer != nil && *spec.EnableMasterLoadBalancer) ||
|
// if the value is explicitly set in a Postgresql manifest, follow this setting
|
||||||
(spec.EnableMasterLoadBalancer == nil && c.OpConfig.EnableMasterLoadBalancer)
|
if spec.EnableReplicaLoadBalancer != nil {
|
||||||
|
return *spec.EnableReplicaLoadBalancer
|
||||||
|
}
|
||||||
|
// otherwise, follow the operator configuration
|
||||||
|
return c.OpConfig.EnableReplicaLoadBalancer
|
||||||
|
|
||||||
|
case Master:
|
||||||
|
|
||||||
|
if spec.EnableMasterLoadBalancer != nil {
|
||||||
|
return *spec.EnableMasterLoadBalancer
|
||||||
|
}
|
||||||
|
return c.OpConfig.EnableMasterLoadBalancer
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("Unknown role %v", role))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,10 +96,9 @@ type PostgresSpec struct {
|
||||||
TeamID string `json:"teamId"`
|
TeamID string `json:"teamId"`
|
||||||
AllowedSourceRanges []string `json:"allowedSourceRanges"`
|
AllowedSourceRanges []string `json:"allowedSourceRanges"`
|
||||||
DockerImage string `json:"dockerImage,omitempty"`
|
DockerImage string `json:"dockerImage,omitempty"`
|
||||||
// EnableMasterLoadBalancer is a pointer, since it is important to know if that parameters is omitted from the Postgres manifest
|
// vars that enable load balancers are pointers because it is important to know if any of them is omitted from the Postgres manifest
|
||||||
// in that case EnableMasterLoadBalancer == nil and the value is taken from the operator config
|
// in that case the var evaluates to nil and the value is taken from the operator config
|
||||||
EnableMasterLoadBalancer *bool `json:"enableMasterLoadBalancer,omitempty"`
|
EnableMasterLoadBalancer *bool `json:"enableMasterLoadBalancer,omitempty"`
|
||||||
// if EnableReplicaLoadBalancer == nil (is unset), value of UseLoadBalancer determines if a balancer for replicas is created
|
|
||||||
EnableReplicaLoadBalancer *bool `json:"enableReplicaLoadBalancer,omitempty"`
|
EnableReplicaLoadBalancer *bool `json:"enableReplicaLoadBalancer,omitempty"`
|
||||||
NumberOfInstances int32 `json:"numberOfInstances"`
|
NumberOfInstances int32 `json:"numberOfInstances"`
|
||||||
Users map[string]UserFlags `json:"users"`
|
Users map[string]UserFlags `json:"users"`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue