enhance e2e test and improve log messages in sync

This commit is contained in:
Felix Kunde 2021-07-16 14:54:04 +02:00
parent ebc1d6ad9f
commit ce522ffeeb
2 changed files with 14 additions and 7 deletions

View File

@ -1431,13 +1431,14 @@ class EndToEndTestCase(unittest.TestCase):
masterPod = k8s.get_cluster_leader_pod() masterPod = k8s.get_cluster_leader_pod()
labels = 'application=spilo,cluster-name=acid-minimal-cluster,spilo-role=master' labels = 'application=spilo,cluster-name=acid-minimal-cluster,spilo-role=master'
creationTimestamp = masterPod.metadata.creation_timestamp creationTimestamp = masterPod.metadata.creation_timestamp
new_max_connections_value = "50"
# adjust max_connection # adjust max_connection
pg_patch_config = { pg_patch_config = {
"spec": { "spec": {
"postgresql": { "postgresql": {
"parameters": { "parameters": {
"max_connections": "50" "max_connections": new_max_connections_value
} }
}, },
"patroni": { "patroni": {
@ -1466,7 +1467,7 @@ class EndToEndTestCase(unittest.TestCase):
desired_parameters = pg_patch_config["spec"]["postgresql"]["parameters"] desired_parameters = pg_patch_config["spec"]["postgresql"]["parameters"]
effective_parameters = effective_config["postgresql"]["parameters"] effective_parameters = effective_config["postgresql"]["parameters"]
self.assertEqual(desired_parameters["max_connections"], effective_parameters["max_connections"], self.assertEqual(desired_parameters["max_connections"], effective_parameters["max_connections"],
"max_connectoins not updated") "max_connections not updated")
self.assertTrue(effective_config["slots"] is not None, "physical replication slot not added") self.assertTrue(effective_config["slots"] is not None, "physical replication slot not added")
self.assertEqual(desired_patroni["ttl"], effective_config["ttl"], self.assertEqual(desired_patroni["ttl"], effective_config["ttl"],
"ttl not updated") "ttl not updated")
@ -1479,8 +1480,14 @@ class EndToEndTestCase(unittest.TestCase):
return True return True
self.eventuallyTrue(compare_config, "Postgres config not applied") self.eventuallyTrue(compare_config, "Postgres config not applied")
pods = k8s.api.core_v1.list_namespaced_pod(
'default', label_selector=labels).items setting_query = """
SELECT setting
FROM pg_settings
WHERE name = 'max_connections';
"""
self.eventuallyEqual(lambda: self.query_database(masterPod.metadata.name, "postgres", setting_query)[0], new_max_connections_value,
"New max_connections setting not applied", 10, 5)
# make sure that pod wasn't recreated # make sure that pod wasn't recreated
self.assertEqual(creationTimestamp, masterPod.metadata.creation_timestamp, self.assertEqual(creationTimestamp, masterPod.metadata.creation_timestamp,

View File

@ -273,7 +273,7 @@ func (c *Cluster) syncStatefulSet() error {
pods, err := c.listPods() pods, err := c.listPods()
if err != nil { if err != nil {
c.logger.Infof("could not list pods of the statefulset: %v", err) c.logger.Warnf("could not list pods of the statefulset: %v", err)
} }
// NB: Be careful to consider the codepath that acts on podsRollingUpdateRequired before returning early. // NB: Be careful to consider the codepath that acts on podsRollingUpdateRequired before returning early.
@ -388,7 +388,7 @@ func (c *Cluster) syncStatefulSet() error {
// since those parameters require PostgreSQL restart. // since those parameters require PostgreSQL restart.
pods, err = c.listPods() pods, err = c.listPods()
if err != nil { if err != nil {
c.logger.Infof("could not list pods of the statefulset: %v", err) c.logger.Warnf("could not get list of pods to apply special PostgreSQL parameters only to be set via Patroni API: %v", err)
} }
for i, pod := range pods { for i, pod := range pods {
@ -407,7 +407,7 @@ func (c *Cluster) syncStatefulSet() error {
instanceRestartRequired, err = c.checkAndSetGlobalPostgreSQLConfiguration(&pod, config) instanceRestartRequired, err = c.checkAndSetGlobalPostgreSQLConfiguration(&pod, config)
if err != nil { if err != nil {
return fmt.Errorf("could not set cluster-wide PostgreSQL configuration options: %v", err) return fmt.Errorf("could not set PostgreSQL configuration options for pod %s: %v", podName, err)
} }
if instanceRestartRequired { if instanceRestartRequired {