Skip to content

Commit

Permalink
Merge pull request #75 from FabianKramm/main
Browse files Browse the repository at this point in the history
fix: erase node port for kubernetes service sync
  • Loading branch information
FabianKramm authored Jul 5, 2021
2 parents 9253e4d + b1e4105 commit e86fd20
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/controllers/resources/services/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,11 @@ func SyncKubernetesService(ctx context.Context, virtualClient client.Client, loc
return err
}

if vObj.Spec.ClusterIP != pObj.Spec.ClusterIP || !equality.Semantic.DeepEqual(vObj.Spec.Ports, pObj.Spec.Ports) {
translatedPorts := translateKubernetesServicePorts(pObj.Spec.Ports)
if vObj.Spec.ClusterIP != pObj.Spec.ClusterIP || !equality.Semantic.DeepEqual(vObj.Spec.Ports, translatedPorts) {
newService := vObj.DeepCopy()
newService.Spec.ClusterIP = pObj.Spec.ClusterIP
newService.Spec.Ports = pObj.Spec.Ports
newService.Spec.Ports = translatedPorts
if vObj.Spec.ClusterIP != pObj.Spec.ClusterIP {
newService.Spec.ClusterIPs = nil

Expand Down Expand Up @@ -417,3 +418,19 @@ func SyncKubernetesService(ctx context.Context, virtualClient client.Client, loc

return nil
}

func translateKubernetesServicePorts(ports []corev1.ServicePort) []corev1.ServicePort {
retPorts := []corev1.ServicePort{}
for _, p := range ports {
// Delete the NodePort
retPorts = append(retPorts, corev1.ServicePort{
Name: p.Name,
Protocol: p.Protocol,
AppProtocol: p.AppProtocol,
Port: p.Port,
TargetPort: p.TargetPort,
})
}

return retPorts
}

0 comments on commit e86fd20

Please sign in to comment.