From 07e1df5bec735def1758d25e5f699fa7eba281d4 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Thu, 10 Aug 2023 09:50:54 -0400 Subject: [PATCH] Honor publishNotReadyAddresses flag for headless services Lighthouse honors this flag when publiishing endpoint addresses so Globalnet needs to as well when allocating a global IP for ingress. Fixes https://github.com/submariner-io/lighthouse/issues/1342 Signed-off-by: Tom Pantelis --- .../controllers/ingress_pod_controller.go | 12 +++++++----- .../service_export_controller_test.go | 17 +++++++++++++++-- pkg/globalnet/controllers/types.go | 7 ++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pkg/globalnet/controllers/ingress_pod_controller.go b/pkg/globalnet/controllers/ingress_pod_controller.go index 254342e4ad..0abc31c95f 100644 --- a/pkg/globalnet/controllers/ingress_pod_controller.go +++ b/pkg/globalnet/controllers/ingress_pod_controller.go @@ -44,10 +44,11 @@ func startIngressPodController(svc *corev1.Service, config *syncer.ResourceSynce } controller := &ingressPodController{ - baseSyncerController: newBaseSyncerController(), - svcName: svc.Name, - namespace: svc.Namespace, - ingressIPMap: set.New[string](), + baseSyncerController: newBaseSyncerController(), + svcName: svc.Name, + namespace: svc.Namespace, + publishNotReadyAddresses: svc.Spec.PublishNotReadyAddresses, + ingressIPMap: set.New[string](), } labelSelector := labels.Set(svc.Spec.Selector).AsSelector().String() @@ -120,7 +121,8 @@ func (c *ingressPodController) process(from runtime.Object, _ int, op syncer.Ope } // TODO: handle phase and podIP changes? - if c.ingressIPMap.Has(ingressIP.Name) || pod.Status.Phase != corev1.PodRunning || pod.Status.PodIP == "" { + if c.ingressIPMap.Has(ingressIP.Name) || pod.Status.PodIP == "" || + (!c.publishNotReadyAddresses && pod.Status.Phase != corev1.PodRunning) { // Avoid assigning ingressIPs to pods that are not ready with an endpoint IP return nil, false } diff --git a/pkg/globalnet/controllers/service_export_controller_test.go b/pkg/globalnet/controllers/service_export_controller_test.go index 1ebca5c8b3..44f38bcd2c 100644 --- a/pkg/globalnet/controllers/service_export_controller_test.go +++ b/pkg/globalnet/controllers/service_export_controller_test.go @@ -122,6 +122,9 @@ func testHeadlessService() { BeforeEach(func() { service = newHeadlessService() backendPod = newHeadlessServicePod(service.Name) + }) + + JustBeforeEach(func() { t.createServiceExport(t.createService(service)) }) @@ -143,19 +146,29 @@ func testHeadlessService() { }) }) - When("a backend Pod for an exported Service isn't initially running", func() { + When("a backend Pod for an exported Service isn't running", func() { BeforeEach(func() { backendPod.Status.Phase = corev1.PodPending t.createPod(backendPod) }) - It("should eventually create a GlobalIngressIP", func() { + It("should eventually create a GlobalIngressIP after the Pod transitions to running", func() { t.ensureNoGlobalIngressIPs() backendPod.Status.Phase = corev1.PodRunning test.UpdateResource(t.pods.Namespace(namespace), backendPod) t.awaitHeadlessGlobalIngressIP(service.Name, backendPod.Name) }) + + Context("and PublishNotReadyAddresses is set to true on the Service", func() { + BeforeEach(func() { + service.Spec.PublishNotReadyAddresses = true + }) + + It("should create a GlobalIngressIP", func() { + t.awaitHeadlessGlobalIngressIP(service.Name, backendPod.Name) + }) + }) }) When("a backend Pod for an exported Service doesn't initially have an IP", func() { diff --git a/pkg/globalnet/controllers/types.go b/pkg/globalnet/controllers/types.go index df41c9c319..0dc889f214 100644 --- a/pkg/globalnet/controllers/types.go +++ b/pkg/globalnet/controllers/types.go @@ -168,9 +168,10 @@ type nodeController struct { type ingressPodController struct { *baseSyncerController - svcName string - namespace string - ingressIPMap set.Set[string] + publishNotReadyAddresses bool + svcName string + namespace string + ingressIPMap set.Set[string] } type IngressPodControllers struct {