Skip to content

Fixes #33319: clean up OMJob pods after their TTL - #35513

Merged
manerow merged 2 commits into
mainfrom
fix/33319-omjob-ttl-cleanup
Oct 16, 2026
Merged

manerow merged 2 commits into
mainfrom
fix/33319-omjob-ttl-cleanup

Conversation

@manerow

@manerow manerow commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #33319

Problem

With the OMJob operator, pods of finished ingestion runs are never deleted, whatever ttlSecondsAfterFinished says. They pile up in the namespace for as long as the cluster runs, and restarting the operator does not help.

Why it happened

The operator finds a run's pods with a label selector that included app.kubernetes.io/managed-by=omjob-operator. The operator does set that label, but it then copies the labels the server puts in the OMJob spec on top, and the server always sends managed-by=openmetadata. So no pod ever matched. TTL cleanup ran on time, deleted nothing, and still published a ResourcesCleanedUp event. The lookups that find a run's main and exit handler pods missed in the same way; they kept working only because they fall back to the pod name stored in the OMJob status.

#26971 fixed the selector and #27143 brought it back two days later, most likely in a merge conflict. Every 2.0 release has it; 1.13 does not. No test caught it: the unit tests mock the Kubernetes client, and the real-cluster TTL test is disabled.

What this PR changes

  • The selector uses only the OMJob name label, which only the operator sets. The labels on the pods do not change, so pods that already leaked match too.
  • The OMJob name and pod type labels are applied last, so labels in an OMJob spec can no longer break pod lookup. managed-by keeps the server's value, as today.
  • Cleanup also deletes the pods recorded in the OMJob status if the label lookup misses them, and logs a warning when that happens, so a future label change cannot silently bring the leak back.
  • The ResourcesCleanedUp event is published only when pods were deleted, and says how many.

What users will notice

  • After upgrading the operator, pods of finished runs past their TTL, including the ones already leaked, are deleted shortly after it starts.
  • Pods of failed runs are deleted after the TTL too. The chart's preserveFailedPods setting has never been read by the operator.
  • Logs of runs older than the TTL can no longer be read from the cluster, the same as in Jobs mode.

How it was tested

  • New tests run pod lookup and cleanup against fabric8's in-memory Kubernetes API, which evaluates label selectors, using OMJobs labelled exactly like the server's. They fail on the current code and pass with this change.
  • On a local Kubernetes 1.36 cluster, the released 2.0.2 operator left the pods of server-shaped runs (scheduled, failed, run-now) after a 60 second TTL, while an unlabelled control run was cleaned. This build then deleted all 10 leaked pods at startup and cleaned new runs 60 seconds after they finished.

Not in this PR

@manerow
manerow requested a review from a team as a code owner October 15, 2026 08:48
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 15, 2026
@gitar-bot

gitar-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk · Fixing OMJob TTL selection and deleting recorded pods could remove finished-run pods and their logs once the configured TTL expires.

Fixes OMJob pod cleanup so finished runs past their TTL are deleted again by selecting pods only on the operator-set OMJob name label, with a fallback to pod names recorded in status and a warning when that fallback is used. The operator pod-identity label contract is now recorded in a decision record referenced from LabelBuilder. No open issues remain.

✅ 1 closed
✅ Quality: Operator pod-identity label contract is not recorded in docs/decisions

📄 openmetadata-k8s-operator/src/main/java/org/openmetadata/operator/util/LabelBuilder.java:97-111 📄 openmetadata-service/src/main/java/org/openmetadata/service/clients/pipeline/k8s/README.md:112-117
This is the third PR on the same OMJob pod selector. #26971 dropped managed-by from it, #27143 brought it back (most likely in a merge conflict), and this PR drops it again. The rule that keeps it from coming back is also a contract with K8sPipelineClient. Right now that rule lives only in the PR description, which the squash merge discards, and in code comments. The description states it as: "The selector uses only the OMJob name label, which only the operator sets" and "The OMJob name and pod type labels are applied last, so labels in an OMJob spec can no longer break pod lookup. managed-by keeps the server's value." Nothing under docs/decisions/ covers OMJob labels. The README edit describes the current labels but not the rule that selectors must avoid labels the server can override.

