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 {