From 319db015a5cf901c43e7fb8bee749b51ac8d8d6a Mon Sep 17 00:00:00 2001 From: Soule BA Date: Wed, 6 Mar 2024 12:19:09 +0100 Subject: [PATCH] Reintroduce missing events for helmChart reconciliation If implemented this PR reintroduce events for some failling action during the reconciliation process, related to the helmChart retrieval and loading of chart and values. Signed-off-by: Soule BA --- internal/controller/helmrelease_controller.go | 4 ++++ internal/controller/helmrelease_controller_test.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/internal/controller/helmrelease_controller.go b/internal/controller/helmrelease_controller.go index 10648ae67..430fe2e96 100644 --- a/internal/controller/helmrelease_controller.go +++ b/internal/controller/helmrelease_controller.go @@ -259,6 +259,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe conditions.MarkStalled(obj, aclv1.AccessDeniedReason, err.Error()) conditions.MarkFalse(obj, meta.ReadyCondition, aclv1.AccessDeniedReason, err.Error()) conditions.Delete(obj, meta.ReconcilingCondition) + r.Eventf(obj, eventv1.EventSeverityError, aclv1.AccessDeniedReason, err.Error()) // Recovering from this is not possible without a restart of the // controller or a change of spec, both triggering a new @@ -268,6 +269,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe msg := fmt.Sprintf("could not get HelmChart object: %s", err.Error()) conditions.MarkFalse(obj, meta.ReadyCondition, v2.ArtifactFailedReason, msg) + r.Eventf(obj, eventv1.EventSeverityError, v2.ArtifactFailedReason, msg) return ctrl.Result{}, err } // Remove any stale corresponding Ready=False condition with Unknown. @@ -293,6 +295,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe values, err := chartutil.ChartValuesFromReferences(ctx, r.Client, obj.Namespace, obj.GetValues(), obj.Spec.ValuesFrom...) if err != nil { conditions.MarkFalse(obj, meta.ReadyCondition, "ValuesError", err.Error()) + r.Eventf(obj, eventv1.EventSeverityError, "ValuesError", err.Error()) return ctrl.Result{}, err } // Remove any stale corresponding Ready=False condition with Unknown. @@ -311,6 +314,7 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe } conditions.MarkFalse(obj, meta.ReadyCondition, v2.ArtifactFailedReason, fmt.Sprintf("Could not load chart: %s", err.Error())) + r.Eventf(obj, eventv1.EventSeverityError, v2.ArtifactFailedReason, err.Error()) return ctrl.Result{}, err } // Remove any stale corresponding Ready=False condition with Unknown. diff --git a/internal/controller/helmrelease_controller_test.go b/internal/controller/helmrelease_controller_test.go index 5de31ad33..e8d19444c 100644 --- a/internal/controller/helmrelease_controller_test.go +++ b/internal/controller/helmrelease_controller_test.go @@ -136,6 +136,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) { WithStatusSubresource(&v2.HelmRelease{}). WithObjects(obj). Build(), + EventRecorder: record.NewFakeRecorder(32), } _, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj) @@ -166,6 +167,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) { WithStatusSubresource(&v2.HelmRelease{}). WithObjects(obj). Build(), + EventRecorder: record.NewFakeRecorder(32), } res, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj) @@ -383,6 +385,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) { WithStatusSubresource(&v2.HelmRelease{}). WithObjects(chart, obj). Build(), + EventRecorder: record.NewFakeRecorder(32), } _, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj)