Skip to content

Commit

Permalink
Merge pull request #147 from mweibel/fix-backend-restic-pw
Browse files Browse the repository at this point in the history
fix: only add ResticPassword if set
  • Loading branch information
Kidswiss authored Nov 27, 2020
2 parents 89672df + 07e2487 commit d799c5c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
6 changes: 4 additions & 2 deletions api/v1alpha1/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ type Backend struct {
func (b *Backend) GetCredentialEnv() map[string]*corev1.EnvVarSource {
vars := make(map[string]*corev1.EnvVarSource)

vars[constants.ResticPasswordEnvName] = &corev1.EnvVarSource{
SecretKeyRef: b.RepoPasswordSecretRef,
if b.RepoPasswordSecretRef != nil {
vars[constants.ResticPasswordEnvName] = &corev1.EnvVarSource{
SecretKeyRef: b.RepoPasswordSecretRef,
}
}

if b.Azure != nil {
Expand Down
1 change: 0 additions & 1 deletion executor/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func DefaultEnv(namespace string) EnvVarConverter {
defaults := NewEnvVarConverter()

defaults.SetString("STATS_URL", constants.GetGlobalStatsURL())
defaults.SetString(constants.ResticPasswordEnvName, constants.GetGlobalRepoPassword())
defaults.SetString(constants.ResticRepositoryEnvName, fmt.Sprintf("s3:%s/%s", constants.GetGlobalS3Endpoint(), constants.GetGlobalS3Bucket()))
defaults.SetString(constants.ResticPasswordEnvName, constants.GetGlobalRepoPassword())
defaults.SetString(constants.AwsAccessKeyIDEnvName, constants.GetGlobalAccessKey())
Expand Down
52 changes: 52 additions & 0 deletions executor/generic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package executor

import (
"testing"

corev1 "k8s.io/api/core/v1"
)

func TestEnvVarConverter_Merge(t *testing.T) {
vars := NewEnvVarConverter()
vars.SetString("nooverridestr", "original")
vars.SetEnvVarSource("nooverridesrc", &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: "original"}})
vars.SetString("nomergestr", "original")
vars.SetEnvVarSource("nomergesource", &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: "original"}})

src := NewEnvVarConverter()
src.SetString("nooverridestr", "updated")
src.SetEnvVarSource("nooverridestr", &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: "updated"}})
src.SetEnvVarSource("nooverridesrc", &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: "updated"}})
src.SetString("newstr", "original")
src.SetEnvVarSource("newsource", &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{Key: "original"}})

if err := vars.Merge(src); err != nil {
t.Errorf("unable to merge: %v", err)
}

v := vars.Vars

if *v["nooverridestr"].stringEnv != "original" {
t.Error("nooverridestr should not have been updated.")
}
if v["nooverridestr"].envVarSource != nil {
t.Error("nooverridestr should not have been updated.")
}
if v["nooverridesrc"].envVarSource.SecretKeyRef.Key != "original" {
t.Error("nooverridesrc should not have been updated.")
}

if *v["nomergestr"].stringEnv != "original" {
t.Error("nomergestr should not have been updated.")
}
if v["nomergesource"].envVarSource.SecretKeyRef.Key != "original" {
t.Error("nomergesource should not have been updated.")
}

if *v["newstr"].stringEnv != "original" {
t.Error("newstr should have been merged in.")
}
if v["newsource"].envVarSource.SecretKeyRef.Key != "original" {
t.Error("nomergesource should have been merged in.")
}
}

0 comments on commit d799c5c

Please sign in to comment.