helmrepo: Make NewArtifact event human friendly

Inform index size and repo instead of a revision.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
This commit is contained in:
Sunny 2022-02-21 18:45:56 +05:30 committed by Hidde Beydals
parent 84bf8c8572
commit 9c7661dcbd
2 changed files with 13 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import (
"os"
"time"
"github.com/docker/go-units"
helmgetter "helm.sh/helm/v3/pkg/getter"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
@ -425,10 +426,20 @@ func (r *HelmRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *s
}
}
// Calculate the artifact size to be included in the NewArtifact event.
fi, err := os.Stat(chartRepo.CachePath)
if err != nil {
return sreconcile.ResultEmpty, &serror.Event{
Err: fmt.Errorf("unable to read the artifact: %w", err),
Reason: sourcev1.StorageOperationFailedReason,
}
}
size := units.HumanSize(float64(fi.Size()))
r.AnnotatedEventf(obj, map[string]string{
"revision": artifact.Revision,
"checksum": artifact.Checksum,
}, corev1.EventTypeNormal, "NewArtifact", "stored artifact for revision '%s'", artifact.Revision)
}, corev1.EventTypeNormal, "NewArtifact", "fetched index of size %s from '%s'", size, chartRepo.URL)
// Record it on the object.
obj.Status.Artifact = artifact.DeepCopy()

2
go.mod
View File

@ -10,6 +10,7 @@ require (
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7
github.com/cyphar/filepath-securejoin v0.2.2
github.com/darkowlzz/controller-check v0.0.0-20220119215126-648356cef22c
github.com/docker/go-units v0.4.0
github.com/elazarl/goproxy v0.0.0-20211114080932-d06c3be7c11b
github.com/fluxcd/pkg/apis/meta v0.12.0
github.com/fluxcd/pkg/gittestserver v0.5.0
@ -73,7 +74,6 @@ require (
github.com/docker/docker-credential-helpers v0.6.3 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect