Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Make clone cleanups more robust #2788

Merged
merged 4 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,11 @@ func (d *Daemon) WithWorkingClone(ctx context.Context, fn func(*git.Checkout) er
if err != nil {
return err
}
defer co.Clean()
defer func() {
if err := co.Clean(); err != nil {
d.Logger.Log("error", fmt.Sprintf("cannot clean working clone: %s", err))
}
}()
if d.GitSecretEnabled {
if err := co.SecretUnseal(ctx); err != nil {
return err
Expand All @@ -673,7 +677,11 @@ func (d *Daemon) WithReadonlyClone(ctx context.Context, fn func(*git.Export) err
if err != nil {
return err
}
defer co.Clean()
defer func() {
if err := co.Clean(); err != nil {
d.Logger.Log("error", fmt.Sprintf("cannot read-only clone: %s", err))
}
}()
if d.GitSecretEnabled {
if err := co.SecretUnseal(ctx); err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion pkg/daemon/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/sha256"
"encoding/base64"
"fmt"
"github.com/fluxcd/flux/pkg/metrics"
"github.com/go-kit/kit/log"
"github.com/pkg/errors"
Expand Down Expand Up @@ -48,7 +49,11 @@ func (d *Daemon) Sync(ctx context.Context, started time.Time, newRevision string
return err
}
cancel()
defer working.Clean()
defer func() {
if err := working.Clean(); err != nil {
d.Logger.Log("error", fmt.Sprintf("cannot clean sync clone: %s", err))
}
}()

// Unseal any secrets if enabled
if d.GitSecretEnabled {
Expand Down
5 changes: 3 additions & 2 deletions pkg/git/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ func (e *Export) Dir() string {
return e.dir
}

func (e *Export) Clean() {
func (e *Export) Clean() error {
if e.dir != "" {
os.RemoveAll(e.dir)
return os.RemoveAll(e.dir)
}
return nil
}

// Export creates a minimal clone of the repo, at the ref given.
Expand Down
6 changes: 5 additions & 1 deletion pkg/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,5 +486,9 @@ func (r *Repo) workingClone(ctx context.Context, ref string) (string, error) {
if err != nil {
return "", err
}
return clone(ctx, working, r.dir, ref)
path, err := clone(ctx, working, r.dir, ref)
if err != nil {
os.RemoveAll(path)
2opremio marked this conversation as resolved.
Show resolved Hide resolved
}
return path, err
}
1 change: 1 addition & 0 deletions pkg/sync/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (p GitTagSyncProvider) UpdateMarker(ctx context.Context, revision string) e
if err != nil {
return err
}
defer checkout.Clean()
return checkout.MoveTagAndPush(ctx, git.TagAction{
Tag: p.syncTag,
Revision: revision,
Expand Down