mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-03 03:23:45 +02:00
Deprecate old LB options, fix endpoint sync. (#287)
* Depreate old LB options, fix endpoint sync. - deprecate useLoadBalancer, replicaLoadBalancer from the manifest and enable_load_balancer from the operator configuration. The old operator configuration options become no-op with this commit. For the old manifest options, `useLoadBalancer` and `replicaLoadBalancer` are still consulted, but only in the absense of the new ones (enableMasterLoadBalancer and enableReplicaLoadBalancer). - Make sure the endpoint being created during the sync receives proper addresses subset. This is more critical for the replicas, as for the masters Patroni will normally re-create the endpoint before the operator. - Avoid creating the replica endpoint, since it will be created automatically by the corresponding service. - Update the README and unit tests. Code review by @mgomezch and @zerg-junior
This commit is contained in:
@@ -166,6 +166,17 @@ func (c *Controller) processEvent(event spec.ClusterEvent) {
|
||||
|
||||
defer c.curWorkerCluster.Store(event.WorkerID, nil)
|
||||
|
||||
if event.EventType == spec.EventAdd || event.EventType == spec.EventUpdate || event.EventType == spec.EventSync {
|
||||
// handle deprecated parameters by possibly assigning their values to the new ones.
|
||||
if event.OldSpec != nil {
|
||||
c.mergeDeprecatedPostgreSQLSpecParameters(&event.OldSpec.Spec)
|
||||
}
|
||||
if event.NewSpec != nil {
|
||||
c.mergeDeprecatedPostgreSQLSpecParameters(&event.NewSpec.Spec)
|
||||
}
|
||||
c.warnOnDeprecatedPostgreSQLSpecParameters(&event.NewSpec.Spec)
|
||||
}
|
||||
|
||||
switch event.EventType {
|
||||
case spec.EventAdd:
|
||||
if clusterFound {
|
||||
@@ -287,6 +298,46 @@ func (c *Controller) processClusterEventsQueue(idx int, stopCh <-chan struct{},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) warnOnDeprecatedPostgreSQLSpecParameters(spec *spec.PostgresSpec) {
|
||||
|
||||
deprecate := func(deprecated, replacement string) {
|
||||
c.logger.Warningf("Parameter %q is deprecated. Consider setting %q instead", deprecated, replacement)
|
||||
}
|
||||
|
||||
noeffect := func(param string, explanation string) {
|
||||
c.logger.Warningf("Parameter %q takes no effect. %s", param, explanation)
|
||||
}
|
||||
|
||||
if spec.UseLoadBalancer != nil {
|
||||
deprecate("useLoadBalancer", "enableMasterLoadBalancer")
|
||||
}
|
||||
if spec.ReplicaLoadBalancer != nil {
|
||||
deprecate("replicaLoadBalancer", "enableReplicaLoadBalancer")
|
||||
}
|
||||
|
||||
if len(spec.MaintenanceWindows) > 0 {
|
||||
noeffect("maintenanceWindows", "Not implemented.")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) mergeDeprecatedPostgreSQLSpecParameters(spec *spec.PostgresSpec) *spec.PostgresSpec {
|
||||
if spec.UseLoadBalancer != nil || spec.ReplicaLoadBalancer != nil {
|
||||
if spec.EnableReplicaLoadBalancer != nil || spec.EnableMasterLoadBalancer != nil {
|
||||
c.logger.Warnf("Both old and new load balancer options are present, ignoring old ones")
|
||||
} else {
|
||||
if spec.UseLoadBalancer != nil {
|
||||
spec.EnableMasterLoadBalancer = new(bool)
|
||||
*spec.EnableMasterLoadBalancer = *spec.UseLoadBalancer
|
||||
}
|
||||
if spec.ReplicaLoadBalancer != nil {
|
||||
spec.EnableReplicaLoadBalancer = new(bool)
|
||||
*spec.EnableReplicaLoadBalancer = *spec.ReplicaLoadBalancer
|
||||
}
|
||||
}
|
||||
}
|
||||
return spec
|
||||
}
|
||||
|
||||
func (c *Controller) queueClusterEvent(old, new *spec.Postgresql, eventType spec.EventType) {
|
||||
var (
|
||||
uid types.UID
|
||||
|
||||
Reference in New Issue
Block a user