Factories the restic environment variables
This commit is contained in:
parent
03c60a1ecb
commit
e2d61c230e
@ -132,7 +132,6 @@ func (r *BackupConfigurationReconciler) addSidecarContainer(backupConf *formolv1
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repo := &formolv1alpha1.Repo{}
|
|
||||||
sidecar := corev1.Container{
|
sidecar := corev1.Container{
|
||||||
Name: "backup",
|
Name: "backup",
|
||||||
Image: "desmo999r/formolcli:latest",
|
Image: "desmo999r/formolcli:latest",
|
||||||
@ -165,6 +164,7 @@ func (r *BackupConfigurationReconciler) addSidecarContainer(backupConf *formolv1
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gather information from the repo
|
// Gather information from the repo
|
||||||
|
repo := &formolv1alpha1.Repo{}
|
||||||
if err := r.Get(context.Background(), client.ObjectKey{
|
if err := r.Get(context.Background(), client.ObjectKey{
|
||||||
Namespace: backupConf.Namespace,
|
Namespace: backupConf.Namespace,
|
||||||
Name: backupConf.Spec.Repository.Name,
|
Name: backupConf.Spec.Repository.Name,
|
||||||
@ -172,31 +172,7 @@ func (r *BackupConfigurationReconciler) addSidecarContainer(backupConf *formolv1
|
|||||||
log.Error(err, "unable to get Repo from BackupConfiguration")
|
log.Error(err, "unable to get Repo from BackupConfiguration")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// S3 backing storage
|
sidecar.Env = append(sidecar.Env, formolutils.ConfigureResticEnvVar(backupConf, repo)...)
|
||||||
if (formolv1alpha1.S3{}) != repo.Spec.Backend.S3 {
|
|
||||||
url := "s3:http://" + repo.Spec.Backend.S3.Server + "/" + repo.Spec.Backend.S3.Bucket + "/" + target.Name
|
|
||||||
sidecar.Env = append(sidecar.Env, corev1.EnvVar{
|
|
||||||
Name: "RESTIC_REPOSITORY",
|
|
||||||
Value: url,
|
|
||||||
})
|
|
||||||
for _, key := range []string{
|
|
||||||
"AWS_ACCESS_KEY_ID",
|
|
||||||
"AWS_SECRET_ACCESS_KEY",
|
|
||||||
"RESTIC_PASSWORD",
|
|
||||||
} {
|
|
||||||
sidecar.Env = append(sidecar.Env, corev1.EnvVar{
|
|
||||||
Name: key,
|
|
||||||
ValueFrom: &corev1.EnvVarSource{
|
|
||||||
SecretKeyRef: &corev1.SecretKeySelector{
|
|
||||||
LocalObjectReference: corev1.LocalObjectReference{
|
|
||||||
Name: repo.Spec.RepositorySecrets,
|
|
||||||
},
|
|
||||||
Key: key,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, volumemount := range target.VolumeMounts {
|
for _, volumemount := range target.VolumeMounts {
|
||||||
log.V(1).Info("mounts", "volumemount", volumemount)
|
log.V(1).Info("mounts", "volumemount", volumemount)
|
||||||
|
|||||||
@ -1,5 +1,12 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
formolv1alpha1 "github.com/desmo999r/formol/api/v1alpha1"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func ContainsString(slice []string, s string) bool {
|
func ContainsString(slice []string, s string) bool {
|
||||||
for _, item := range slice {
|
for _, item := range slice {
|
||||||
if item == s {
|
if item == s {
|
||||||
@ -18,3 +25,33 @@ func RemoveString(slice []string, s string) (result []string) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConfigureResticEnvVar(backupConf *formolv1alpha1.BackupConfiguration, repo *formolv1alpha1.Repo) []corev1.EnvVar {
|
||||||
|
env := []corev1.EnvVar{}
|
||||||
|
// S3 backing storage
|
||||||
|
if (formolv1alpha1.S3{}) != repo.Spec.Backend.S3 {
|
||||||
|
url := fmt.Sprintf("s3:http://%s/%s/%s-%s", repo.Spec.Backend.S3.Server, repo.Spec.Backend.S3.Bucket, strings.ToUpper(backupConf.Namespace), strings.ToLower(backupConf.Name))
|
||||||
|
env = append(env, corev1.EnvVar{
|
||||||
|
Name: "RESTIC_REPOSITORY",
|
||||||
|
Value: url,
|
||||||
|
})
|
||||||
|
for _, key := range []string{
|
||||||
|
"AWS_ACCESS_KEY_ID",
|
||||||
|
"AWS_SECRET_ACCESS_KEY",
|
||||||
|
"RESTIC_PASSWORD",
|
||||||
|
} {
|
||||||
|
env = append(env, corev1.EnvVar{
|
||||||
|
Name: key,
|
||||||
|
ValueFrom: &corev1.EnvVarSource{
|
||||||
|
SecretKeyRef: &corev1.SecretKeySelector{
|
||||||
|
LocalObjectReference: corev1.LocalObjectReference{
|
||||||
|
Name: repo.Spec.RepositorySecrets,
|
||||||
|
},
|
||||||
|
Key: key,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return env
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user