-
Notifications
You must be signed in to change notification settings - Fork 1k
add the possibility to create a standby cluster that streams from a remote primary #1544
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
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 |
---|---|---|
|
@@ -1111,9 +1111,10 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef | |
sort.Slice(customPodEnvVarsList, | ||
func(i, j int) bool { return customPodEnvVarsList[i].Name < customPodEnvVarsList[j].Name }) | ||
|
||
if spec.StandbyCluster != nil && spec.StandbyCluster.S3WalPath == "" && | ||
spec.StandbyCluster.GSWalPath == "" { | ||
return nil, fmt.Errorf("one of s3_wal_path or gs_wal_path must be set for standby cluster") | ||
if spec.StandbyCluster != nil { | ||
if spec.StandbyCluster.S3WalPath == "" && spec.StandbyCluster.GSWalPath == "" && spec.StandbyCluster.StandbyHost == "" { | ||
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. when one of the three options is required, I guess this extra if would be obsolete then |
||
return nil, fmt.Errorf("s3_wal_path, gs_wal_path and standby_host are empty for standby cluster") | ||
} | ||
} | ||
|
||
// backward compatible check for InitContainers | ||
|
@@ -1922,39 +1923,49 @@ func (c *Cluster) generateCloneEnvironment(description *acidv1.CloneDescription) | |
func (c *Cluster) generateStandbyEnvironment(description *acidv1.StandbyDescription) []v1.EnvVar { | ||
result := make([]v1.EnvVar, 0) | ||
|
||
if description.S3WalPath == "" && description.GSWalPath == "" { | ||
return nil | ||
} | ||
|
||
if description.S3WalPath != "" { | ||
// standby with S3, find out the bucket to setup standby | ||
msg := "standby from S3 bucket using custom parsed S3WalPath from the manifest %s " | ||
c.logger.Infof(msg, description.S3WalPath) | ||
|
||
if description.StandbyHost != "" { | ||
// standby from remote primary | ||
result = append(result, v1.EnvVar{ | ||
Name: "STANDBY_WALE_S3_PREFIX", | ||
Value: description.S3WalPath, | ||
Name: "STANDBY_HOST", | ||
Value: description.StandbyHost, | ||
}) | ||
} else if description.GSWalPath != "" { | ||
msg := "standby from GS bucket using custom parsed GSWalPath from the manifest %s " | ||
c.logger.Infof(msg, description.GSWalPath) | ||
if description.StandbyPort != "" { | ||
result = append(result, v1.EnvVar{ | ||
Name: "STANDBY_PORT", | ||
Value: description.StandbyPort, | ||
}) | ||
} | ||
} else { | ||
if description.S3WalPath != "" { | ||
// standby with S3, find out the bucket to setup standby | ||
msg := "Standby from S3 bucket using custom parsed S3WalPath from the manifest %s " | ||
c.logger.Infof(msg, description.S3WalPath) | ||
|
||
envs := []v1.EnvVar{ | ||
{ | ||
Name: "STANDBY_WALE_GS_PREFIX", | ||
Value: description.GSWalPath, | ||
}, | ||
{ | ||
Name: "STANDBY_GOOGLE_APPLICATION_CREDENTIALS", | ||
Value: c.OpConfig.GCPCredentials, | ||
}, | ||
result = append(result, v1.EnvVar{ | ||
Name: "STANDBY_WALE_S3_PREFIX", | ||
Value: description.S3WalPath, | ||
}) | ||
} else if description.GSWalPath != "" { | ||
msg := "Standby from GS bucket using custom parsed GSWalPath from the manifest %s " | ||
c.logger.Infof(msg, description.GSWalPath) | ||
|
||
envs := []v1.EnvVar{ | ||
{ | ||
Name: "STANDBY_WALE_GS_PREFIX", | ||
Value: description.GSWalPath, | ||
}, | ||
{ | ||
Name: "STANDBY_GOOGLE_APPLICATION_CREDENTIALS", | ||
Value: c.OpConfig.GCPCredentials, | ||
}, | ||
} | ||
result = append(result, envs...) | ||
} | ||
result = append(result, envs...) | ||
|
||
} | ||
result = append(result, v1.EnvVar{Name: "STANDBY_METHOD", Value: "STANDBY_WITH_WALE"}) | ||
machine424 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
result = append(result, v1.EnvVar{Name: "STANDBY_WAL_BUCKET_SCOPE_PREFIX", Value: ""}) | ||
|
||
result = append(result, v1.EnvVar{Name: "STANDBY_METHOD", Value: "STANDBY_WITH_WALE"}) | ||
result = append(result, v1.EnvVar{Name: "STANDBY_WAL_BUCKET_SCOPE_PREFIX", Value: ""}) | ||
} | ||
|
||
return result | ||
machine424 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -531,6 +531,83 @@ func TestCloneEnv(t *testing.T) { | |
} | ||
} | ||
|
||
func TestStandbyEnv(t *testing.T) { | ||
testName := "TestStandbyEnv" | ||
tests := []struct { | ||
subTest string | ||
standbyOpts *acidv1.StandbyDescription | ||
env v1.EnvVar | ||
envPos int | ||
}{ | ||
{ | ||
subTest: "from custom s3 path", | ||
standbyOpts: &acidv1.StandbyDescription{ | ||
S3WalPath: "s3://some/path/", | ||
}, | ||
env: v1.EnvVar{ | ||
Name: "STANDBY_WALE_S3_PREFIX", | ||
Value: "s3://some/path/", | ||
}, | ||
envPos: 0, | ||
}, | ||
{ | ||
subTest: "from custom gs path", | ||
standbyOpts: &acidv1.StandbyDescription{ | ||
GSWalPath: "gs://some/path/", | ||
}, | ||
env: v1.EnvVar{ | ||
Name: "STANDBY_WALE_GS_PREFIX", | ||
Value: "gs://some/path/", | ||
}, | ||
envPos: 0, | ||
}, | ||
{ | ||
subTest: "from remote primary", | ||
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. could add here that this also tests host taking precedence over wal path setting. Maybe make it an extra test with right comment. |
||
standbyOpts: &acidv1.StandbyDescription{ | ||
S3WalPath: "s3://some/path/", | ||
StandbyHost: "remote-primary", | ||
}, | ||
env: v1.EnvVar{ | ||
Name: "STANDBY_HOST", | ||
Value: "remote-primary", | ||
}, | ||
envPos: 0, | ||
}, | ||
{ | ||
subTest: "from remote primary with port", | ||
standbyOpts: &acidv1.StandbyDescription{ | ||
S3WalPath: "s3://some/path/", | ||
StandbyHost: "remote-primary", | ||
StandbyPort: "9876", | ||
}, | ||
env: v1.EnvVar{ | ||
Name: "STANDBY_PORT", | ||
Value: "9876", | ||
}, | ||
envPos: 1, | ||
}, | ||
} | ||
|
||
var cluster = New( | ||
Config{}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger, eventRecorder) | ||
|
||
for _, tt := range tests { | ||
envs := cluster.generateStandbyEnvironment(tt.standbyOpts) | ||
|
||
env := envs[tt.envPos] | ||
|
||
if env.Name != tt.env.Name { | ||
t.Errorf("%s %s: Expected env name %s, have %s instead", | ||
testName, tt.subTest, tt.env.Name, env.Name) | ||
} | ||
|
||
if env.Value != tt.env.Value { | ||
t.Errorf("%s %s: Expected env value %s, have %s instead", | ||
testName, tt.subTest, tt.env.Value, env.Value) | ||
} | ||
} | ||
} | ||
|
||
func TestExtractPgVersionFromBinPath(t *testing.T) { | ||
testName := "TestExtractPgVersionFromBinPath" | ||
tests := []struct { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Hm, it should not be required if host or gs_wal_path is set. We can work with
oneOf
in the CRD schema validation, I think.