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 ee66fdf
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions pkg/controllers/collaset/synccontrol/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func decidePodToUpdateByPartition(
return podToUpdate
}

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

func decideNotCreatedOldPods(
func decideNeedUpdateButNotCreate(
podInfos []*PodUpdateInfo,
ownedIDs map[int]*appsv1alpha1.ContextDetail,
updatedRevision *appsv1.ControllerRevision) int {
Expand All @@ -257,21 +257,31 @@ 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)
// ignore updated pod
if !exist || revision == updatedRevision.Name {
continue
}
// ignore replace new pod
if _, exist := contextDetail.Data[ReplaceOriginPodIDContextDataKey]; exist {
continue
}
// ignore scaling in pod
if _, exist := contextDetail.Data[ScaleInContextDataKey]; exist {
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 ee66fdf

Please sign in to comment.