diff --git a/pkg/ring-controller/agent/vcjobworker.go b/pkg/ring-controller/agent/vcjobworker.go index 38f1aa109a5f85737cc5ce5f12b5a8a22a837ef4..851d9db7b8cb99b7b5ee27584274dd546667153d 100644 --- a/pkg/ring-controller/agent/vcjobworker.go +++ b/pkg/ring-controller/agent/vcjobworker.go @@ -354,17 +354,17 @@ func (b *WorkerInfo) handleAddUpdateEvent(podInfo *podIdentifier, pod *apiCoreV1 if rankExist { return fmt.Errorf("pod %s/%s already has rankIndex: %s", pod.Namespace, pod.Name, rankIndexStr) } + rankIndexStr = strconv.Itoa(int(b.rankIndex)) - err := b.updatePod(pod, func(newPod *apiCoreV1.Pod) { - rankIndexStr = strconv.Itoa(int(b.rankIndex)) - newPod.Annotations[PodRankIndexKey] = rankIndexStr - }) + // Cache device info from the pod + err := b.configmapData.CachePodInfo(pod, instance, rankIndexStr) if err != nil { return err } - // Cache device info from the pod - err = b.configmapData.CachePodInfo(pod, instance, rankIndexStr) + err = b.updatePod(pod, func(newPod *apiCoreV1.Pod) { + newPod.Annotations[PodRankIndexKey] = rankIndexStr + }) if err != nil { return err } diff --git a/pkg/ring-controller/ranktable/v2/ranktable.go b/pkg/ring-controller/ranktable/v2/ranktable.go index aa31ff7af98e0467793374101dbcdc1b7905106d..f270a389fc9f168019a08ffd654b9939f437c912 100644 --- a/pkg/ring-controller/ranktable/v2/ranktable.go +++ b/pkg/ring-controller/ranktable/v2/ranktable.go @@ -47,6 +47,10 @@ func (r *RankTable) BeforeUpdate() { // CachePodInfo :Cache pod info to RankTableV2 func (r *RankTable) CachePodInfo(pod *apiCoreV1.Pod, instance ranktablev1.Instance, rankStr string) error { + if _, ok := r.Servers.Load(pod.UID); ok { + return fmt.Errorf("%s/%s already exists in ranktable", pod.Namespace, pod.Name) + } + rankIndex, err := strconv.Atoi(rankStr) if err != nil { return fmt.Errorf("conv rankStr(%s) to int failed, err: %v", rankStr, err)