Skip to content

Commit f46468a

Browse files
committed
Enable sync worker to refresh payload when a change occurs
1 parent 309f0be commit f46468a

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

pkg/cvo/sync_worker.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,27 @@ func (w *SyncWorker) Start(ctx context.Context, maxWorkers int) {
647647

648648
// determine whether we need to do work
649649
w.lock.Lock()
650-
changed := work.calculateNextFrom(w.work)
650+
changed, featureGatesChanged := work.calculateNextFrom(w.work)
651+
652+
if featureGatesChanged {
653+
// When the feature gates change, we must reload the payload.
654+
// Loading the payload fiters out files that didn't match the previous set of feature gates,
655+
// this means now, additional files may match the new set of feature gates and need to be included.
656+
// Some files in the current payload may no longer match the new set of feature gates and need to be excluded,
657+
// though these ones are already excluded when apply calls Include on the manifests.
658+
klog.V(2).Infof("Feature gates changed, loading updated payload")
659+
660+
// Clear the payload to force a reload.
661+
w.payload = nil
662+
663+
_, err := w.loadUpdatedPayload(ctx, w.work)
664+
if err != nil {
665+
klog.Warningf("Error when attempting to load updated payload: %v.", err)
666+
}
667+
}
668+
651669
w.lock.Unlock()
670+
652671
if !changed && waitingToReconcile {
653672
klog.V(2).Infof("No change, waiting")
654673
continue
@@ -781,7 +800,7 @@ func (w *statusWrapper) Report(status SyncWorkerStatus) {
781800
// returns true if any changes were made. The reconciling flag is set the first
782801
// time work transitions from empty to not empty (as a result of someone invoking
783802
// Update).
784-
func (w *SyncWork) calculateNextFrom(desired *SyncWork) bool {
803+
func (w *SyncWork) calculateNextFrom(desired *SyncWork) (bool, bool) {
785804
sameVersion, sameOverrides, sameCapabilities, sameFeatureGates := equalSyncWork(w, desired, "calculating next work")
786805
changed := !(sameVersion && sameOverrides && sameCapabilities && sameFeatureGates)
787806

@@ -803,8 +822,9 @@ func (w *SyncWork) calculateNextFrom(desired *SyncWork) bool {
803822
}
804823

805824
w.Generation = desired.Generation
825+
w.EnabledFeatureGates = desired.EnabledFeatureGates.Clone()
806826

807-
return changed
827+
return changed, !sameFeatureGates
808828
}
809829

810830
// equalUpdate returns true if two updates are semantically equivalent.

0 commit comments

Comments
 (0)