Skip to content

Fixed the issue where the service could not change from Loadbalancer to ClusterIP/NodePort #2729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/controllers/resources/services/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (s *serviceSyncer) Sync(ctx *synccontext.SyncContext, event *synccontext.Sy

// update status
event.Virtual.Status = event.Host.Status
ensureLoadBalancerStatus(event.Virtual)

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

return retPorts
}

// ensureLoadBalancerStatus removes any LoadBalancer-related fields from the Service
// if it is of type ClusterIP.
//
// This is necessary to ensure consistency when syncing services from a virtual
// cluster to the host cluster. ClusterIP services should not carry LoadBalancer
// settings such as LoadBalancerIP or Status.LoadBalancer.Ingress, which are
// specific to LoadBalancer-type services and can cause incorrect behavior if retained.
func ensureLoadBalancerStatus(vObj *corev1.Service) {
if vObj.Spec.Type != corev1.ServiceTypeLoadBalancer {
vObj.Spec.LoadBalancerIP = ""
vObj.Status.LoadBalancer.Ingress = make([]corev1.LoadBalancerIngress, 0)
}
}