From 1ddf9d329c4b972fd229fec4ed85c8d807d69363 Mon Sep 17 00:00:00 2001 From: spwangxp Date: Sun, 23 Apr 2023 14:07:05 +0800 Subject: [PATCH] bugfix #1340: not compare all svc.spec for user modified scene Signed-off-by: spwangxp --- internal/infrastructure/kubernetes/applier/apply.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/infrastructure/kubernetes/applier/apply.go b/internal/infrastructure/kubernetes/applier/apply.go index 6aa7f751d6ce..b0441dc0d9d5 100644 --- a/internal/infrastructure/kubernetes/applier/apply.go +++ b/internal/infrastructure/kubernetes/applier/apply.go @@ -8,6 +8,8 @@ package applier import ( "context" "fmt" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "reflect" appsv1 "k8s.io/api/apps/v1" @@ -122,7 +124,9 @@ func (i *Instance) CreateOrUpdateService(ctx context.Context, svc *corev1.Servic } } else { // Update if current value is different. - if !reflect.DeepEqual(svc.Spec, current.Spec) { + // Only compare the selector and ports(not include nodePort) in case user have modified for some scene. + if !cmp.Equal(svc.Spec.Selector, current.Spec.Selector) && + !cmp.Equal(svc.Spec.Ports, current.Spec.Ports, cmpopts.IgnoreFields(corev1.ServicePort{}, "NodePort")) { svc.ResourceVersion = current.ResourceVersion svc.UID = current.UID if err := i.Client.Update(ctx, svc); err != nil {