From 5090b5fb1abc87cae16b209562786a1b86dc77e9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Andre Date: Wed, 22 Feb 2023 14:33:44 +0100 Subject: [PATCH] added local repository for restic --- api/v1alpha1/repo_types.go | 6 ++++-- api/v1alpha1/zz_generated.deepcopy.go | 3 ++- .../backupconfiguration_controller_helpers.go | 12 +++++------- test/00-setup.yaml | 3 ++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/api/v1alpha1/repo_types.go b/api/v1alpha1/repo_types.go index b124b32..224befe 100644 --- a/api/v1alpha1/repo_types.go +++ b/api/v1alpha1/repo_types.go @@ -24,6 +24,8 @@ import ( ) const ( + RESTIC_REPO_VOLUME = "restic-volume" + RESTIC_REPO_PATH = "/restic-repo" RESTIC_REPOSITORY = "RESTIC_REPOSITORY" RESTIC_PASSWORD = "RESTIC_PASSWORD" AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID" @@ -38,7 +40,7 @@ type S3 struct { } type Local struct { - Path string `json:"path"` + corev1.VolumeSource `json:"source"` } type Backend struct { @@ -115,7 +117,7 @@ func (repo *Repo) GetResticEnv(backupConf BackupConfiguration) []corev1.EnvVar { if repo.Spec.Backend.Local != nil { env = append(env, corev1.EnvVar{ Name: RESTIC_REPOSITORY, - Value: repo.Spec.Backend.Local.Path, + Value: RESTIC_REPO_PATH, }) } env = append(env, corev1.EnvVar{ diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index e8cf666..3c46448 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -37,7 +37,7 @@ func (in *Backend) DeepCopyInto(out *Backend) { if in.Local != nil { in, out := &in.Local, &out.Local *out = new(Local) - **out = **in + (*in).DeepCopyInto(*out) } } @@ -350,6 +350,7 @@ func (in *Keep) DeepCopy() *Keep { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Local) DeepCopyInto(out *Local) { *out = *in + in.VolumeSource.DeepCopyInto(&out.VolumeSource) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Local. diff --git a/controllers/backupconfiguration_controller_helpers.go b/controllers/backupconfiguration_controller_helpers.go index df04c68..c40bed7 100644 --- a/controllers/backupconfiguration_controller_helpers.go +++ b/controllers/backupconfiguration_controller_helpers.go @@ -187,7 +187,7 @@ func (r *BackupConfigurationReconciler) DeleteSidecar(backupConf formolv1alpha1. if repo.Spec.Backend.Local != nil { restoreVolumes := []corev1.Volume{} for _, volume := range targetPodSpec.Volumes { - if volume.Name == "restic-local-repo" { + if volume.Name == formolv1alpha1.RESTIC_REPO_VOLUME { continue } restoreVolumes = append(restoreVolumes, volume) @@ -310,14 +310,12 @@ func (r *BackupConfigurationReconciler) addOnlineSidecar(backupConf formolv1alph }) if repo.Spec.Backend.Local != nil { sidecar.VolumeMounts = append(vms, corev1.VolumeMount{ - Name: "restic-local-repo", - MountPath: "/repo", + Name: formolv1alpha1.RESTIC_REPO_VOLUME, + MountPath: formolv1alpha1.RESTIC_REPO_PATH, }) targetPodSpec.Volumes = append(targetPodSpec.Volumes, corev1.Volume{ - Name: "restic-local-repo", - VolumeSource: corev1.VolumeSource{ - EmptyDir: &corev1.EmptyDirVolumeSource{}, - }, + Name: formolv1alpha1.RESTIC_REPO_VOLUME, + VolumeSource: repo.Spec.Backend.Local.VolumeSource, }) } else { sidecar.VolumeMounts = vms diff --git a/test/00-setup.yaml b/test/00-setup.yaml index 7a9ef76..d186669 100644 --- a/test/00-setup.yaml +++ b/test/00-setup.yaml @@ -79,7 +79,8 @@ metadata: spec: backend: local: - path: /repo + source: + emptyDir: repositorySecrets: secret-minio --- apiVersion: formol.desmojim.fr/v1alpha1