From 1ae8ac9002b4c9ceff7e492bc304a4bfea7a2da7 Mon Sep 17 00:00:00 2001 From: maheshbaliga Date: Wed, 11 Dec 2024 23:07:54 +0530 Subject: [PATCH] bugfix: set cluster-ip when mapping host to vCluster service --- pkg/controllers/servicesync/servicesync.go | 10 ++++++++-- test/e2e/servicesync/servicesync.go | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/servicesync/servicesync.go b/pkg/controllers/servicesync/servicesync.go index f682007a6a..44c78b2b88 100644 --- a/pkg/controllers/servicesync/servicesync.go +++ b/pkg/controllers/servicesync/servicesync.go @@ -219,11 +219,17 @@ func (e *ServiceSyncer) syncServiceAndEndpoints(ctx context.Context, fromService }, }, Spec: corev1.ServiceSpec{ - Ports: fromService.Spec.Ports, - ClusterIP: corev1.ClusterIPNone, + Ports: fromService.Spec.Ports, }, } + // Check if ClusterIP is not "None" + if fromService.Spec.ClusterIP != corev1.ClusterIPNone { + toService.Spec.ClusterIP = fromService.Spec.ClusterIP + } else { + toService.Spec.ClusterIP = corev1.ClusterIPNone + } + if e.IsVirtualToHostSyncer { e.Log.Infof("Add owner reference to host target service %s", to.Name) toService.OwnerReferences = translate.GetOwnerReference(nil) diff --git a/test/e2e/servicesync/servicesync.go b/test/e2e/servicesync/servicesync.go index a3cd6426d2..447084da0a 100644 --- a/test/e2e/servicesync/servicesync.go +++ b/test/e2e/servicesync/servicesync.go @@ -163,6 +163,7 @@ func testMapping(ctx context.Context, fromClient kubernetes.Interface, fromNames framework.ExpectEqual(toService.Spec.Selector[translate.NamespaceLabel], fromNamespace) framework.ExpectEqual(toService.Spec.Selector[translate.MarkerLabel], translate.VClusterName) framework.ExpectEqual(toService.Spec.Selector[translate.HostLabel("test")], "test") + framework.ExpectEqual(toService.Spec.ClusterIP, fromService.Spec.ClusterIP) } // check service deletion