Skip to content

fix: Kubernetes Job Service lifecycle - #368

Open
ethanbates-ez wants to merge 2 commits into
TangleML:masterfrom
ethanbates-ez:fix/cleanup-kubernetes-job-services
Open

ethanbates-ez wants to merge 2 commits into
TangleML:masterfrom
ethanbates-ez:fix/cleanup-kubernetes-job-services

Conversation

@ethanbates-ez

@ethanbates-ez ethanbates-ez commented Sep 24, 2026 •

Copy link
Copy Markdown

What

Give each indexed Kubernetes Job's headless Service a Job owner reference so Kubernetes removes the Service and its EndpointSlice with the Job. Cleanup also explicitly deletes the deterministic Service name for executions created before owner references existed. A Job is rolled back if its required Service cannot be created.

Why

Job cleanup deleted only the Job, leaving one permanent headless Service and EndpointSlice per execution. High-throughput installations can accumulate enough orphaned objects to exhaust cluster-wide informer caches and control-plane consumers.

Associated Issue

Fixes #370

Dev Notes

The Job must be created first to obtain the UID required by the Service owner reference. This introduces a short interval before the DNS records exist; the launcher does not return until the Service is created, and a creation failure immediately rolls back the Job.

Signed-off-by: Ethan Bates <ethan.bates@shopify.com>
@ethanbates-ez
ethanbates-ez requested a review from a team September 24, 2026 02:20
@ethanbates-ez ethanbates-ez changed the title Fix Kubernetes Job Service lifecycle fix: Kubernetes Job Service lifecycle Sep 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, put this test file in launchers sub-directory?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea will move

labels=_DEFAULT_KUBERNETES_LABELS,
),
spec=k8s_client_lib.V1ServiceSpec(
# "Headless" service.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has disappeared during the code move. Did anything else change (outside of the owner reference addition)?
I think I see some subtle changes.
I prefer doing refactorings manually or via IDE source actions such that I can be sure no extra modifications are produced. It could be pretty hard to find differences between two almost identical images or code snippets.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will tighten the diff up; the flow here

  • Service creation now happens after Job creation
  • If Service creation fails, the Job is rolled back so it cannot continue without its required DNS.
  • Cleanup explicitly deletes same-named legacy Services and tolerates an already-deleted Job or Service

@Ark-kun Ark-kun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this improvement.
I've left a couple of comments.

Signed-off-by: Ethan Bates <ethan.bates@shopify.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kubernetes Job cleanup leaks headless Services

2 participants