Skip to content

Commit

Permalink
decideNeedUpdateButNotCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdsteelRail committed Jun 13, 2024
1 parent 0239c1b commit a9862ba
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pkg/controllers/collaset/synccontrol/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,18 @@ func decidePodToUpdateByPartition(
return podToUpdate
}

notCreatedOld := minInt(partition, decideNotCreatedOldPods(podInfos, ownedIDs, updatedRevision))
podToUpdate = ordered[:podsNum-partition+notCreatedOld]
for i := podsNum - partition; i < podsNum; i++ {
moreToUpdate := minInt(partition, decideNeedUpdateButNotCreate(podInfos, ownedIDs, updatedRevision))
updateNum := podsNum - partition + moreToUpdate
podToUpdate = ordered[:updateNum]
for i := updateNum; i < podsNum; i++ {
if podInfos[i].PodDecorationChanged {
podToUpdate = append(podToUpdate, podInfos[i])
}
}
return podToUpdate
}

func decideNotCreatedOldPods(
func decideNeedUpdateButNotCreate(
podInfos []*PodUpdateInfo,
ownedIDs map[int]*appsv1alpha1.ContextDetail,
updatedRevision *appsv1.ControllerRevision) int {
Expand All @@ -257,21 +258,26 @@ func decideNotCreatedOldPods(
mapIDToPod[id] = pod
}

var idToUpdate []*appsv1alpha1.ContextDetail
var needUpdatePodsId []*appsv1alpha1.ContextDetail
for _, contextDetail := range ownedIDs {
revision, exist := contextDetail.Data[podcontext.RevisionContextDataKey]
if exist && revision != updatedRevision.Name {
idToUpdate = append(idToUpdate, contextDetail)
if !exist || revision == updatedRevision.Name {
continue
}
// never update replaceNew and scaleIn pod
if contextDetail.Data[ReplaceOriginPodIDContextDataKey] != "" || contextDetail.Data[ScaleInContextDataKey] != "" {
continue
}
needUpdatePodsId = append(needUpdatePodsId, contextDetail)
}

notCreated := 0
for _, contextDetail := range idToUpdate {
needUpdateButNotCreate := 0
for _, contextDetail := range needUpdatePodsId {
if _, exist := mapIDToPod[strconv.Itoa(contextDetail.ID)]; !exist {
notCreated++
needUpdateButNotCreate++
}
}
return notCreated
return needUpdateButNotCreate
}

// filter these pods in replacing and is new created pod
Expand Down

0 comments on commit a9862ba

Please sign in to comment.