Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic when HelmRepository's artifact size is nil #683

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions controllers/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,17 @@ func (r *HelmRepositoryReconciler) notify(oldObj, newObj *sourcev1.HelmRepositor
sourcev1.GroupVersion.Group + "/checksum": newObj.Status.Artifact.Checksum,
}

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

var oldChecksum string
if oldObj.GetArtifact() != nil {
oldChecksum = oldObj.GetArtifact().Checksum
}

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

// Notify on new artifact and failure recovery.
if oldChecksum != newObj.GetArtifact().Checksum {
Expand Down
9 changes: 9 additions & 0 deletions controllers/helmrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,15 @@ func TestHelmRepositoryReconciler_notify(t *testing.T) {
res: sreconcile.ResultEmpty,
resErr: errors.New("some error"),
},
{
name: "new artifact with nil size",
res: sreconcile.ResultSuccess,
resErr: nil,
newObjBeforeFunc: func(obj *sourcev1.HelmRepository) {
obj.Status.Artifact = &sourcev1.Artifact{Revision: "xxx", Checksum: "yyy", Size: nil}
},
wantEvent: "Normal NewArtifact stored fetched index of unknown size",
},
{
name: "new artifact",
res: sreconcile.ResultSuccess,
Expand Down