From 6ae82f70d456c05b3ad0ab01e901be8bd01bb9eb Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Fri, 17 May 2024 16:35:40 -0700 Subject: [PATCH] fix: downgrade omission of 'instance' field from an error to a warning --- internal/orchestrator/repo/repo.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/orchestrator/repo/repo.go b/internal/orchestrator/repo/repo.go index c071b5a..3003700 100644 --- a/internal/orchestrator/repo/repo.go +++ b/internal/orchestrator/repo/repo.go @@ -98,7 +98,11 @@ func (r *RepoOrchestrator) SnapshotsForPlan(ctx context.Context, plan *v1.Plan) ctx, flush := forwardResticLogs(ctx) defer flush() - snapshots, err := r.repo.Snapshots(ctx, restic.WithFlags("--tag", TagForPlan(plan.Id)+","+TagForInstance(r.config.Instance))) + tags := []string{TagForPlan(plan.Id)} + if r.config.Instance != "" { + tags = append(tags, TagForInstance(r.config.Instance)) + } + snapshots, err := r.repo.Snapshots(ctx, restic.WithFlags("--tag", strings.Join(tags, ","))) if err != nil { return nil, fmt.Errorf("get snapshots for plan %q: %w", plan.Id, err) } @@ -132,8 +136,13 @@ func (r *RepoOrchestrator) Backup(ctx context.Context, plan *v1.Plan, progressCa opts = append(opts, restic.WithFlags( "--exclude-caches", "--tag", TagForPlan(plan.Id), - "--tag", TagForInstance(r.config.Instance)), - ) + )) + + if r.config.Instance != "" { + opts = append(opts, restic.WithFlags("--tag", TagForInstance(r.config.Instance))) + } else { + zap.L().Warn("Creating a backup without an 'instance' tag as no value is set in the config. In a future backrest release this will be an error.") + } for _, exclude := range plan.Excludes { opts = append(opts, restic.WithFlags("--exclude", exclude)) @@ -193,10 +202,6 @@ func (r *RepoOrchestrator) Forget(ctx context.Context, plan *v1.Plan, tags []str return nil, fmt.Errorf("plan %q has no retention policy", plan.Id) } - if r.config.Instance == "" { - return nil, errors.New("instance is a required field in the backrest config") - } - result, err := r.repo.Forget( ctx, protoutil.RetentionPolicyFromProto(plan.Retention), restic.WithFlags("--tag", strings.Join(tags, ",")),