Skip to content

fix(cli): find the pods of a cronjob - #15806

Open
BahaaMattar wants to merge 1 commit into
linkerd:mainfrom
BahaaMattar:fix-getpodsfor-cronjob-owner
Open

BahaaMattar wants to merge 1 commit into
linkerd:mainfrom
BahaaMattar:fix-getpodsfor-cronjob-owner

Conversation

@BahaaMattar

Copy link
Copy Markdown

Problem

k8s.GetPodsFor resolves a cronjob/<name> argument by listing the
jobs of the namespace and keeping the ones that the cronjob owns. The
owner check passed the UID of the job itself, so it asked whether the
job owns itself, which is never true. The cronjob was not even looked
up by name. As a result the function always returned no pods for a
cronjob.

The CLI commands that resolve workloads with this function showed
nothing for cronjobs: linkerd diagnostics proxy-metrics cronjob/<name>
printed no output and exited successfully, and linkerd authz cronjob
listed no authorizations.

Solution

Get the cronjob by name, like the other workload kinds, and keep the
jobs whose owner references contain the UID of that cronjob, as the
controller's own GetPodsFor already does. Looking the cronjob up also
gives a not found error for a name that does not exist.

Validation

Added TestGetPodsForCronJob with two cronjobs and a standalone job,
each with a pod. It fails without the change (no pods are returned) and
passes with it.

go test ./pkg/k8s/

Fixes #15805

Problem

`k8s.GetPodsFor` resolves a `cronjob/<name>` argument by listing the
jobs of the namespace and keeping the ones that the cronjob owns. The
owner check passed the UID of the job itself, so it asked whether the
job owns itself, which is never true. The cronjob was not even looked
up by name. As a result the function always returned no pods for a
cronjob.

The CLI commands that resolve workloads with this function showed
nothing for cronjobs: `linkerd diagnostics proxy-metrics cronjob/<name>`
printed no output and exited successfully, and `linkerd authz cronjob`
listed no authorizations.

Solution

Get the cronjob by name, like the other workload kinds, and keep the
jobs whose owner references contain the UID of that cronjob, as the
controller's own GetPodsFor already does. Looking the cronjob up also
gives a not found error for a name that does not exist.

Validation

Added `TestGetPodsForCronJob` with two cronjobs and a standalone job,
each with a pod. It fails without the change (no pods are returned) and
passes with it.

go test ./pkg/k8s/

Fixes linkerd#15805

Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>
@BahaaMattar
BahaaMattar requested a review from a team as a code owner November 19, 2026 23:46
@anthoturc
anthoturc requested a review from cpakulski November 20, 2026 17:21
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.

linkerd diagnostics proxy-metrics cronjob/<name> finds no pods, and linkerd authz cronjob lists nothing

1 participant