Skip to content

Commit d6caf18

Browse files
committed
fix old svc remain after pod recreate when using ali-lb models
Signed-off-by: ChrisLiu <[email protected]>
1 parent b3991f2 commit d6caf18

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

cloudprovider/alibabacloud/nlb.go

+6
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ func (n *NlbPlugin) OnPodUpdated(c client.Client, pod *corev1.Pod, ctx context.C
155155
return pod, cperrors.NewPluginError(cperrors.ApiCallError, err.Error())
156156
}
157157

158+
// old svc remain
159+
if svc.OwnerReferences[0].Kind == "Pod" && svc.OwnerReferences[0].UID != pod.UID {
160+
log.Infof("[%s] waitting old svc %s/%s deleted. old owner pod uid is %s, but now is %s", NlbNetwork, svc.Namespace, svc.Name, svc.OwnerReferences[0].UID, pod.UID)
161+
return pod, nil
162+
}
163+
158164
// update svc
159165
if util.GetHash(sc) != svc.GetAnnotations()[SlbConfigHashKey] {
160166
networkStatus.CurrentNetworkState = gamekruiseiov1alpha1.NetworkNotReady

cloudprovider/alibabacloud/slb.go

+6
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ func (s *SlbPlugin) OnPodUpdated(c client.Client, pod *corev1.Pod, ctx context.C
181181
return pod, cperrors.NewPluginError(cperrors.ApiCallError, err.Error())
182182
}
183183

184+
// old svc remain
185+
if svc.OwnerReferences[0].Kind == "Pod" && svc.OwnerReferences[0].UID != pod.UID {
186+
log.Infof("[%s] waitting old svc %s/%s deleted. old owner pod uid is %s, but now is %s", NlbNetwork, svc.Namespace, svc.Name, svc.OwnerReferences[0].UID, pod.UID)
187+
return pod, nil
188+
}
189+
184190
// update svc
185191
if util.GetHash(sc) != svc.GetAnnotations()[SlbConfigHashKey] {
186192
networkStatus.CurrentNetworkState = gamekruiseiov1alpha1.NetworkNotReady

pkg/util/hash_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ func TestGetHash(t *testing.T) {
5555
objectB: nil,
5656
result: true,
5757
},
58+
{
59+
objectA: &corev1.Pod{
60+
Spec: corev1.PodSpec{
61+
Containers: []corev1.Container{
62+
{
63+
Name: "containerA",
64+
},
65+
},
66+
},
67+
},
68+
objectB: &corev1.Pod{
69+
Spec: corev1.PodSpec{
70+
Containers: []corev1.Container{
71+
{
72+
Name: "containerB",
73+
},
74+
},
75+
},
76+
},
77+
result: false,
78+
},
5879
}
5980

6081
for _, test := range tests {

0 commit comments

Comments
 (0)