@@ -220,6 +220,26 @@ func (r *RealSyncControl) SyncTargets(ctx context.Context, instance api.XSetObje
220
220
}
221
221
}
222
222
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
+
223
243
targetWrappers = append (targetWrappers , & TargetWrapper {
224
244
Object : target ,
225
245
ID : id ,
@@ -231,6 +251,9 @@ func (r *RealSyncControl) SyncTargets(ctx context.Context, instance api.XSetObje
231
251
232
252
IsDuringScaleInOps : opslifecycle .IsDuringOps (r .updateConfig .XsetLabelAnnoMgr , r .scaleInLifecycleAdapter , target ),
233
253
IsDuringUpdateOps : opslifecycle .IsDuringOps (r .updateConfig .XsetLabelAnnoMgr , r .updateLifecycleAdapter , target ),
254
+
255
+ DecorationInfo : decorationInfo ,
256
+ OpsPriority : opsPriority ,
234
257
})
235
258
236
259
if id >= 0 {
@@ -395,7 +418,7 @@ func (r *RealSyncControl) Replace(ctx context.Context, xsetObject api.XSetObject
395
418
syncContext .replacingMap = classifyTargetReplacingMapping (r .xsetLabelAnnoMgr , syncContext .activeTargets )
396
419
}()
397
420
398
- needReplaceOriginTargets , needCleanLabelTargets , targetsNeedCleanLabels , needDeleteTargets := r .dealReplaceTargets (ctx , syncContext .FilteredTarget )
421
+ needReplaceOriginTargets , needCleanLabelTargets , targetsNeedCleanLabels , needDeleteTargets := r .dealReplaceTargets (ctx , syncContext .TargetWrappers )
399
422
400
423
// delete origin targets for replace
401
424
err = r .BatchDeleteTargetsByLabel (ctx , r .xControl , needDeleteTargets )
@@ -516,18 +539,18 @@ func (r *RealSyncControl) Scale(ctx context.Context, xsetObject api.XSetObject,
516
539
if decorationAdapter , ok := r .xsetController .(api.DecorationAdapter ); ok {
517
540
revisionsInfo , ok := r .resourceContextControl .Get (availableIDContext , api .EnumTargetDecorationRevisionKey )
518
541
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 {
522
544
return err
523
545
}
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
527
552
} else {
528
- // upgrade by recreate target case
529
- patcherFn := decorationAdapter .GetDecorationPatcherFromRevisions (ctx , revisionsInfo )
530
- return patcherFn (object )
553
+ return fn (object )
531
554
}
532
555
}
533
556
return nil
@@ -571,10 +594,6 @@ func (r *RealSyncControl) Scale(ctx context.Context, xsetObject api.XSetObject,
571
594
}
572
595
573
596
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
- }
578
597
// chose the targets to scale in
579
598
targetsToScaleIn := r .getTargetsToDelete (xsetObject , syncContext .activeTargets , syncContext .replacingMap , diff * - 1 )
580
599
// filter out Targets need to trigger TargetOpsLifecycle
@@ -725,11 +744,6 @@ func (r *RealSyncControl) Update(ctx context.Context, xsetObject api.XSetObject,
725
744
var err error
726
745
var recordedRequeueAfter * time.Duration
727
746
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
-
733
747
// 1. scan and analysis targets update info for active targets and PlaceHolder targets
734
748
targetUpdateInfos , err := r .attachTargetUpdateInfo (ctx , xsetObject , syncContext )
735
749
if err != nil {
@@ -746,7 +760,7 @@ func (r *RealSyncControl) Update(ctx context.Context, xsetObject api.XSetObject,
746
760
// 3. filter already updated revision,
747
761
for i , targetInfo := range targetToUpdate {
748
762
// TODO check decoration and pvc template changed
749
- if targetInfo .IsUpdatedRevision && ! targetInfo .PvcTmpHashChanged {
763
+ if targetInfo .IsUpdatedRevision && ! targetInfo .PvcTmpHashChanged && ! targetInfo . DecorationChanged {
750
764
continue
751
765
}
752
766
@@ -1007,22 +1021,6 @@ func (r *RealSyncControl) reclaimOwnedIDs(
1007
1021
return nil
1008
1022
}
1009
1023
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
-
1026
1024
// FilterOutActiveTargetWrappers filter out non placeholder targets
1027
1025
func FilterOutActiveTargetWrappers (targets []* TargetWrapper ) []* TargetWrapper {
1028
1026
var filteredTargetWrappers []* TargetWrapper
0 commit comments