Skip to content

Commit

Permalink
Honor publishNotReadyAddresses flag for headless services
Browse files Browse the repository at this point in the history
Lighthouse honors this flag when publiishing endpoint addresses so
Globalnet needs to as well when allocating a global IP for ingress.

Fixes submariner-io/lighthouse#1342

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
  • Loading branch information
tpantelis committed Aug 10, 2023
1 parent bf8acf1 commit 07e1df5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
12 changes: 7 additions & 5 deletions pkg/globalnet/controllers/ingress_pod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/globalnet/controllers/service_export_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func testHeadlessService() {
BeforeEach(func() {
service = newHeadlessService()
backendPod = newHeadlessServicePod(service.Name)
})

JustBeforeEach(func() {
t.createServiceExport(t.createService(service))
})

Expand All @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions pkg/globalnet/controllers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 07e1df5

Please sign in to comment.