Skip to content

Commit c3d5dac

Browse files
Max Jonas Wernerhiddeco
Max Jonas Werner
andcommitted
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 <mail@makk.es> Co-authored-by: Hidde Beydals <hiddeco@users.noreply.github.com>
1 parent c51b359 commit c3d5dac

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

controllers/helmrepository_controller.go

+5-2
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

+9
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)