@@ -39,6 +39,7 @@ import (
3939 helmgetter "helm.sh/helm/v3/pkg/getter"
4040 helmreg "helm.sh/helm/v3/pkg/registry"
4141 corev1 "k8s.io/api/core/v1"
42+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4243 "k8s.io/apimachinery/pkg/runtime"
4344 "k8s.io/apimachinery/pkg/types"
4445 kuberecorder "k8s.io/client-go/tools/record"
@@ -52,29 +53,20 @@ import (
5253var helmRepositoryOCIReadyCondition = summarize.Conditions {
5354 Target : meta .ReadyCondition ,
5455 Owned : []string {
55- sourcev1 .FetchFailedCondition ,
5656 meta .ReadyCondition ,
5757 meta .ReconcilingCondition ,
5858 meta .StalledCondition ,
5959 },
6060 Summarize : []string {
61- sourcev1 .FetchFailedCondition ,
6261 meta .StalledCondition ,
6362 meta .ReconcilingCondition ,
6463 },
6564 NegativePolarity : []string {
66- sourcev1 .FetchFailedCondition ,
6765 meta .StalledCondition ,
6866 meta .ReconcilingCondition ,
6967 },
7068}
7169
72- // helmRepositoryOCIFailConditions contains the conditions that represent a
73- // failure.
74- var helmRepositoryOCIFailConditions = []string {
75- sourcev1 .FetchFailedCondition ,
76- }
77-
7870// +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=helmrepositories,verbs=get;list;watch;create;update;patch;delete
7971// +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=helmrepositories/status,verbs=get;update;patch
8072// +kubebuilder:rbac:groups=source.toolkit.fluxcd.io,resources=helmrepositories/finalizers,verbs=get;create;update;patch;delete
@@ -216,7 +208,28 @@ func (r *HelmRepositoryOCIReconciler) reconcileDelete(ctx context.Context, obj *
216208func (r * HelmRepositoryOCIReconciler ) notify (oldObj , newObj * sourcev1.HelmRepository , res sreconcile.Result , resErr error ) {
217209 // Notify successful recovery from any failure.
218210 if resErr == nil && res == sreconcile .ResultSuccess {
219- if sreconcile .FailureRecovery (oldObj , newObj , helmRepositoryOCIFailConditions ) {
211+ // since the object is successfully reconciled without error,
212+ // we can determine recovery by comparing the old and new object
213+ // readyConditions status.
214+ // We can use the readyConditions to determine if the object has
215+ // recovered from a failure because, in this reconciliation loop
216+ // the readyConditions is directly set by the subreconcilers and not calculated
217+ // as a result of the subreconcilers.
218+ var oldReadyStatus , newReadyStatus metav1.ConditionStatus
219+ if cond := conditions .Get (oldObj , meta .ReadyCondition ); cond != nil {
220+ oldReadyStatus = cond .Status
221+ }
222+
223+ if cond := conditions .Get (newObj , meta .ReadyCondition ); cond != nil {
224+ newReadyStatus = cond .Status
225+ }
226+
227+ if oldReadyStatus == "" || newReadyStatus == "" {
228+ // if the ready status is not set, it is not a recovery
229+ return
230+ }
231+
232+ if oldReadyStatus == metav1 .ConditionFalse && newReadyStatus == metav1 .ConditionTrue {
220233 r .Eventf (newObj , corev1 .EventTypeNormal ,
221234 meta .SucceededReason , "Helm repository %q has been successfully reconciled" , newObj .Name )
222235 }
@@ -271,7 +284,7 @@ func (r *HelmRepositoryOCIReconciler) reconcileSource(ctx context.Context, obj *
271284 Err : fmt .Errorf ("failed to get secret '%s': %w" , name .String (), err ),
272285 Reason : sourcev1 .AuthenticationFailedReason ,
273286 }
274- conditions .MarkTrue (obj , sourcev1 . FetchFailedCondition , e .Reason , e .Err .Error ())
287+ conditions .MarkFalse (obj , meta . ReadyCondition , e .Reason , e .Err .Error ())
275288 return sreconcile .ResultEmpty , e
276289 }
277290
@@ -282,8 +295,7 @@ func (r *HelmRepositoryOCIReconciler) reconcileSource(ctx context.Context, obj *
282295 Err : fmt .Errorf ("failed to configure Helm client with secret data: %w" , err ),
283296 Reason : sourcev1 .AuthenticationFailedReason ,
284297 }
285- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
286- // Return err as the content of the secret may change.
298+ conditions .MarkFalse (obj , meta .ReadyCondition , e .Reason , e .Err .Error ())
287299 return sreconcile .ResultEmpty , e
288300 }
289301
0 commit comments