Restic repository now includes the targetName to avoid concurrency when multiple targets are doing backup simulteanously
This commit is contained in:
parent
05cb6bd1cb
commit
910dbbbbd5
@ -81,8 +81,9 @@ var deleteSnapshotCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
name, _ := cmd.Flags().GetString("name")
|
||||
namespace, _ := cmd.Flags().GetString("namespace")
|
||||
targetName, _ := cmd.Flags().GetString("target-name")
|
||||
snapshotId, _ := cmd.Flags().GetString("snapshot-id")
|
||||
standalone.DeleteSnapshot(namespace, name, snapshotId)
|
||||
standalone.DeleteSnapshot(namespace, name, targetName, snapshotId)
|
||||
},
|
||||
}
|
||||
|
||||
@ -138,7 +139,9 @@ func init() {
|
||||
deleteSnapshotCmd.Flags().String("snapshot-id", "", "The snapshot id to delete")
|
||||
deleteSnapshotCmd.Flags().String("namespace", "", "The namespace of the BackupConfiguration containing the information about the backup.")
|
||||
deleteSnapshotCmd.Flags().String("name", "", "The name of the BackupConfiguration containing the information about the backup.")
|
||||
deleteSnapshotCmd.Flags().String("target-name", "", "The name of the backup target.")
|
||||
deleteSnapshotCmd.MarkFlagRequired("snapshot-id")
|
||||
deleteSnapshotCmd.MarkFlagRequired("namespace")
|
||||
deleteSnapshotCmd.MarkFlagRequired("name")
|
||||
deleteSnapshotCmd.MarkFlagRequired("target-name")
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
}
|
||||
|
||||
// Do preliminary checks with the repository
|
||||
if err = r.SetResticEnv(backupConf); err != nil {
|
||||
if err = r.SetResticEnv(backupConf, target.TargetName); err != nil {
|
||||
r.Log.Error(err, "unable to set restic env")
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ func (r *BackupSessionReconciler) backupSnapshot(target formolv1alpha1.Target) (
|
||||
sidecar := formolv1alpha1.GetSidecar(r.backupConf, target)
|
||||
sidecar.Args = append([]string{"backupsession", "backup", "--namespace", r.Namespace, "--name", r.Name, "--target-name", target.TargetName}, paths...)
|
||||
sidecar.VolumeMounts = vms
|
||||
if env, err := r.getResticEnv(r.backupConf); err != nil {
|
||||
if env, err := r.getResticEnv(r.backupConf, target.TargetName); err != nil {
|
||||
r.Log.Error(err, "unable to get restic env")
|
||||
return err
|
||||
} else {
|
||||
|
||||
@ -69,7 +69,7 @@ func (r *RestoreSessionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
|
||||
}
|
||||
|
||||
// Do preliminary checks with the repository
|
||||
if err = r.SetResticEnv(backupConf); err != nil {
|
||||
if err = r.SetResticEnv(backupConf, target.TargetName); err != nil {
|
||||
r.Log.Error(err, "unable to set restic env")
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ func (r *RestoreSessionReconciler) restoreInitContainer(target formolv1alpha1.Ta
|
||||
for i, _ := range initContainer.VolumeMounts {
|
||||
initContainer.VolumeMounts[i].ReadOnly = false
|
||||
}
|
||||
if env, err := r.getResticEnv(r.backupConf); err != nil {
|
||||
if env, err := r.getResticEnv(r.backupConf, target.TargetName); err != nil {
|
||||
r.Log.Error(err, "unable to get restic env")
|
||||
return err
|
||||
} else {
|
||||
|
||||
@ -40,7 +40,7 @@ const (
|
||||
RESTIC_EXEC = "/usr/bin/restic"
|
||||
)
|
||||
|
||||
func (s Session) getResticEnv(backupConf formolv1alpha1.BackupConfiguration) (envs []corev1.EnvVar, err error) {
|
||||
func (s Session) getResticEnv(backupConf formolv1alpha1.BackupConfiguration, targetName string) (envs []corev1.EnvVar, err error) {
|
||||
repo := formolv1alpha1.Repo{}
|
||||
if err = s.Get(s.Context, client.ObjectKey{
|
||||
Namespace: backupConf.Namespace,
|
||||
@ -52,11 +52,12 @@ func (s Session) getResticEnv(backupConf formolv1alpha1.BackupConfiguration) (en
|
||||
if repo.Spec.Backend.S3 != nil {
|
||||
envs = append(envs, corev1.EnvVar{
|
||||
Name: formolv1alpha1.RESTIC_REPOSITORY,
|
||||
Value: fmt.Sprintf("s3:http://%s/%s/%s-%s",
|
||||
Value: fmt.Sprintf("s3:http://%s/%s/%s-%s/%s",
|
||||
repo.Spec.Backend.S3.Server,
|
||||
repo.Spec.Backend.S3.Bucket,
|
||||
strings.ToUpper(backupConf.Namespace),
|
||||
strings.ToLower(backupConf.Name)),
|
||||
strings.ToLower(backupConf.Name),
|
||||
targetName),
|
||||
})
|
||||
|
||||
data := s.getSecretData(repo.Spec.RepositorySecrets)
|
||||
@ -76,8 +77,8 @@ func (s Session) getResticEnv(backupConf formolv1alpha1.BackupConfiguration) (en
|
||||
return
|
||||
}
|
||||
|
||||
func (s Session) SetResticEnv(backupConf formolv1alpha1.BackupConfiguration) error {
|
||||
envs, err := s.getResticEnv(backupConf)
|
||||
func (s Session) SetResticEnv(backupConf formolv1alpha1.BackupConfiguration, targetName string) error {
|
||||
envs, err := s.getResticEnv(backupConf, targetName)
|
||||
for _, env := range envs {
|
||||
os.Setenv(env.Name, env.Value)
|
||||
}
|
||||
|
||||
2
formol
2
formol
@ -1 +1 @@
|
||||
Subproject commit 92ea7f38729eebebd3cabff4a391bdb878c4e387
|
||||
Subproject commit 6f150cc36de7f879e2ddd89d126de84b77af0651
|
||||
@ -199,7 +199,7 @@ func CreateBackupSession(ref corev1.ObjectReference) {
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteSnapshot(namespace string, name string, snapshotId string) {
|
||||
func DeleteSnapshot(namespace string, name string, targetName string, snapshotId string) {
|
||||
log := session.Log.WithName("DeleteSnapshot")
|
||||
session.Namespace = namespace
|
||||
backupConf := formolv1alpha1.BackupConfiguration{}
|
||||
@ -210,7 +210,7 @@ func DeleteSnapshot(namespace string, name string, snapshotId string) {
|
||||
log.Error(err, "unable to get the BackupConf")
|
||||
return
|
||||
}
|
||||
if err := session.SetResticEnv(backupConf); err != nil {
|
||||
if err := session.SetResticEnv(backupConf, targetName); err != nil {
|
||||
log.Error(err, "unable to set the restic env")
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user