Skip to content
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

Honor publishNotReadyAddresses flag for headless services #2646

Merged
merged 3 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
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
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
Loading