Skip to content

Commit 001f73a

Browse files
authored
Merge pull request #278 from hhyasdf/release/v0.5.1
[CHERRY PICK] fix address duplication error while active-standby switch happens
2 parents 69861de + 1680097 commit 001f73a

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

cmd/manager/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ func main() {
116116
}
117117
}()
118118

119+
// Initialization should be after leader election success
120+
<-mgr.Elected()
121+
119122
// wait for manager cache client ready
120123
mgr.GetCache().WaitForCacheSync(globalContext)
121124

pkg/controllers/networking/pod_controller.go

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ func (r *PodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result
129129
(len(ipInstanceList) == 2 && ipFamily == ipamtypes.DualStack) {
130130
return ctrl.Result{}, nil
131131
}
132+
133+
if len(ipInstanceList) > 0 {
134+
return ctrl.Result{}, fmt.Errorf("duplicated ip instances exist for pod: %v/%v, pod ip family is %v",
135+
pod.Namespace, pod.Name, ipFamily)
136+
}
132137
}
133138

134139
networkName, err = r.selectNetwork(ctx, pod)

pkg/controllers/networking/pod_ip_cache.go

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ func NewPodIPCache(ctx context.Context, c client.Reader, logger logr.Logger) (Po
9999
recordedIPInstances = cache.podToIP[namespacedKey(podName, ip.Namespace)].ipInstanceNames
100100
}
101101

102+
logger.V(1).Info("add record to init cache", "ip",
103+
ip.Name, "namespace", ip.Namespace, "pod", podName, "pod uid", podUID)
104+
102105
// this is different from a normal Record action
103106
cache.podToIP[namespacedKey(podName, ip.Namespace)] = &podAllocatedInfo{
104107
podUID: podUID,

0 commit comments

Comments
 (0)