Skip to content

Commit 0836d88

Browse files
authored
Merge pull request fluxcd#683 from fluxcd/fix-panic
2 parents c51b359 + c3d5dac commit 0836d88

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

controllers/helmrepository_controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,17 @@ func (r *HelmRepositoryReconciler) notify(oldObj, newObj *sourcev1.HelmRepositor
255255
sourcev1.GroupVersion.Group + "/checksum": newObj.Status.Artifact.Checksum,
256256
}
257257

258-
size := units.HumanSize(float64(*newObj.Status.Artifact.Size))
258+
humanReadableSize := "unknown size"
259+
if size := newObj.Status.Artifact.Size; size != nil {
260+
humanReadableSize = fmt.Sprintf("size %s", units.HumanSize(float64(*size)))
261+
}
259262

260263
var oldChecksum string
261264
if oldObj.GetArtifact() != nil {
262265
oldChecksum = oldObj.GetArtifact().Checksum
263266
}
264267

265-
message := fmt.Sprintf("stored fetched index of size %s from '%s'", size, chartRepo.URL)
268+
message := fmt.Sprintf("stored fetched index of %s from '%s'", humanReadableSize, chartRepo.URL)
266269

267270
// Notify on new artifact and failure recovery.
268271
if oldChecksum != newObj.GetArtifact().Checksum {

controllers/helmrepository_controller_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,15 @@ func TestHelmRepositoryReconciler_notify(t *testing.T) {
859859
res: sreconcile.ResultEmpty,
860860
resErr: errors.New("some error"),
861861
},
862+
{
863+
name: "new artifact with nil size",
864+
res: sreconcile.ResultSuccess,
865+
resErr: nil,
866+
newObjBeforeFunc: func(obj *sourcev1.HelmRepository) {
867+
obj.Status.Artifact = &sourcev1.Artifact{Revision: "xxx", Checksum: "yyy", Size: nil}
868+
},
869+
wantEvent: "Normal NewArtifact stored fetched index of unknown size",
870+
},
862871
{
863872
name: "new artifact",
864873
res: sreconcile.ResultSuccess,

0 commit comments

Comments
 (0)