@@ -25,6 +25,7 @@ import (
2525 "github.com/rancher/fleet/internal/metrics"
2626 "github.com/rancher/fleet/internal/ocistorage"
2727 fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
28+ "github.com/rancher/fleet/pkg/durations"
2829 fleetevent "github.com/rancher/fleet/pkg/event"
2930 "github.com/rancher/fleet/pkg/sharding"
3031 corev1 "k8s.io/api/core/v1"
@@ -62,7 +63,7 @@ type Store interface {
6263}
6364
6465type TargetBuilder interface {
65- Targets (ctx context.Context , bundle * fleet.Bundle , manifestID string ) ([]* target.Target , error )
66+ Targets (ctx context.Context , bundle * fleet.Bundle , manifestID string ) ([]* target.Target , bool , error )
6667}
6768
6869// BundleReconciler reconciles a Bundle object
@@ -243,7 +244,7 @@ func (r *BundleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
243244 }
244245 }
245246
246- matchedTargets , err := r .Builder .Targets (ctx , bundle , manifestID )
247+ matchedTargets , secretsMissing , err := r .Builder .Targets (ctx , bundle , manifestID )
247248 if err != nil {
248249 return ctrl.Result {},
249250 r .updateErrorStatus (
@@ -328,13 +329,20 @@ func (r *BundleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
328329 bd .Spec .OCIContents = contentsInOCI
329330 bd .Spec .HelmChartOptions = bundle .Spec .HelmOpOptions
330331
331- valuesHash , optionsSecret , err := r .manageOptionsSecret (ctx , bd )
332- if err != nil {
333- return r .computeResult (ctx , logger , bundleOrig , bundle , "failed to initialize options secret" , err )
334- }
332+ var optionsSecret * corev1.Secret
333+ // If the options secret was unavailable during Targets(). Preserve the
334+ // existing ValuesHash (already present in bd.Spec from BundleDeployment())
335+ // and skip writing the secret so we don't overwrite it with empty values.
336+ if ! bd .Spec .WaitingForValues {
337+ var valuesHash string
338+ valuesHash , optionsSecret , err = r .manageOptionsSecret (ctx , bd )
339+ if err != nil {
340+ return r .computeResult (ctx , logger , bundleOrig , bundle , "failed to initialize options secret" , err )
341+ }
335342
336- // Changes in the values hash trigger a bundle deployment reconcile.
337- bd .Spec .ValuesHash = valuesHash
343+ // Changes in the values hash trigger a bundle deployment reconcile.
344+ bd .Spec .ValuesHash = valuesHash
345+ }
338346
339347 // When content resources are stored in etcd, we need to keep track of the content resource so they
340348 // are properly gargabe-collected by the content controller.
@@ -402,6 +410,13 @@ func (r *BundleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
402410 return ctrl.Result {}, errutil .NewAggregate (merr )
403411 }
404412
413+ if secretsMissing {
414+ // At least one BundleDeployment had its options secret transiently
415+ // unavailable. Requeue so we can retry loading those values; we cannot
416+ // rely on an external event to re-trigger the reconcile.
417+ return ctrl.Result {RequeueAfter : durations .DefaultRequeueAfter }, errutil .NewAggregate (merr )
418+ }
419+
405420 return ctrl.Result {}, errutil .NewAggregate (merr )
406421}
407422
0 commit comments