Skip to content

Commit 9c7661d

Browse files
darkowlzzhiddeco
authored andcommitted
helmrepo: Make NewArtifact event human friendly
Inform index size and repo instead of a revision. Signed-off-by: Sunny <[email protected]>
1 parent 84bf8c8 commit 9c7661d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

controllers/helmrepository_controller.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"time"
2626

27+
"github.com/docker/go-units"
2728
helmgetter "helm.sh/helm/v3/pkg/getter"
2829
corev1 "k8s.io/api/core/v1"
2930
"k8s.io/apimachinery/pkg/runtime"
@@ -425,10 +426,20 @@ func (r *HelmRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *s
425426
}
426427
}
427428

429+
// Calculate the artifact size to be included in the NewArtifact event.
430+
fi, err := os.Stat(chartRepo.CachePath)
431+
if err != nil {
432+
return sreconcile.ResultEmpty, &serror.Event{
433+
Err: fmt.Errorf("unable to read the artifact: %w", err),
434+
Reason: sourcev1.StorageOperationFailedReason,
435+
}
436+
}
437+
size := units.HumanSize(float64(fi.Size()))
438+
428439
r.AnnotatedEventf(obj, map[string]string{
429440
"revision": artifact.Revision,
430441
"checksum": artifact.Checksum,
431-
}, corev1.EventTypeNormal, "NewArtifact", "stored artifact for revision '%s'", artifact.Revision)
442+
}, corev1.EventTypeNormal, "NewArtifact", "fetched index of size %s from '%s'", size, chartRepo.URL)
432443

433444
// Record it on the object.
434445
obj.Status.Artifact = artifact.DeepCopy()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7
1111
github.com/cyphar/filepath-securejoin v0.2.2
1212
github.com/darkowlzz/controller-check v0.0.0-20220119215126-648356cef22c
13+
github.com/docker/go-units v0.4.0
1314
github.com/elazarl/goproxy v0.0.0-20211114080932-d06c3be7c11b
1415
github.com/fluxcd/pkg/apis/meta v0.12.0
1516
github.com/fluxcd/pkg/gittestserver v0.5.0
@@ -73,7 +74,6 @@ require (
7374
github.com/docker/docker-credential-helpers v0.6.3 // indirect
7475
github.com/docker/go-connections v0.4.0 // indirect
7576
github.com/docker/go-metrics v0.0.1 // indirect
76-
github.com/docker/go-units v0.4.0 // indirect
7777
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
7878
github.com/dustin/go-humanize v1.0.0 // indirect
7979
github.com/emirpasic/gods v1.12.0 // indirect

0 commit comments

Comments
 (0)