Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,9 @@ func (c *Cluster) getPasswordForUser(username string) (string, error) {
}
c.multisiteClient = client
}
reqTimeoutCtx, _ := context.WithTimeout(context.TODO(), time.Duration(2)*time.Second)
reqTimeoutCtx, cancel := context.WithTimeout(context.TODO(), time.Duration(2)*time.Second)
defer cancel()

credentialsKey := fmt.Sprintf("/multisite/%s/%s/credentials/%s", c.Namespace, c.Name, username)
response, err := c.multisiteClient.Get(reqTimeoutCtx, credentialsKey)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/k8sres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,7 @@ func (c *Cluster) generatePodAnnotations(spec *cpov1.PostgresSpec) map[string]st
for k, v := range c.OpConfig.CustomPodAnnotations {
annotations[k] = v
}
if spec != nil || spec.PodAnnotations != nil {
if spec != nil && spec.PodAnnotations != nil {
for k, v := range spec.PodAnnotations {
annotations[k] = v
}
Expand Down
67 changes: 33 additions & 34 deletions pkg/cluster/k8sres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,15 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
tdeConfig: TDEConfig{
Enabled: false,
},
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},{"auth-local":"trust"}],"users":{"humans":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{}}}`,
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},"data-checksums",{"auth-local":"trust"},{"encoding":"UTF8"},{"locale":"en_US.UTF-8"},{"locale-provider":"icu"},{"icu-locale":"en_US"}],"users":null,"dcs":{}}}`,
},
{
subtest: "Patroni configured",
pgParam: &cpov1.PostgresqlParam{PgVersion: "17"},
patroni: &cpov1.Patroni{
InitDB: map[string]string{
"encoding": "UTF8",
"locale": "en_US.UTF-8",
"data-checksums": "true",
"encoding": "UTF8",
"locale": "en_US.UTF-8",
},
PgHba: []string{"hostssl all all 0.0.0.0/0 scram-sha-256", "host all all 0.0.0.0/0 scram-sha-256"},
TTL: 30,
Expand All @@ -114,7 +113,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
tdeConfig: TDEConfig{
Enabled: false,
},
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin","pg_hba":["hostssl all all 0.0.0.0/0 scram-sha-256","host all all 0.0.0.0/0 scram-sha-256"]},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},{"auth-local":"trust"},"data-checksums",{"encoding":"UTF8"},{"locale":"en_US.UTF-8"}],"users":{"humans":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"synchronous_mode":true,"synchronous_mode_strict":true,"synchronous_node_count":1,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}},"failsafe_mode":true}}}`,
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin","pg_hba":["hostssl all all 0.0.0.0/0 scram-sha-256","host all all 0.0.0.0/0 scram-sha-256"]},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},"data-checksums",{"auth-local":"trust"},{"encoding":"UTF8"},{"locale":"en_US.UTF-8"},{"locale-provider":"icu"},{"icu-locale":"en_US"}],"users":null,"dcs":{"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"synchronous_mode":true,"synchronous_mode_strict":true,"synchronous_node_count":1,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}},"failsafe_mode":true}}}`,
},
{
subtest: "Patroni failsafe_mode configured globally",
Expand All @@ -129,7 +128,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
tdeConfig: TDEConfig{
Enabled: false,
},
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},{"auth-local":"trust"}],"users":{"humans":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":true}}}`,
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},"data-checksums",{"auth-local":"trust"},{"encoding":"UTF8"},{"locale":"en_US.UTF-8"},{"locale-provider":"icu"},{"icu-locale":"en_US"}],"users":null,"dcs":{"failsafe_mode":true}}}`,
},
{
subtest: "Patroni failsafe_mode configured globally, disabled for cluster",
Expand All @@ -146,7 +145,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
tdeConfig: TDEConfig{
Enabled: false,
},
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},{"auth-local":"trust"}],"users":{"humans":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":false}}}`,
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},"data-checksums",{"auth-local":"trust"},{"encoding":"UTF8"},{"locale":"en_US.UTF-8"},{"locale-provider":"icu"},{"icu-locale":"en_US"}],"users":null,"dcs":{"failsafe_mode":false}}}`,
},
{
subtest: "Patroni failsafe_mode disabled globally, configured for cluster",
Expand All @@ -163,7 +162,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
tdeConfig: TDEConfig{
Enabled: false,
},
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},{"auth-local":"trust"}],"users":{"humans":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{"failsafe_mode":true}}}`,
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},"data-checksums",{"auth-local":"trust"},{"encoding":"UTF8"},{"locale":"en_US.UTF-8"},{"locale-provider":"icu"},{"icu-locale":"en_US"}],"users":null,"dcs":{"failsafe_mode":true}}}`,
},
{
subtest: "TDE enabled with 256 bits",
Expand All @@ -178,7 +177,7 @@ func TestGenerateSpiloJSONConfiguration(t *testing.T) {
Enabled: true,
KeyBits: "256",
},
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},{"auth-local":"trust"},{"encryption-key-command": "/tmp/tde.sh"},{"key-bits":"256"}],"users":{"humans":{"password":"","options":["CREATEDB","NOLOGIN"]}},"dcs":{}}}`,
result: `{"postgresql":{"bin_dir":"/usr/lib/postgresql/17/bin"},"bootstrap":{"initdb":[{"auth-host":"scram-sha-256"},"data-checksums",{"auth-local":"trust"},{"encoding":"UTF8"},{"locale":"en_US.UTF-8"},{"locale-provider":"icu"},{"icu-locale":"en_US"},{"encryption-key-command":"/tmp/tde.sh"},{"key-bits":"256"}],"users":null,"dcs":{}}}`,
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -530,67 +529,67 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
}
expectedSpiloWalPathCompat := []ExpectedValue{
{
envIndex: 12,
envIndex: 15,
envVarConstant: "ENABLE_WAL_PATH_COMPAT",
envVarValue: "true",
},
}
expectedValuesS3Bucket := []ExpectedValue{
{
envIndex: 15,
envIndex: 18,
envVarConstant: "WAL_S3_BUCKET",
envVarValue: "global-s3-bucket",
},
{
envIndex: 16,
envIndex: 19,
envVarConstant: "WAL_BUCKET_SCOPE_SUFFIX",
envVarValue: fmt.Sprintf("/%s", dummyUUID),
},
{
envIndex: 17,
envIndex: 20,
envVarConstant: "WAL_BUCKET_SCOPE_PREFIX",
envVarValue: "",
},
}
expectedValuesGCPCreds := []ExpectedValue{
{
envIndex: 15,
envIndex: 18,
envVarConstant: "WAL_GS_BUCKET",
envVarValue: "global-gs-bucket",
},
{
envIndex: 16,
envIndex: 19,
envVarConstant: "WAL_BUCKET_SCOPE_SUFFIX",
envVarValue: fmt.Sprintf("/%s", dummyUUID),
},
{
envIndex: 17,
envIndex: 20,
envVarConstant: "WAL_BUCKET_SCOPE_PREFIX",
envVarValue: "",
},
{
envIndex: 18,
envIndex: 21,
envVarConstant: "GOOGLE_APPLICATION_CREDENTIALS",
envVarValue: "some-path-to-credentials",
},
}
expectedS3BucketConfigMap := []ExpectedValue{
{
envIndex: 17,
envIndex: 20,
envVarConstant: "wal_s3_bucket",
envVarValue: "global-s3-bucket-configmap",
},
}
expectedCustomS3BucketSpec := []ExpectedValue{
{
envIndex: 15,
envIndex: 18,
envVarConstant: "WAL_S3_BUCKET",
envVarValue: "custom-s3-bucket",
},
}
expectedCustomVariableSecret := []ExpectedValue{
{
envIndex: 16,
envIndex: 19,
envVarConstant: "custom_variable",
envVarValueRef: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
Expand All @@ -604,72 +603,72 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
}
expectedCustomVariableConfigMap := []ExpectedValue{
{
envIndex: 16,
envIndex: 19,
envVarConstant: "custom_variable",
envVarValue: "configmap-test",
},
}
expectedCustomVariableSpec := []ExpectedValue{
{
envIndex: 15,
envIndex: 18,
envVarConstant: "CUSTOM_VARIABLE",
envVarValue: "spec-env-test",
},
}
expectedCloneEnvSpec := []ExpectedValue{
{
envIndex: 16,
envIndex: 19,
envVarConstant: "CLONE_WALE_S3_PREFIX",
envVarValue: "s3://another-bucket",
},
{
envIndex: 19,
envIndex: 22,
envVarConstant: "CLONE_WAL_BUCKET_SCOPE_PREFIX",
envVarValue: "",
},
{
envIndex: 20,
envIndex: 23,
envVarConstant: "CLONE_AWS_ENDPOINT",
envVarValue: "s3.eu-central-1.amazonaws.com",
},
}
expectedCloneEnvSpecEnv := []ExpectedValue{
{
envIndex: 15,
envIndex: 18,
envVarConstant: "CLONE_WAL_BUCKET_SCOPE_PREFIX",
envVarValue: "test-cluster",
},
{
envIndex: 17,
envIndex: 20,
envVarConstant: "CLONE_WALE_S3_PREFIX",
envVarValue: "s3://another-bucket",
},
{
envIndex: 21,
envIndex: 24,
envVarConstant: "CLONE_AWS_ENDPOINT",
envVarValue: "s3.eu-central-1.amazonaws.com",
},
}
expectedCloneEnvConfigMap := []ExpectedValue{
{
envIndex: 16,
envIndex: 19,
envVarConstant: "CLONE_WAL_S3_BUCKET",
envVarValue: "global-s3-bucket",
},
{
envIndex: 17,
envIndex: 20,
envVarConstant: "CLONE_WAL_BUCKET_SCOPE_SUFFIX",
envVarValue: fmt.Sprintf("/%s", dummyUUID),
},
{
envIndex: 21,
envIndex: 24,
envVarConstant: "clone_aws_endpoint",
envVarValue: "s3.eu-west-1.amazonaws.com",
},
}
expectedCloneEnvSecret := []ExpectedValue{
{
envIndex: 21,
envIndex: 24,
envVarConstant: "clone_aws_access_key_id",
envVarValueRef: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
Expand All @@ -683,12 +682,12 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
}
expectedStandbyEnvSecret := []ExpectedValue{
{
envIndex: 15,
envIndex: 18,
envVarConstant: "STANDBY_WALE_GS_PREFIX",
envVarValue: "gs://some/path/",
},
{
envIndex: 20,
envIndex: 23,
envVarConstant: "standby_google_application_credentials",
envVarValueRef: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ func (c *Cluster) updateSecret(
}

if updateSecret {
c.logger.Debugln("%s", updateSecretMsg)
c.logger.Debugf("%s", updateSecretMsg)
if _, err = c.KubeClient.Secrets(secret.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{}); err != nil {
return fmt.Errorf("could not update secret %s: %v", secretName, err)
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/cluster/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func logNiceDiff(log *logrus.Entry, old, new interface{}) {
nice := nicediff.Diff(string(o), string(n), true)
for _, s := range strings.Split(nice, "\n") {
// " is not needed in the value to understand
log.Debugf(strings.ReplaceAll(s, "\"", ""))
log.Debugf("%s", strings.ReplaceAll(s, "\"", ""))
}
}

Expand Down Expand Up @@ -512,8 +512,6 @@ func (c *Cluster) waitForPrimaryLoadBalancerIp() error {
}
return len(svc.Status.LoadBalancer.Ingress) > 0, nil
})

return nil
}

func (c *Cluster) getPrimaryLoadBalancerIp() (string, error) {
Expand Down
Loading