This repository was archived by the owner on May 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +33
-8
lines changed
Expand file tree Collapse file tree 3 files changed +33
-8
lines changed Original file line number Diff line number Diff line change @@ -552,15 +552,11 @@ func (observer *ClusterStateObserver) truncateHistory(observed *ObservedClusterS
552552 historyLimit = 10
553553 }
554554
555- history := make ([]* appsv1.ControllerRevision , 0 , len (revisions ))
556- historyLen := len (history )
557- if historyLen <= historyLimit {
558- return nil
559- }
555+ nonLiveHistory := getNonLiveHistory (revisions , historyLimit )
556+
560557 // delete any non-live history to maintain the revision limit.
561- history = history [:(historyLen - historyLimit )]
562- for i := 0 ; i < len (history ); i ++ {
563- if err := observer .history .DeleteControllerRevision (history [i ]); err != nil {
558+ for i := 0 ; i < len (nonLiveHistory ); i ++ {
559+ if err := observer .history .DeleteControllerRevision (nonLiveHistory [i ]); err != nil {
564560 return err
565561 }
566562 }
Original file line number Diff line number Diff line change @@ -519,3 +519,17 @@ func getUpdateState(observed ObservedClusterState) UpdateState {
519519 }
520520 return UpdateStateUpdating
521521}
522+
523+ func getNonLiveHistory (revisions []* appsv1.ControllerRevision , historyLimit int ) []* appsv1.ControllerRevision {
524+
525+ history := append ([]* appsv1.ControllerRevision {}, revisions ... )
526+ nonLiveHistory := make ([]* appsv1.ControllerRevision , 0 )
527+
528+ historyLen := len (history )
529+ if historyLen <= historyLimit {
530+ return nonLiveHistory
531+ }
532+
533+ nonLiveHistory = append (nonLiveHistory , history [:(historyLen - historyLimit )]... )
534+ return nonLiveHistory
535+ }
Original file line number Diff line number Diff line change @@ -553,3 +553,18 @@ func TestGetFlinkAPIBaseURL(t *testing.T) {
553553 apiBaseURL = getFlinkAPIBaseURL (& cluster )
554554 assert .Equal (t , apiBaseURL , "http://mycluster-jobmanager.default.svc.my.domain:8004" )
555555}
556+
557+ func TestGetNonLiveHistory (t * testing.T ) {
558+ revison0 := appsv1.ControllerRevision {Revision : int64 (0 )}
559+ revison1 := appsv1.ControllerRevision {Revision : int64 (1 )}
560+ revisions := []* appsv1.ControllerRevision {& revison0 , & revison1 }
561+
562+ historyLimit := 1
563+ nonLiveHistory := getNonLiveHistory (revisions , historyLimit )
564+ assert .Equal (t , len (nonLiveHistory ), 1 )
565+ assert .Equal (t , nonLiveHistory [0 ].Revision , int64 (0 ))
566+
567+ historyLimit = 3
568+ nonLiveHistory = getNonLiveHistory (revisions , historyLimit )
569+ assert .Equal (t , len (nonLiveHistory ), 0 )
570+ }
You can’t perform that action at this time.
0 commit comments