Skip to content

Commit 2b13caf

Browse files
fix: replace panic, update panic (#338)
* fix: replace panic, update panic * fix: replace panic, update panic * fix: replace panic, update panic * fix: replace panic, update panic
1 parent d3f3b14 commit 2b13caf

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pkg/controllers/collaset/synccontrol/replace.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func (r *RealSyncControl) replaceOriginPods(
131131
successCount, err := controllerutils.SlowStartBatch(len(needReplaceOriginPods), controllerutils.SlowStartInitialBatchSize, false, func(i int, _ error) error {
132132
originPod := needReplaceOriginPods[i]
133133
originPodId, _ := collasetutils.GetPodInstanceID(originPod)
134+
if ownedIDs[originPodId] == nil {
135+
r.recorder.Eventf(originPod, corev1.EventTypeWarning, "OriginPodContext", "cannot found resource context id %d of origin pod %s/%s", originPodId, originPod.Namespace, originPod.Name)
136+
return fmt.Errorf("cannot found context for replace origin pod %s/%s", originPod.Namespace, originPod.Name)
137+
}
138+
134139
ownerRef := metav1.NewControllerRef(instance, instance.GroupVersionKind())
135140
updatedPDs, err := resources.PDGetter.GetEffective(ctx, originPod)
136141
replaceRevision := getReplaceRevision(originPod, resources)
@@ -155,7 +160,8 @@ func (r *RealSyncControl) replaceOriginPods(
155160
logger.Info("replaceOriginPods", "try to reuse new pod resourceContext id", instanceId)
156161
} else {
157162
if availableContexts[i] == nil {
158-
return fmt.Errorf("cannot found available context for replace new pod when replacing origin pod %s/%s", originPod.Namespace, originPod.Name)
163+
r.recorder.Eventf(originPod, corev1.EventTypeWarning, "AvailableContext", "cannot found available context for replace new pod when replacing origin pod %s/%s", originPod.Namespace, originPod.Name)
164+
return fmt.Errorf("cannot find available context for replace new pod when replacing origin pod %s/%s", originPod.Namespace, originPod.Name)
159165
}
160166
newPodContext = availableContexts[i]
161167
// add replace pair-relation to podContexts for originPod and newPod

pkg/controllers/collaset/synccontrol/update.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ func decidePodToUpdateByPartition(
272272
filteredPodInfos []*PodUpdateInfo) []*PodUpdateInfo {
273273

274274
replicas := ptr.Deref(cls.Spec.Replicas, 0)
275+
currentPodCount := int32(len(filteredPodInfos))
275276
partition := int32(0)
276277
if cls.Spec.UpdateStrategy.RollingUpdate != nil && cls.Spec.UpdateStrategy.RollingUpdate.ByPartition != nil {
277278
partition = ptr.Deref(cls.Spec.UpdateStrategy.RollingUpdate.ByPartition.Partition, 0)
278279
}
279280

280-
//filteredPodInfos := getTargetsUpdatePods(podInfos)
281281
// update all or not update any replicas
282282
if partition == 0 {
283283
return filteredPodInfos
@@ -290,7 +290,7 @@ func decidePodToUpdateByPartition(
290290
ordered := orderByDefault(filteredPodInfos)
291291
sort.Sort(ordered)
292292
podToUpdate := ordered[:replicas-partition]
293-
for i := replicas - partition; i < replicas; i++ {
293+
for i := replicas - partition; i < int32Min(replicas, currentPodCount); i++ {
294294
if ordered[i].PodDecorationChanged {
295295
// separate pd and collaset update progress
296296
filteredPodInfos[i].IsUpdatedRevision = true
@@ -907,3 +907,11 @@ func isPodUpdatedServiceAvailable(podInfo *PodUpdateInfo) (finished bool, msg st
907907

908908
return false, "pod not service available", nil
909909
}
910+
911+
func int32Min(l, r int32) int32 {
912+
if l < r {
913+
return l
914+
}
915+
916+
return r
917+
}

0 commit comments

Comments
 (0)