-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix patroni config updates #513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
29cfa27
3ca1a76
d4faf3f
7f5ca22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,7 +149,7 @@ func fillResourceList(spec acidv1.ResourceDescription, defaults acidv1.ResourceD | |
return requests, nil | ||
} | ||
|
||
func generateSpiloJSONConfiguration(pg *acidv1.PostgresqlParam, patroni *acidv1.Patroni, pamRoleName string, logger *logrus.Entry) (string, error) { | ||
func generateSpiloJSONConfiguration(pg *acidv1.PostgresqlParam, patroni *acidv1.Patroni, pamRoleName string, logger *logrus.Entry, isNewCluster bool, initialPatroniConfig string) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests also need to be updated pkg/cluster/k8sres_test.go:76:48: not enough arguments in call to generateSpiloJSONConfiguration
have (*"github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1".PostgresqlParam, *"github.com/zala
ndo/postgres-operator/pkg/apis/acid.zalan.do/v1".Patroni, string, *logrus.Entry)
want (*"github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1".PostgresqlParam, *"github.com/zala
ndo/postgres-operator/pkg/apis/acid.zalan.do/v1".Patroni, string, *logrus.Entry, bool, string) |
||
config := spiloConfiguration{} | ||
|
||
config.Bootstrap = pgBootstrap{} | ||
|
@@ -219,8 +219,27 @@ PatroniInitDBParams: | |
if patroni.TTL != 0 { | ||
config.Bootstrap.DCS.TTL = patroni.TTL | ||
} | ||
if patroni.Slots != nil { | ||
config.Bootstrap.DCS.Slots = patroni.Slots | ||
|
||
// The SPILO image is taking in account the 'Slots' settings **only** when bootstraping a new cluster. | ||
// Therefore, updating this value in the SPILO_CONFIGURATION of the statefulset is pointless, but still | ||
// required at cluster creation. | ||
if isNewCluster { | ||
if patroni.Slots != nil { | ||
config.Bootstrap.DCS.Slots = patroni.Slots | ||
} | ||
} else { | ||
oldestKnownPatroniCfg := acidv1.Patroni{} | ||
if initialPatroniConfig == "" { | ||
// when upgrading postgres-operator to this new version, existing StatefulSet won't have this annotation, so we're using the current specs | ||
oldestKnownPatroniCfg = *patroni | ||
} else { | ||
if err := json.Unmarshal([]byte(initialPatroniConfig), &oldestKnownPatroniCfg); err != nil { | ||
logger.Errorf("cannot decode initial patroni config from annotations: %s (%v)", err, initialPatroniConfig) | ||
return "", err | ||
} | ||
} | ||
|
||
config.Bootstrap.DCS.Slots = oldestKnownPatroniCfg.Slots | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but at this point the cluster already exists and bootstrap options have no effect. why are we resetting it again ? to get the same stateful set spec ? |
||
} | ||
|
||
config.PgLocalConfiguration = make(map[string]interface{}) | ||
|
@@ -784,7 +803,12 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State | |
func(i, j int) bool { return customPodEnvVarsList[i].Name < customPodEnvVarsList[j].Name }) | ||
} | ||
|
||
spiloConfiguration, err := generateSpiloJSONConfiguration(&spec.PostgresqlParam, &spec.Patroni, c.OpConfig.PamRoleName, c.logger) | ||
// c.Statefulset is not set when called from .createStatefulSet() | ||
initialPatroniConfig := "" | ||
if c.Statefulset != nil { | ||
initialPatroniConfig = c.Statefulset.ObjectMeta.Annotations[initialPatroniConfigAnnotationKey] | ||
} | ||
spiloConfiguration, err := generateSpiloJSONConfiguration(&spec.PostgresqlParam, &spec.Patroni, c.OpConfig.PamRoleName, c.logger, c.isNewCluster(), initialPatroniConfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not generate Spilo JSON configuration: %v", err) | ||
} | ||
|
@@ -875,6 +899,20 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State | |
|
||
numberOfInstances := c.getNumberOfInstances(spec) | ||
|
||
ann := map[string]string{rollingUpdateStatefulsetAnnotationKey: "false"} | ||
// Save the initial patroni config for later usage. | ||
// Note: if the annotation is empty (during the upgrade path for example), set it to the current specs. | ||
// see: issues#501 | ||
if c.isNewCluster() || initialPatroniConfig == "" { | ||
x, err := json.Marshal(spec.Patroni) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not JSON encode initial patroni config: %v", err) | ||
} | ||
ann[initialPatroniConfigAnnotationKey] = string(x) | ||
} else { | ||
ann[initialPatroniConfigAnnotationKey] = initialPatroniConfig | ||
} | ||
|
||
// the operator has domain-specific logic on how to do rolling updates of PG clusters | ||
// so we do not use default rolling updates implemented by stateful sets | ||
// that leaves the legacy "OnDelete" update strategy as the only option | ||
|
@@ -894,7 +932,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*v1beta1.State | |
Name: c.statefulSetName(), | ||
Namespace: c.Namespace, | ||
Labels: c.labelsSet(true), | ||
Annotations: map[string]string{rollingUpdateStatefulsetAnnotationKey: "false"}, | ||
Annotations: ann, | ||
}, | ||
Spec: v1beta1.StatefulSetSpec{ | ||
Replicas: &numberOfInstances, | ||
|
@@ -1242,11 +1280,11 @@ func (c *Cluster) generateCloneEnvironment(description *acidv1.CloneDescription) | |
c.logger.Info(msg, description.S3WalPath) | ||
|
||
envs := []v1.EnvVar{ | ||
v1.EnvVar{ | ||
{ | ||
Name: "CLONE_WAL_S3_BUCKET", | ||
Value: c.OpConfig.WALES3Bucket, | ||
}, | ||
v1.EnvVar{ | ||
{ | ||
Name: "CLONE_WAL_BUCKET_SCOPE_SUFFIX", | ||
Value: getBucketScopeSuffix(description.UID), | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the intention here to update Patroni config in DCS on every
Update
event even if the actual config did not change ?