Skip to content

Commit

Permalink
filter out onlyPlaceHolder origin pods in update
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdsteelRail committed Jun 30, 2024
1 parent 480dafc commit bc1b723
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pkg/controllers/collaset/collaset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ func calculateStatus(
var scheduledReplicas, readyReplicas, availableReplicas, replicas, updatedReplicas, operatingReplicas,
updatedReadyReplicas, updatedAvailableReplicas int32

currentPods := synccontrol.FilterOutOnlyPlaceholderPods(podWrappers)
for _, podWrapper := range currentPods {
activePods := synccontrol.FilterOutOnlyPlaceHolderPodWrappers(podWrappers)
for _, podWrapper := range activePods {
replicas++

isUpdated := false
Expand Down
16 changes: 8 additions & 8 deletions pkg/controllers/collaset/synccontrol/sync_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,15 @@ func (r *RealSyncControl) Scale(

logger := r.logger.WithValues("collaset", commonutils.ObjectKeyString(cls))
var recordedRequeueAfter *time.Duration
currentPods := FilterOutOnlyPlaceholderPods(podWrappers)
replacePodMap := classifyPodReplacingMapping(currentPods)
activePods := FilterOutOnlyPlaceHolderPodWrappers(podWrappers)
replacePodMap := classifyPodReplacingMapping(activePods)

diff := int(realValue(cls.Spec.Replicas)) - len(replacePodMap)
scaling := false

if diff >= 0 {
// trigger delete pods indicated in ScaleStrategy.PodToDelete by label
for _, podWrapper := range currentPods {
for _, podWrapper := range activePods {
if podWrapper.ToDelete {
err := r.deletePodsByLabel([]*corev1.Pod{podWrapper.Pod})
if err != nil {
Expand All @@ -492,7 +492,7 @@ func (r *RealSyncControl) Scale(
// scale out pods and return if diff > 0
if diff > 0 {
// collect instance ID in used from owned Pods
podInstanceIDSet := collasetutils.CollectPodInstanceID(currentPods)
podInstanceIDSet := collasetutils.CollectPodInstanceID(activePods)
// find IDs and their contexts which have not been used by owned Pods
availableContext := extractAvailableContexts(diff, ownedIDs, podInstanceIDSet)
needUpdateContext := false
Expand Down Expand Up @@ -581,7 +581,7 @@ func (r *RealSyncControl) Scale(
}
} else if diff < 0 {
// chose the pods to scale in
podsToScaleIn := getPodsToDelete(currentPods, replacePodMap, diff*-1)
podsToScaleIn := getPodsToDelete(activePods, replacePodMap, diff*-1)
// filter out Pods need to trigger PodOpsLifecycle
podCh := make(chan *collasetutils.PodWrapper, len(podsToScaleIn))
for i := range podsToScaleIn {
Expand Down Expand Up @@ -701,7 +701,7 @@ func (r *RealSyncControl) Scale(

// reset ContextDetail.ScalingIn, if there are Pods had its PodOpsLifecycle reverted
needUpdatePodContext := false
for _, podWrapper := range currentPods {
for _, podWrapper := range activePods {
if !podopslifecycle.IsDuringOps(collasetutils.ScaleInOpsLifecycleAdapter, podWrapper) && ownedIDs[podWrapper.ID].Contains(ScaleInContextDataKey, "true") {
needUpdatePodContext = true
ownedIDs[podWrapper.ID].Remove(ScaleInContextDataKey)
Expand All @@ -720,7 +720,7 @@ func (r *RealSyncControl) Scale(
return scaling, recordedRequeueAfter, nil
}

func FilterOutOnlyPlaceholderPods(pods []*collasetutils.PodWrapper) []*collasetutils.PodWrapper {
func FilterOutOnlyPlaceHolderPodWrappers(pods []*collasetutils.PodWrapper) []*collasetutils.PodWrapper {
var filteredPodWrappers []*collasetutils.PodWrapper
for _, pod := range pods {
if pod.OnlyPlaceholder {
Expand Down Expand Up @@ -840,7 +840,7 @@ func (r *RealSyncControl) Update(

// 2. decide Pod update candidates
candidates := decidePodToUpdate(cls, podUpdateInfos)
podToUpdate := filterOnlyPlaceholderInfos(candidates)
podToUpdate := filterOutOnlyPlaceHolderUpdateInfos(candidates)
podCh := make(chan *PodUpdateInfo, len(podToUpdate))
updater := newPodUpdater(ctx, r.client, cls, r.podControl, r.recorder)
updating := false
Expand Down
25 changes: 14 additions & 11 deletions pkg/controllers/collaset/synccontrol/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ type PodUpdateInfo struct {
}

func attachPodUpdateInfo(ctx context.Context, cls *appsv1alpha1.CollaSet, pods []*collasetutils.PodWrapper, resource *collasetutils.RelatedResources) ([]*PodUpdateInfo, error) {
currentPods := FilterOutOnlyPlaceholderPods(pods)
podUpdateInfoList := make([]*PodUpdateInfo, len(currentPods))
activePods := FilterOutOnlyPlaceHolderPodWrappers(pods)
podUpdateInfoList := make([]*PodUpdateInfo, len(activePods))

for i, pod := range currentPods {
for i, pod := range activePods {
updateInfo := &PodUpdateInfo{
PodWrapper: pod,
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func attachPodUpdateInfo(ctx context.Context, cls *appsv1alpha1.CollaSet, pods [
for _, podUpdateInfo := range podUpdateInfoList {
podUpdateInfoMap[podUpdateInfo.Name] = podUpdateInfo
}
replacePodMap := classifyPodReplacingMapping(currentPods)
replacePodMap := classifyPodReplacingMapping(activePods)
for originPodName, replacePairNewPod := range replacePodMap {
originPodInfo := podUpdateInfoMap[originPodName]
if replacePairNewPod != nil {
Expand Down Expand Up @@ -191,7 +191,7 @@ func attachPodUpdateInfo(ctx context.Context, cls *appsv1alpha1.CollaSet, pods [
return podUpdateInfoList, nil
}

func filterOnlyPlaceholderInfos(pods []*PodUpdateInfo) []*PodUpdateInfo {
func filterOutOnlyPlaceHolderUpdateInfos(pods []*PodUpdateInfo) []*PodUpdateInfo {
var filteredPodUpdateInfos []*PodUpdateInfo
for _, pod := range pods {
if pod.OnlyPlaceholder {
Expand All @@ -207,8 +207,8 @@ func decidePodToUpdate(
podInfos []*PodUpdateInfo) []*PodUpdateInfo {

if cls.Spec.UpdateStrategy.RollingUpdate != nil && cls.Spec.UpdateStrategy.RollingUpdate.ByLabel != nil {
currentPodInfos := filterOnlyPlaceholderInfos(podInfos)
return decidePodToUpdateByLabel(cls, currentPodInfos)
activePodInfos := filterOutOnlyPlaceHolderUpdateInfos(podInfos)
return decidePodToUpdateByLabel(cls, activePodInfos)
}

return decidePodToUpdateByPartition(cls, podInfos)
Expand Down Expand Up @@ -274,9 +274,12 @@ func filterReplacingNewCreatedPod(podInfos []*PodUpdateInfo) (filteredPodInfos [
continue
}

_, exist := podInfo.ContextDetail.Data[ReplaceOriginPodIDContextDataKey]
if exist && podInfo.OnlyPlaceholder {
continue
if podInfo.OnlyPlaceholder {
_, isReplaceNewPod := podInfo.ContextDetail.Data[ReplaceOriginPodIDContextDataKey]
_, isReplaceOriginPod := podInfo.ContextDetail.Data[ReplaceNewPodIDContextDataKey]
if isReplaceNewPod || isReplaceOriginPod {
continue
}
}

filteredPodInfos = append(filteredPodInfos, podInfo)
Expand Down Expand Up @@ -780,7 +783,7 @@ func (u *replaceUpdatePodUpdater) BeginUpdatePod(resources *collasetutils.Relate
}

func (u *replaceUpdatePodUpdater) FilterAllowOpsPods(candidates []*PodUpdateInfo, _ map[int]*appsv1alpha1.ContextDetail, _ *collasetutils.RelatedResources, podCh chan *PodUpdateInfo) (requeueAfter *time.Duration, err error) {
podToUpdate := filterOnlyPlaceholderInfos(candidates)
podToUpdate := filterOutOnlyPlaceHolderUpdateInfos(candidates)
for i, podInfo := range podToUpdate {
if podInfo.IsUpdatedRevision && !podInfo.PodDecorationChanged && !podInfo.PvcTmpHashChanged {
continue
Expand Down

0 comments on commit bc1b723

Please sign in to comment.