@@ -220,6 +220,26 @@ func (r *RealSyncControl) SyncTargets(ctx context.Context, instance api.XSetObje
220220 }
221221 }
222222
223+ // sync decoration revisions
224+ var decorationInfo DecorationInfo
225+ if decorationAdapter , enabled := r .xsetController .(api.DecorationAdapter ); enabled {
226+ if decorationInfo .DecorationCurrentRevisions , err = decorationAdapter .GetTargetCurrentDecorationRevisions (ctx , r .Client , target ); err != nil {
227+ return false , err
228+ }
229+ if decorationInfo .DecorationUpdatedRevisions , err = decorationAdapter .GetTargetUpdatedDecorationRevisions (ctx , r .Client , target ); err != nil {
230+ return false , err
231+ }
232+ if decorationInfo .DecorationChanged , err = decorationAdapter .IsTargetDecorationChanged (decorationInfo .DecorationCurrentRevisions , decorationInfo .DecorationUpdatedRevisions ); err != nil {
233+ return false , err
234+ }
235+ }
236+
237+ // sync target ops priority
238+ var opsPriority * api.OpsPriority
239+ if opsPriority , err = r .xsetController .GetXOpsPriority (ctx , r .Client , target ); err != nil {
240+ return false , err
241+ }
242+
223243 targetWrappers = append (targetWrappers , & TargetWrapper {
224244 Object : target ,
225245 ID : id ,
@@ -231,6 +251,9 @@ func (r *RealSyncControl) SyncTargets(ctx context.Context, instance api.XSetObje
231251
232252 IsDuringScaleInOps : opslifecycle .IsDuringOps (r .updateConfig .XsetLabelAnnoMgr , r .scaleInLifecycleAdapter , target ),
233253 IsDuringUpdateOps : opslifecycle .IsDuringOps (r .updateConfig .XsetLabelAnnoMgr , r .updateLifecycleAdapter , target ),
254+
255+ DecorationInfo : decorationInfo ,
256+ OpsPriority : opsPriority ,
234257 })
235258
236259 if id >= 0 {
@@ -395,7 +418,7 @@ func (r *RealSyncControl) Replace(ctx context.Context, xsetObject api.XSetObject
395418 syncContext .replacingMap = classifyTargetReplacingMapping (r .xsetLabelAnnoMgr , syncContext .activeTargets )
396419 }()
397420
398- needReplaceOriginTargets , needCleanLabelTargets , targetsNeedCleanLabels , needDeleteTargets := r .dealReplaceTargets (ctx , syncContext .FilteredTarget )
421+ needReplaceOriginTargets , needCleanLabelTargets , targetsNeedCleanLabels , needDeleteTargets := r .dealReplaceTargets (ctx , syncContext .TargetWrappers )
399422
400423 // delete origin targets for replace
401424 err = r .BatchDeleteTargetsByLabel (ctx , r .xControl , needDeleteTargets )
@@ -516,18 +539,18 @@ func (r *RealSyncControl) Scale(ctx context.Context, xsetObject api.XSetObject,
516539 if decorationAdapter , ok := r .xsetController .(api.DecorationAdapter ); ok {
517540 revisionsInfo , ok := r .resourceContextControl .Get (availableIDContext , api .EnumTargetDecorationRevisionKey )
518541 if ! ok {
519- needUpdateContext .Store (true )
520- revisions , err := decorationAdapter .GetDecorationRevisionFromTarget (ctx , object )
521- if err != nil {
542+ // get updated decoration revisions from target and write to resource context
543+ if revisionsInfo , err = decorationAdapter .GetTargetUpdatedDecorationRevisions (ctx , r .Client , object ); err != nil {
522544 return err
523545 }
524- r .resourceContextControl .Put (availableIDContext , api .EnumTargetDecorationRevisionKey , revisions )
525- patcherFn := decorationAdapter .GetDecorationPatcherFromTarget (ctx , object )
526- return patcherFn (object )
546+ r .resourceContextControl .Put (availableIDContext , api .EnumTargetDecorationRevisionKey , revisionsInfo )
547+ needUpdateContext .Store (true )
548+ }
549+ // get patcher from decoration revisions and patch target
550+ if fn , err := decorationAdapter .GetDecorationPatcherByRevisions (ctx , r .Client , object , revisionsInfo ); err != nil {
551+ return err
527552 } else {
528- // upgrade by recreate target case
529- patcherFn := decorationAdapter .GetDecorationPatcherFromRevisions (ctx , revisionsInfo )
530- return patcherFn (object )
553+ return fn (object )
531554 }
532555 }
533556 return nil
@@ -571,10 +594,6 @@ func (r *RealSyncControl) Scale(ctx context.Context, xsetObject api.XSetObject,
571594 }
572595
573596 if diff <= 0 {
574- // get targets ops priority
575- if err := r .getTargetsOpsPriority (ctx , r .Client , syncContext .activeTargets ); err != nil {
576- return false , recordedRequeueAfter , err
577- }
578597 // chose the targets to scale in
579598 targetsToScaleIn := r .getTargetsToDelete (xsetObject , syncContext .activeTargets , syncContext .replacingMap , diff * - 1 )
580599 // filter out Targets need to trigger TargetOpsLifecycle
@@ -725,11 +744,6 @@ func (r *RealSyncControl) Update(ctx context.Context, xsetObject api.XSetObject,
725744 var err error
726745 var recordedRequeueAfter * time.Duration
727746
728- // 0. get targets ops priority
729- if err := r .getTargetsOpsPriority (ctx , r .Client , syncContext .TargetWrappers ); err != nil {
730- return false , recordedRequeueAfter , err
731- }
732-
733747 // 1. scan and analysis targets update info for active targets and PlaceHolder targets
734748 targetUpdateInfos , err := r .attachTargetUpdateInfo (ctx , xsetObject , syncContext )
735749 if err != nil {
@@ -746,7 +760,7 @@ func (r *RealSyncControl) Update(ctx context.Context, xsetObject api.XSetObject,
746760 // 3. filter already updated revision,
747761 for i , targetInfo := range targetToUpdate {
748762 // TODO check decoration and pvc template changed
749- if targetInfo .IsUpdatedRevision && ! targetInfo .PvcTmpHashChanged {
763+ if targetInfo .IsUpdatedRevision && ! targetInfo .PvcTmpHashChanged && ! targetInfo . DecorationChanged {
750764 continue
751765 }
752766
@@ -1007,22 +1021,6 @@ func (r *RealSyncControl) reclaimOwnedIDs(
10071021 return nil
10081022}
10091023
1010- // getTargetsOpsPriority try to set targets' ops priority
1011- func (r * RealSyncControl ) getTargetsOpsPriority (ctx context.Context , c client.Client , targets []* TargetWrapper ) error {
1012- _ , err := controllerutils .SlowStartBatch (len (targets ), controllerutils .SlowStartInitialBatchSize , true , func (i int , _ error ) error {
1013- if targets [i ].PlaceHolder || targets [i ].Object == nil || targets [i ].OpsPriority != nil {
1014- return nil
1015- }
1016- var iErr error
1017- targets [i ].OpsPriority , iErr = r .xsetController .GetXOpsPriority (ctx , c , targets [i ].Object )
1018- if iErr != nil {
1019- return fmt .Errorf ("failed to get target %s/%s ops priority: %w" , targets [i ].Object .GetNamespace (), targets [i ].Object .GetName (), iErr )
1020- }
1021- return nil
1022- })
1023- return err
1024- }
1025-
10261024// FilterOutActiveTargetWrappers filter out non placeholder targets
10271025func FilterOutActiveTargetWrappers (targets []* TargetWrapper ) []* TargetWrapper {
10281026 var filteredTargetWrappers []* TargetWrapper
0 commit comments