Skip to content

Commit b907001

Browse files
author
Max Jonas Werner
committed
fix panic when HelmRepository's artifact size is nil
This fixes the immediate issue of the nil pointer dereference but we still haven't isolated the actual cause of the size being nil to begin with. This is ongoing work and as soon as we have boiled that down to the simplest case we will provide a regression test for that case. closes #680 Signed-off-by: Max Jonas Werner <[email protected]>
1 parent c51b359 commit b907001

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

controllers/helmrepository_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,20 @@ 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+
size := newObj.Status.Artifact.Size
259+
var humanReadableSize string
260+
if size != nil {
261+
humanReadableSize = fmt.Sprintf("size %s", units.HumanSize(float64(*size)))
262+
} else {
263+
humanReadableSize = "unknown size"
264+
}
259265

260266
var oldChecksum string
261267
if oldObj.GetArtifact() != nil {
262268
oldChecksum = oldObj.GetArtifact().Checksum
263269
}
264270

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

267273
// Notify on new artifact and failure recovery.
268274
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)