Skip to content
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

feat: add custom env to logical backup #1973

Closed
Closed
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
1 change: 1 addition & 0 deletions pkg/apis/acid.zalan.do/v1/postgresql_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type PostgresSpec struct {
ShmVolume *bool `json:"enableShmVolume,omitempty"`
EnableLogicalBackup bool `json:"enableLogicalBackup,omitempty"`
LogicalBackupSchedule string `json:"logicalBackupSchedule,omitempty"`
LogicalBackupEnv []v1.EnvVar `json:"logicalBackupEnv,omitempty"`
StandbyCluster *StandbyDescription `json:"standby,omitempty"`
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/cluster/k8sres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,11 @@ func (c *Cluster) generateLogicalBackupPodEnvVars() []v1.EnvVar {
envVars = append(envVars, v1.EnvVar{Name: "AWS_SECRET_ACCESS_KEY", Value: c.OpConfig.LogicalBackup.LogicalBackupS3SecretAccessKey})
}

// fetch logical-backup-specific variables that will override all subsequent global variables
if len(c.Spec.LogicalBackupEnv) > 0 {
envVars = appendEnvVars(envVars, c.Spec.LogicalBackupEnv...)
}

return envVars
}

Expand Down
74 changes: 74 additions & 0 deletions pkg/cluster/k8sres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,80 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
}
}

func TestGenerateLogicalBackupPodEnvVars(t *testing.T) {
testName := "TestGenerateLogicalBackupPodEnvVars"
tests := []struct {
subTest string
opConfig config.Config
expectedValues []ExpectedValue
pgsql acidv1.Postgresql
}{
{
subTest: "will set CLUSTER_NAME_LABEL env",
opConfig: config.Config{
Resources: config.Resources{
ClusterNameLabel: "test",
},
},
expectedValues: []ExpectedValue{
{
envIndex: 1,
envVarConstant: "CLUSTER_NAME_LABEL",
envVarValue: "test",
},
},
},
{
subTest: "will set CUSTOM_VALUE env by logicalBackupEnv",
pgsql: acidv1.Postgresql{
Spec: acidv1.PostgresSpec{
LogicalBackupEnv: []v1.EnvVar{
{
Name: "CUSTOM_VALUE",
Value: "my-scope-label",
},
},
},
},
expectedValues: []ExpectedValue{
{
envIndex: 17,
envVarConstant: "CUSTOM_VALUE",
envVarValue: "my-scope-label",
},
},
},
}

for _, tt := range tests {
c := newMockCluster(tt.opConfig)
c.Postgresql = tt.pgsql
actualEnvs := c.generateLogicalBackupPodEnvVars()

for _, ev := range tt.expectedValues {
env := actualEnvs[ev.envIndex]

if env.Name != ev.envVarConstant {
t.Errorf("%s %s: expected env name %s, have %s instead",
testName, tt.subTest, ev.envVarConstant, env.Name)
}

if ev.envVarValueRef != nil {
if !reflect.DeepEqual(env.ValueFrom, ev.envVarValueRef) {
t.Errorf("%s %s: expected env value reference %#v, have %#v instead",
testName, tt.subTest, ev.envVarValueRef, env.ValueFrom)
}
continue
}

if env.Value != ev.envVarValue {
t.Errorf("%s %s: expected env value %s, have %s instead",
testName, tt.subTest, ev.envVarValue, env.Value)
}
}
}
}

func TestGetNumberOfInstances(t *testing.T) {
tests := []struct {
subTest string
Expand Down
Loading