diff --git a/README.md b/README.md index 44bbdf4f2..b12949b5b 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,8 @@ For instance, of a cluster manifest has 1 instance and the min_instances is set For any Postgresql/Spilo cluster an operator creates two separate k8s services: one for the master pod and one for replica pods. To expose these services to an outer network, one can attach load balancers to them by setting `enableMasterLoadBalancer` and/or `enableReplicaLoadBalancer` to `true` in the cluster manifest. In the case any of these variables is omitted from the manifest, the operator configmap's settings `enable_master_load_balancer` and `enable_replica_load_balancer` apply. Note that the operator settings affect all Postgresql services running in a namespace watched by the operator. +For backward compatibility with already configured clusters we maintain in a cluster manifest older parameter names, namely `useLoadBalancer` for enabling the master service's load balancer and `replicaLoadBalancer` for the replica service. If set, these params take precedence over the newer `enableMasterLoadBalancer` and `enableReplicaLoadBalancer`. Note that in older versions of the operator (before PR #258) `replicaLoadBalancer` was responsible for both creating the replica service and attaching an LB to it; now the service is always created (since k8s service typically is free in the cloud setting), and this param only attaches an LB (that typically costs money). + # Setup development environment The following steps guide you through the setup to work on the operator itself. diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 0fe7dfa58..4bc399481 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -675,18 +675,31 @@ func (c *Cluster) shouldCreateLoadBalancerForService(role PostgresRole, spec *sp case Replica: + // deprecated option takes priority for backward compatibility + if spec.ReplicaLoadBalancer != nil { + c.logger.Debugf("The Postgres manifest for the cluster %v sets the deprecated `replicaLoadBalancer` param. Consider using the `enableReplicaLoadBalancer` instead.", c.Name) + return *spec.ReplicaLoadBalancer + } + // if the value is explicitly set in a Postgresql manifest, follow this setting if spec.EnableReplicaLoadBalancer != nil { return *spec.EnableReplicaLoadBalancer } + // otherwise, follow the operator configuration return c.OpConfig.EnableReplicaLoadBalancer case Master: + if spec.UseLoadBalancer != nil { + c.logger.Debugf("The Postgres manifest for the cluster %v sets the deprecated `useLoadBalancer` param. Consider using the `enableMasterLoadBalancer` instead.", c.Name) + return *spec.UseLoadBalancer + } + if spec.EnableMasterLoadBalancer != nil { return *spec.EnableMasterLoadBalancer } + return c.OpConfig.EnableMasterLoadBalancer default: diff --git a/pkg/spec/postgresql.go b/pkg/spec/postgresql.go index a948f1698..1b47ca162 100644 --- a/pkg/spec/postgresql.go +++ b/pkg/spec/postgresql.go @@ -96,17 +96,24 @@ type PostgresSpec struct { TeamID string `json:"teamId"` AllowedSourceRanges []string `json:"allowedSourceRanges"` DockerImage string `json:"dockerImage,omitempty"` + // 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 the var evaluates to nil and the value is taken from the operator config - EnableMasterLoadBalancer *bool `json:"enableMasterLoadBalancer,omitempty"` - EnableReplicaLoadBalancer *bool `json:"enableReplicaLoadBalancer,omitempty"` - NumberOfInstances int32 `json:"numberOfInstances"` - Users map[string]UserFlags `json:"users"` - MaintenanceWindows []MaintenanceWindow `json:"maintenanceWindows,omitempty"` - Clone CloneDescription `json:"clone"` - ClusterName string `json:"-"` - Databases map[string]string `json:"databases,omitempty"` - Tolerations []v1.Toleration `json:"tolerations,omitempty"` + EnableMasterLoadBalancer *bool `json:"enableMasterLoadBalancer,omitempty"` + EnableReplicaLoadBalancer *bool `json:"enableReplicaLoadBalancer,omitempty"` + + // deprecated load balancer settings mantained for backward compatibility + // see "Load balancers" operator docs (PR #258) + UseLoadBalancer *bool `json:"useLoadBalancer,omitempty"` + ReplicaLoadBalancer *bool `json:"replicaLoadBalancer,omitempty"` + + NumberOfInstances int32 `json:"numberOfInstances"` + Users map[string]UserFlags `json:"users"` + MaintenanceWindows []MaintenanceWindow `json:"maintenanceWindows,omitempty"` + Clone CloneDescription `json:"clone"` + ClusterName string `json:"-"` + Databases map[string]string `json:"databases,omitempty"` + Tolerations []v1.Toleration `json:"tolerations,omitempty"` } // PostgresqlList defines a list of PostgreSQL clusters.