From a1908d4c5971c4bb6e05a23056d640a930d3a731 Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Wed, 30 Mar 2022 16:21:40 +0200 Subject: [PATCH] extending unit tests --- docs/administrator.md | 6 +-- pkg/apis/acid.zalan.do/v1/postgresql_type.go | 2 +- pkg/cluster/k8sres.go | 1 - pkg/cluster/k8sres_test.go | 44 +++++++++++++++++--- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/docs/administrator.md b/docs/administrator.md index 050c12a76..cd4504c31 100644 --- a/docs/administrator.md +++ b/docs/administrator.md @@ -1087,9 +1087,9 @@ data: ### Standby clusters -The setup for [standby clusters](user.md#setting-up-a-standby-cluster) is very -similar to cloning. They can stream from a WAL archive (S3, GCS). Like with -cloning, if you are using [additional environment variables](#custom-pod-environment-variables) +The setup for [standby clusters](user.md#setting-up-a-standby-cluster) is +similar to cloning when they stream changes from a WAL archive (S3 or GCS). +If you are using [additional environment variables](#custom-pod-environment-variables) to access your backup location you have to copy those variables and prepend the `STANDBY_` prefix for Spilo to find the backups and WAL files to stream. diff --git a/pkg/apis/acid.zalan.do/v1/postgresql_type.go b/pkg/apis/acid.zalan.do/v1/postgresql_type.go index d0eacf5a4..b7c41be58 100644 --- a/pkg/apis/acid.zalan.do/v1/postgresql_type.go +++ b/pkg/apis/acid.zalan.do/v1/postgresql_type.go @@ -170,7 +170,7 @@ type Patroni struct { SynchronousNodeCount uint32 `json:"synchronous_node_count,omitempty" defaults:"1"` } -// StandbyDescription contains remote primary config or s3 wal path +// StandbyDescription contains remote primary config or s3/gs wal path type StandbyDescription struct { S3WalPath string `json:"s3_wal_path,omitempty"` GSWalPath string `json:"gs_wal_path,omitempty"` diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 322f836ba..8fe3b12f8 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -1963,7 +1963,6 @@ func (c *Cluster) generateStandbyEnvironment(description *acidv1.StandbyDescript 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 diff --git a/pkg/cluster/k8sres_test.go b/pkg/cluster/k8sres_test.go index b264c7f58..13e5aca67 100644 --- a/pkg/cluster/k8sres_test.go +++ b/pkg/cluster/k8sres_test.go @@ -538,6 +538,7 @@ func TestStandbyEnv(t *testing.T) { standbyOpts *acidv1.StandbyDescription env v1.EnvVar envPos int + envLen int }{ { subTest: "from custom s3 path", @@ -549,6 +550,7 @@ func TestStandbyEnv(t *testing.T) { Value: "s3://some/path/", }, envPos: 0, + envLen: 3, }, { subTest: "from custom gs path", @@ -556,15 +558,28 @@ func TestStandbyEnv(t *testing.T) { GSWalPath: "gs://some/path/", }, env: v1.EnvVar{ - Name: "STANDBY_WALE_GS_PREFIX", - Value: "gs://some/path/", + Name: "STANDBY_GOOGLE_APPLICATION_CREDENTIALS", + Value: "", }, - envPos: 0, + envPos: 1, + envLen: 4, + }, + { + subTest: "ignore gs path if s3 is set", + standbyOpts: &acidv1.StandbyDescription{ + S3WalPath: "s3://some/path/", + GSWalPath: "gs://some/path/", + }, + env: v1.EnvVar{ + Name: "STANDBY_METHOD", + Value: "STANDBY_WITH_WALE", + }, + envPos: 1, + envLen: 3, }, { subTest: "from remote primary", standbyOpts: &acidv1.StandbyDescription{ - S3WalPath: "s3://some/path/", StandbyHost: "remote-primary", }, env: v1.EnvVar{ @@ -572,11 +587,11 @@ func TestStandbyEnv(t *testing.T) { Value: "remote-primary", }, envPos: 0, + envLen: 1, }, { subTest: "from remote primary with port", standbyOpts: &acidv1.StandbyDescription{ - S3WalPath: "s3://some/path/", StandbyHost: "remote-primary", StandbyPort: "9876", }, @@ -585,6 +600,20 @@ func TestStandbyEnv(t *testing.T) { Value: "9876", }, envPos: 1, + envLen: 2, + }, + { + subTest: "from remote primary - ignore WAL path", + standbyOpts: &acidv1.StandbyDescription{ + GSWalPath: "gs://some/path/", + StandbyHost: "remote-primary", + }, + env: v1.EnvVar{ + Name: "STANDBY_HOST", + Value: "remote-primary", + }, + envPos: 0, + envLen: 1, }, } @@ -605,6 +634,11 @@ func TestStandbyEnv(t *testing.T) { t.Errorf("%s %s: Expected env value %s, have %s instead", testName, tt.subTest, tt.env.Value, env.Value) } + + if len(envs) != tt.envLen { + t.Errorf("%s %s: Expected number of env variables %d, have %d instead", + testName, tt.subTest, tt.envLen, len(envs)) + } } }