Skip to content

Commit f9ab0af

Browse files
author
yujiel
committed
Fixed the issue where the service could not change from Loadbalancer to ClusterIP/NodePort
Signed-off-by: yujiel <yujiel@ebtech.com>
1 parent 0c93504 commit f9ab0af

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/controllers/resources/services/syncer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func (s *serviceSyncer) Sync(ctx *synccontext.SyncContext, event *synccontext.Sy
192192

193193
// update status
194194
event.Virtual.Status = event.Host.Status
195+
ensureLoadBalancerStatus(event.Virtual)
195196

196197
// bi-directional sync of annotations and labels
197198
event.Virtual.Annotations, event.Host.Annotations = translate.AnnotationsBidirectionalUpdate(event, s.excludedAnnotations...)
@@ -299,3 +300,17 @@ func TranslateServicePorts(ports []corev1.ServicePort) []corev1.ServicePort {
299300

300301
return retPorts
301302
}
303+
304+
// ensureLoadBalancerStatus removes any LoadBalancer-related fields from the Service
305+
// if it is of type ClusterIP.
306+
//
307+
// This is necessary to ensure consistency when syncing services from a virtual
308+
// cluster to the host cluster. ClusterIP services should not carry LoadBalancer
309+
// settings such as LoadBalancerIP or Status.LoadBalancer.Ingress, which are
310+
// specific to LoadBalancer-type services and can cause incorrect behavior if retained.
311+
func ensureLoadBalancerStatus(vObj *corev1.Service) {
312+
if vObj.Spec.Type != corev1.ServiceTypeLoadBalancer {
313+
vObj.Spec.LoadBalancerIP = ""
314+
vObj.Status.LoadBalancer.Ingress = make([]corev1.LoadBalancerIngress, 0)
315+
}
316+
}

0 commit comments

Comments
 (0)