The record should say: The OMJob operator selects its pods only by labels it alone owns (omjob.pipelines.openmetadata.org/name, plus pod-type for per-role lookup), and writes those labels after the OMJob spec labels. Labels the server sets, such as app.kubernetes.io/managed-by=openmetadata, are copied onto pods but never used in a selector. LabelBuilder.buildPodSelector/buildPodLabels can then cite it as ADR:2026-10-xx-... so the next merge conflict has something to point to.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@manerow
manerow added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 263d763 Oct 16, 2026
82 of 83 checks passed
@manerow
manerow deleted the fix/33319-omjob-ttl-cleanup branch October 16, 2026 05:21
mohityadav766 added a commit that referenced this pull request Oct 23, 2026
The operator's TTL-cleanup tests (#35513) start an in-memory Kubernetes API on
MockWebServer, pinned at mockwebserver 4.12.0, while #35557 moved okhttp to
5.5.0 through the root okhttp-bom. The explicit pin beat the BOM, so
mockwebserver 4 ran against okhttp 5 core and every test that starts the
fixture failed with NoClassDefFoundError: okhttp3/internal/Util. The two PRs
merged an hour apart on 2026-10-15, and the operator unit-test job is
path-filtered, so main stayed red until a PR touched
openmetadata-k8s-operator.

Drop the version so the BOM holds mockwebserver on 5.5.0 with okhttp-jvm.
egwada pushed a commit to egwada/OpenMetadata that referenced this pull request Oct 23, 2026
… JDKs (open-metadata#36087)

* fix(security): drop the emSign roots behind CVE-2026-91403 from image JDKs

eMudhra's compromised intermediates (CVE-2026-91403) chain to emSign ECC Root
CA - G3, emSign ECC Root CA - C3 and emSign Root CA - C1. Temurin 21.0.13
removes those roots from cacerts, but eclipse-temurin:21-jdk and
21-jre-alpine are still on 21.0.12.1, which trusts the compromised chains.

Delete the three roots by SHA-256 from the server images' jlink runtime and
from the k8s operator's JRE, and fail the build if any is still trusted. Once
the base images ship 21.0.13 the step deletes nothing.

* fix(security): record the emSign-root decision and cover the pinned JDKs

Review follow-up. The reason the step deletes roots instead of adding the
advisory's fingerprints to blocked.certs was only in the PR description: an
ECDSA signature re-encoded as (r, n-s) gives an intermediate a new fingerprint
that still verifies. Record it as
ADR:2026-10-23-image-jdks-distrust-compromised-cas-by-deleting-roots, cite it
from each step, and note why the operator keeps java as its entrypoint.

docker/olivaw and docker/oss-scanner run Maven on a Temurin 21.0.11 base pinned
by digest, so they never pick up 21.0.13 on their own; give them the same step.

* fix(deps): let the okhttp BOM manage the operator's mockwebserver

The operator's TTL-cleanup tests (open-metadata#35513) start an in-memory Kubernetes API on
MockWebServer, pinned at mockwebserver 4.12.0, while open-metadata#35557 moved okhttp to
5.5.0 through the root okhttp-bom. The explicit pin beat the BOM, so
mockwebserver 4 ran against okhttp 5 core and every test that starts the
fixture failed with NoClassDefFoundError: okhttp3/internal/Util. The two PRs
merged an hour apart on 2026-10-15, and the operator unit-test job is
path-filtered, so main stayed red until a PR touched
openmetadata-k8s-operator.

Drop the version so the BOM holds mockwebserver on 5.5.0 with okhttp-jvm.
pmbrull added a commit that referenced this pull request Nov 4, 2026
…37047)

* fix(k8s): backport operator pod label safety

Required by the Kubernetes resource metadata backport (#36354).

Backport of #35513, commit 263d763.

* feat(k8s): backport pipeline pod metadata

Backport #36354 to 2.0 using the original feature and test commits:

5a317d0
eb8484e

Skip Kubernetes initialization in the existing bot-token unit tests so JWT assertions do not depend on a local cluster.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] OMJob TTL cleanup fails because PodManager uses a mismatched managed-by label

2 participants