From d163cca5ad766a9624882b7030906d7484e8099d 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/infrastructure/kubernetes/applier/apply.go b/internal/infrastructure/kubernetes/applier/apply.go index 6aa7f751d6ce..e4ca3a33ef5b 100644 --- a/internal/infrastructure/kubernetes/applier/apply.go +++ b/internal/infrastructure/kubernetes/applier/apply.go @@ -122,7 +122,13 @@ 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. + var currentPortsWithoutNP []corev1.ServicePort + for _, port := range current.Spec.Ports { + port.NodePort = 0 + currentPortsWithoutNP = append(currentPortsWithoutNP, port) + } + if !reflect.DeepEqual(svc.Spec.Selector, current.Spec.Selector) && !reflect.DeepEqual(svc.Spec.Selector, currentPortsWithoutNP) { svc.ResourceVersion = current.ResourceVersion svc.UID = current.UID if err := i.Client.Update(ctx, svc); err != nil {