Compare commits
2 Commits
6c4d1a749c
...
55f3dc8dff
| Author | SHA1 | Date | |
|---|---|---|---|
| 55f3dc8dff | |||
| e80871346e |
@ -23,6 +23,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
RESTIC_REPOSITORY = "RESTIC_REPOSITORY"
|
||||||
|
RESTIC_PASSWORD = "RESTIC_PASSWORD"
|
||||||
|
AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID"
|
||||||
|
AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY"
|
||||||
|
)
|
||||||
|
|
||||||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
|
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
|
||||||
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
|
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
|
||||||
type S3 struct {
|
type S3 struct {
|
||||||
@ -83,13 +90,13 @@ func (repo *Repo) GetResticEnv(backupConf BackupConfiguration) []corev1.EnvVar {
|
|||||||
strings.ToUpper(backupConf.Namespace),
|
strings.ToUpper(backupConf.Namespace),
|
||||||
strings.ToLower(backupConf.Name))
|
strings.ToLower(backupConf.Name))
|
||||||
env = append(env, corev1.EnvVar{
|
env = append(env, corev1.EnvVar{
|
||||||
Name: "RESTIC_REPOSITORY",
|
Name: RESTIC_REPOSITORY,
|
||||||
Value: url,
|
Value: url,
|
||||||
})
|
})
|
||||||
for _, key := range []string{
|
for _, key := range []string{
|
||||||
"AWS_ACCESS_KEY_ID",
|
AWS_ACCESS_KEY_ID,
|
||||||
"AWS_SECRET_ACCESS_KEY",
|
AWS_SECRET_ACCESS_KEY,
|
||||||
"RESTIC_PASSWORD",
|
RESTIC_PASSWORD,
|
||||||
} {
|
} {
|
||||||
env = append(env, corev1.EnvVar{
|
env = append(env, corev1.EnvVar{
|
||||||
Name: key,
|
Name: key,
|
||||||
|
|||||||
@ -93,11 +93,20 @@ func (r *BackupConfigurationReconciler) Reconcile(ctx context.Context, req ctrl.
|
|||||||
backupConf.Status.ActiveCronJob = true
|
backupConf.Status.ActiveCronJob = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.AddSidecar(backupConf); err != nil {
|
for _, target := range backupConf.Spec.Targets {
|
||||||
r.Log.Error(err, "unable to add sidecar container")
|
switch target.BackupType {
|
||||||
|
case formolv1alpha1.OnlineKind:
|
||||||
|
// TODO: add a sidecar to the pod with the target.Containers[].Paths mounted
|
||||||
|
if err := r.AddOnlineSidecar(backupConf, target); err != nil {
|
||||||
|
r.Log.Error(err, "unable to add online sidecar")
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
} else {
|
}
|
||||||
backupConf.Status.ActiveSidecar = true
|
backupConf.Status.ActiveSidecar = true
|
||||||
|
case formolv1alpha1.JobKind:
|
||||||
|
// TODO: add a sidecar to the pod with a shared
|
||||||
|
case formolv1alpha1.SnapshotKind:
|
||||||
|
// TOD: add a sidecar to run the steps
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.Status().Update(ctx, &backupConf); err != nil {
|
if err := r.Status().Update(ctx, &backupConf); err != nil {
|
||||||
|
|||||||
@ -178,11 +178,7 @@ func (r *BackupConfigurationReconciler) DeleteSidecar(backupConf formolv1alpha1.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BackupConfigurationReconciler) AddSidecar(backupConf formolv1alpha1.BackupConfiguration) error {
|
func (r *BackupConfigurationReconciler) AddOnlineSidecar(backupConf formolv1alpha1.BackupConfiguration, target formolv1alpha1.Target) error {
|
||||||
// Go through all the 'targets'
|
|
||||||
// the backupType: Online needs a sidecar container for every single listed 'container'
|
|
||||||
// if the backupType is something else than Online, the 'container' will still need a sidecar
|
|
||||||
// if it has 'steps'
|
|
||||||
addTags := func(sideCar *corev1.Container, podSpec *corev1.PodSpec, target formolv1alpha1.Target) bool {
|
addTags := func(sideCar *corev1.Container, podSpec *corev1.PodSpec, target formolv1alpha1.Target) bool {
|
||||||
for i, container := range podSpec.Containers {
|
for i, container := range podSpec.Containers {
|
||||||
if container.Name == formolv1alpha1.SIDECARCONTAINER_NAME {
|
if container.Name == formolv1alpha1.SIDECARCONTAINER_NAME {
|
||||||
@ -217,17 +213,6 @@ func (r *BackupConfigurationReconciler) AddSidecar(backupConf formolv1alpha1.Bac
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, target := range backupConf.Spec.Targets {
|
|
||||||
addSidecar := false
|
|
||||||
for _, targetContainer := range target.Containers {
|
|
||||||
if len(targetContainer.Steps) > 0 {
|
|
||||||
addSidecar = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if target.BackupType == formolv1alpha1.OnlineKind {
|
|
||||||
addSidecar = true
|
|
||||||
}
|
|
||||||
if addSidecar {
|
|
||||||
repo := formolv1alpha1.Repo{}
|
repo := formolv1alpha1.Repo{}
|
||||||
if err := r.Get(r.Context, client.ObjectKey{
|
if err := r.Get(r.Context, client.ObjectKey{
|
||||||
Namespace: backupConf.Namespace,
|
Namespace: backupConf.Namespace,
|
||||||
@ -285,8 +270,6 @@ func (r *BackupConfigurationReconciler) AddSidecar(backupConf formolv1alpha1.Bac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user