Skip to content

Commit

Permalink
bugfix #1340: not compare all svc.spec for user modified scene
Browse files Browse the repository at this point in the history
Signed-off-by: spwangxp <[email protected]>
  • Loading branch information
spwangxp committed Apr 23, 2023
1 parent 690a045 commit 1ddf9d3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/infrastructure/kubernetes/applier/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1ddf9d3

Please sign in to comment.