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 d163cca
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/infrastructure/kubernetes/applier/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d163cca

Please sign in to comment.