From 14e281dfa92101eb88a2e870e9a41884468b344e Mon Sep 17 00:00:00 2001 From: ChrisLiu <70144550+chrisliu1995@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:43:50 +0800 Subject: [PATCH] fix old svc remain after pod recreate when using ali-lb models (#165) Signed-off-by: ChrisLiu --- cloudprovider/alibabacloud/nlb.go | 6 ++++++ cloudprovider/alibabacloud/slb.go | 6 ++++++ pkg/util/hash_test.go | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/cloudprovider/alibabacloud/nlb.go b/cloudprovider/alibabacloud/nlb.go index 21250b60..724925c5 100644 --- a/cloudprovider/alibabacloud/nlb.go +++ b/cloudprovider/alibabacloud/nlb.go @@ -155,6 +155,12 @@ func (n *NlbPlugin) OnPodUpdated(c client.Client, pod *corev1.Pod, ctx context.C return pod, cperrors.NewPluginError(cperrors.ApiCallError, err.Error()) } + // old svc remain + if svc.OwnerReferences[0].Kind == "Pod" && svc.OwnerReferences[0].UID != pod.UID { + 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) + return pod, nil + } + // update svc if util.GetHash(sc) != svc.GetAnnotations()[SlbConfigHashKey] { networkStatus.CurrentNetworkState = gamekruiseiov1alpha1.NetworkNotReady diff --git a/cloudprovider/alibabacloud/slb.go b/cloudprovider/alibabacloud/slb.go index 8b259f33..5777576b 100644 --- a/cloudprovider/alibabacloud/slb.go +++ b/cloudprovider/alibabacloud/slb.go @@ -181,6 +181,12 @@ func (s *SlbPlugin) OnPodUpdated(c client.Client, pod *corev1.Pod, ctx context.C return pod, cperrors.NewPluginError(cperrors.ApiCallError, err.Error()) } + // old svc remain + if svc.OwnerReferences[0].Kind == "Pod" && svc.OwnerReferences[0].UID != pod.UID { + log.Infof("[%s] waitting old svc %s/%s deleted. old owner pod uid is %s, but now is %s", SlbNetwork, svc.Namespace, svc.Name, svc.OwnerReferences[0].UID, pod.UID) + return pod, nil + } + // update svc if util.GetHash(sc) != svc.GetAnnotations()[SlbConfigHashKey] { networkStatus.CurrentNetworkState = gamekruiseiov1alpha1.NetworkNotReady diff --git a/pkg/util/hash_test.go b/pkg/util/hash_test.go index 695cbc32..c9977ea6 100644 --- a/pkg/util/hash_test.go +++ b/pkg/util/hash_test.go @@ -55,6 +55,27 @@ func TestGetHash(t *testing.T) { objectB: nil, result: true, }, + { + objectA: &corev1.Pod{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "containerA", + }, + }, + }, + }, + objectB: &corev1.Pod{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "containerB", + }, + }, + }, + }, + result: false, + }, } for _, test := range tests {