Merge pull request #659 from fluxcd/gc-fail-event-fix
Avoid event logging GC failure
This commit is contained in:
commit
73aa3c4511
|
@ -634,12 +634,10 @@ func (r *BucketReconciler) garbageCollect(ctx context.Context, obj *sourcev1.Buc
|
||||||
if obj.GetArtifact() != nil {
|
if obj.GetArtifact() != nil {
|
||||||
delFiles, err := r.Storage.GarbageCollect(ctx, *obj.GetArtifact(), time.Second*5)
|
delFiles, err := r.Storage.GarbageCollect(ctx, *obj.GetArtifact(), time.Second*5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := &serror.Event{
|
return &serror.Event{
|
||||||
Err: fmt.Errorf("garbage collection of artifacts failed: %w", err),
|
Err: fmt.Errorf("garbage collection of artifacts failed: %w", err),
|
||||||
Reason: "GarbageCollectionFailed",
|
Reason: "GarbageCollectionFailed",
|
||||||
}
|
}
|
||||||
r.eventLogf(ctx, obj, corev1.EventTypeWarning, e.Reason, e.Err.Error())
|
|
||||||
return e
|
|
||||||
}
|
}
|
||||||
if len(delFiles) > 0 {
|
if len(delFiles) > 0 {
|
||||||
r.eventLogf(ctx, obj, events.EventTypeTrace, "GarbageCollectionSucceeded",
|
r.eventLogf(ctx, obj, events.EventTypeTrace, "GarbageCollectionSucceeded",
|
||||||
|
|
|
@ -710,12 +710,10 @@ func (r *GitRepositoryReconciler) garbageCollect(ctx context.Context, obj *sourc
|
||||||
if obj.GetArtifact() != nil {
|
if obj.GetArtifact() != nil {
|
||||||
delFiles, err := r.Storage.GarbageCollect(ctx, *obj.GetArtifact(), time.Second*5)
|
delFiles, err := r.Storage.GarbageCollect(ctx, *obj.GetArtifact(), time.Second*5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := &serror.Event{
|
return &serror.Event{
|
||||||
Err: fmt.Errorf("garbage collection of artifacts failed: %w", err),
|
Err: fmt.Errorf("garbage collection of artifacts failed: %w", err),
|
||||||
Reason: "GarbageCollectionFailed",
|
Reason: "GarbageCollectionFailed",
|
||||||
}
|
}
|
||||||
r.eventLogf(ctx, obj, corev1.EventTypeWarning, e.Reason, e.Err.Error())
|
|
||||||
return e
|
|
||||||
}
|
}
|
||||||
if len(delFiles) > 0 {
|
if len(delFiles) > 0 {
|
||||||
r.eventLogf(ctx, obj, events.EventTypeTrace, "GarbageCollectionSucceeded",
|
r.eventLogf(ctx, obj, events.EventTypeTrace, "GarbageCollectionSucceeded",
|
||||||
|
|
|
@ -806,12 +806,10 @@ func (r *HelmChartReconciler) garbageCollect(ctx context.Context, obj *sourcev1.
|
||||||
if obj.GetArtifact() != nil {
|
if obj.GetArtifact() != nil {
|
||||||
delFiles, err := r.Storage.GarbageCollect(ctx, *obj.GetArtifact(), time.Second*5)
|
delFiles, err := r.Storage.GarbageCollect(ctx, *obj.GetArtifact(), time.Second*5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := &serror.Event{
|
return &serror.Event{
|
||||||
Err: fmt.Errorf("garbage collection of artifacts failed: %w", err),
|
Err: fmt.Errorf("garbage collection of artifacts failed: %w", err),
|
||||||
Reason: "GarbageCollectionFailed",
|
Reason: "GarbageCollectionFailed",
|
||||||
}
|
}
|
||||||
r.eventLogf(ctx, obj, corev1.EventTypeWarning, e.Reason, e.Err.Error())
|
|
||||||
return e
|
|
||||||
}
|
}
|
||||||
if len(delFiles) > 0 {
|
if len(delFiles) > 0 {
|
||||||
r.eventLogf(ctx, obj, events.EventTypeTrace, "GarbageCollectionSucceeded",
|
r.eventLogf(ctx, obj, events.EventTypeTrace, "GarbageCollectionSucceeded",
|
||||||
|
|
|
@ -520,12 +520,10 @@ func (r *HelmRepositoryReconciler) garbageCollect(ctx context.Context, obj *sour
|
||||||
if obj.GetArtifact() != nil {
|
if obj.GetArtifact() != nil {
|
||||||
delFiles, err := r.Storage.GarbageCollect(ctx, *obj.GetArtifact(), time.Second*5)
|
delFiles, err := r.Storage.GarbageCollect(ctx, *obj.GetArtifact(), time.Second*5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := &serror.Event{
|
return &serror.Event{
|
||||||
Err: fmt.Errorf("garbage collection of artifacts failed: %w", err),
|
Err: fmt.Errorf("garbage collection of artifacts failed: %w", err),
|
||||||
Reason: "GarbageCollectionFailed",
|
Reason: "GarbageCollectionFailed",
|
||||||
}
|
}
|
||||||
r.eventLogf(ctx, obj, corev1.EventTypeWarning, e.Reason, e.Err.Error())
|
|
||||||
return e
|
|
||||||
}
|
}
|
||||||
if len(delFiles) > 0 {
|
if len(delFiles) > 0 {
|
||||||
r.eventLogf(ctx, obj, events.EventTypeTrace, "GarbageCollectionSucceeded",
|
r.eventLogf(ctx, obj, events.EventTypeTrace, "GarbageCollectionSucceeded",
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -32,16 +33,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
securejoin "github.com/cyphar/filepath-securejoin"
|
securejoin "github.com/cyphar/filepath-securejoin"
|
||||||
|
"github.com/fluxcd/pkg/lockedfile"
|
||||||
|
"github.com/fluxcd/pkg/untar"
|
||||||
"github.com/go-git/go-git/v5/plumbing/format/gitignore"
|
"github.com/go-git/go-git/v5/plumbing/format/gitignore"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
kerrors "k8s.io/apimachinery/pkg/util/errors"
|
kerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
|
|
||||||
"github.com/fluxcd/pkg/lockedfile"
|
|
||||||
|
|
||||||
"io/fs"
|
|
||||||
|
|
||||||
"github.com/fluxcd/pkg/untar"
|
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
|
||||||
sourcefs "github.com/fluxcd/source-controller/internal/fs"
|
sourcefs "github.com/fluxcd/source-controller/internal/fs"
|
||||||
"github.com/fluxcd/source-controller/pkg/sourceignore"
|
"github.com/fluxcd/source-controller/pkg/sourceignore"
|
||||||
|
@ -181,7 +178,7 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if totalFiles >= totalCountLimit {
|
if totalFiles >= totalCountLimit {
|
||||||
return fmt.Errorf("Reached file walking limit, already walked over: %d", totalFiles)
|
return fmt.Errorf("reached file walking limit, already walked over: %d", totalFiles)
|
||||||
}
|
}
|
||||||
info, err := d.Info()
|
info, err := d.Info()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -190,8 +187,8 @@ func (s *Storage) getGarbageFiles(artifact sourcev1.Artifact, totalCountLimit, m
|
||||||
}
|
}
|
||||||
createdAt := info.ModTime().UTC()
|
createdAt := info.ModTime().UTC()
|
||||||
diff := now.Sub(createdAt)
|
diff := now.Sub(createdAt)
|
||||||
// compare the time difference between now and the time at which the file was created
|
// Compare the time difference between now and the time at which the file was created
|
||||||
// with the provided ttl. delete if difference is greater than the ttl.
|
// with the provided TTL. Delete if the difference is greater than the TTL.
|
||||||
expired := diff > ttl
|
expired := diff > ttl
|
||||||
if !info.IsDir() && info.Mode()&os.ModeSymlink != os.ModeSymlink {
|
if !info.IsDir() && info.Mode()&os.ModeSymlink != os.ModeSymlink {
|
||||||
if path != localPath && expired {
|
if path != localPath && expired {
|
||||||
|
|
Loading…
Reference in New Issue