fix(kubernetes): probe Keycloak CRDs by output in oidc-bootstrap cleanup - #3520
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: cozystack/cozystack/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe mode=None OIDC cleanup now checks the ChangesOIDC cleanup
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The cleanup change is ready to merge after normal checks. No actionable merge-blocking risk remains. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/apps/kubernetes/templates/oidc-rbac-job.yaml`:
- Line 231: Preserve the kubectl api-resources exit status separately from
EDP_RESOURCES in the discovery logic of
packages/apps/kubernetes/templates/oidc-rbac-job.yaml, so cleanup retries or
fails on discovery errors and monitoring skips only when the successfully
discovered CRD list is empty. Update the corresponding assertions or setup in
hack/e2e-apps/monitoring-oidc-customconfig.bats lines 110-114 and
hack/e2e-apps/monitoring-oidc-system.bats lines 131-135 to cover the distinct
discovery-failure and empty-list cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 0c429de9-355b-485e-84fb-94fd4ec5b509
📒 Files selected for processing (4)
hack/e2e-apps/monitoring-oidc-customconfig.batshack/e2e-apps/monitoring-oidc-system.batspackages/apps/kubernetes/templates/oidc-rbac-job.yamlpackages/apps/kubernetes/tests/oidc_test.yaml
Note for reviewers: overlapping file with a sibling PR
|
|
The observation is accurate: line 231 uses This script is a The failure mode of keeping it as-is is also much milder, and self-healing: if discovery genuinely fails, the cleanup skips, the hook succeeds, and the deletes are attempted again on the next upgrade of that release. The objects it would have removed are chart-owned, so nothing else claims them in the meantime. A stuck upgrade, by contrast, needs a human. Your point about the two Correction to the paragraph above, and thanks for the prompt to look again. I wrote that the The guards now skip only on a genuinely empty list and fail with the discovery error when the call itself fails. Validated against a stub My position on the Helm hook is unchanged, and the contrast is the point: there any non-zero exit blocks the release upgrade, so conflating the two states is a deliberate availability trade-off. A test has no such trade-off to make, so your finding was right for the |
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
NOT LGTM, though the template fix itself is right and I want it in: people are hitting this in production today.
I verified the fix end to end rather than reading it. kubectl api-resources --api-group=<absent> --output=name exits 0 and prints nothing, while a present group prints <resource>.<group>, so the old exit-code guard could never skip and the ^keycloakclients\. anchor is the correct test. The mode=None path has no other unknown-type call. The new unit case fails all four assertions when I restore only the pre-fix oidc-rbac-job.yaml, so the test bites. release-1.6 still carries the broken guard, so the backport target is valid.
What blocks it sits in the second half of the diff and in the text around it.
Nothing executes the two files under hack/e2e-apps/. packages/core/testing/Makefile runs three named bats files plus chainsaw, the root Makefile builds its unit list from $(wildcard hack/*.bats) which is not recursive, and a grep for e2e-apps across .github/, hack/*.sh and both Makefiles returns one comment in cozytest.sh. That matters because the PR body describes their behaviour in CI ("burned its 60s timeout", "passed for the wrong reason") and commit 5810ac094 is titled "fail the OIDC e2e when CRD discovery itself fails". Neither can happen. With the backport label those statements travel to release-1.6, and a commit title is permanent. How they got there: the Chainsaw migration removed the runner on 2026-06-25 and these two files arrived on 2026-07-15, into a directory nothing had read for three weeks.
Second, the change makes an undefined command reachable in those same files. hack/cozytest.sh defines no skip, only an unrelated skip_next variable, and runs each body in a subshell under set -eu -x, so calling skip is exit 127 and fails the test. Before this diff the guard never fell true and the line was unreachable text; now it is reachable, which inverts what it was written to do. The same pattern sits at hack/e2e-install-cozystack.bats:593 in a file CI does run, so I filed that separately as #3827.
Both blockers close with one action: drop the two files, ideally in their own commit that says it removes dead code, take the CI claims out of the body, and reword 5810ac094 to describe the template fix it actually makes.
The red checks are not yours. Both die pushing to OCIR anonymously because this branch predates #3257: git show <head>:.github/workflows/pull-requests.yaml | grep -c OCI_EXPORT_DIR gives 0 here and a non-zero count on main, so the fork path that exports images instead of pushing them is simply absent from the branch. A rebase should clear them.
|
mattia-eleuteri Where this stands: the template fix and its test are right and verified, and the only thing holding this is the second half of the diff, the two files under hack/e2e-apps that nothing runs, plus the CI wording in the body and the title of 5810ac0. The two red checks are the fork path missing #3257, a rebase clears them. Can you drop the two files and reword those two texts? If you would rather not touch it further, say so and I will open a separate PR for the template fix with credit to you. |
5810ac0 to
06817c1
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Done, and I would rather finish it than hand it over. The branch is now two commits on top of
I checked your three findings rather than taking them on trust, and all three hold. Two things I did beyond the ask, both to keep the deletion honest: Four comments asserted what the directory currently holds and the deletion falsifies them — And #3786 says the choice needs someone who knows whether the coverage is still wanted. It is, so I opened #4051 with what the pair actually asserted in each mode, plus the two traps a port should not repeat — probe the output, and keep a failed discovery distinct from an empty list, which a test has no reason to conflate. My position on the hook itself is unchanged and now stands alone: there, conflating a failed discovery with an absent group is deliberate, because any non-zero exit blocks the release upgrade. That trade-off was never a reason to conflate them in a test — it just no longer has a test to argue with. Rebased for #3257, so the OCIR checks should clear. |
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
mattia-eleuteri NOT LGTM, only because main moved under the branch. The template fix is still needed and still right, so this should be a short rebase.
The second commit is already on main. #4019 deleted the same two suites under hack/e2e-apps/ and reworded the same comments, so the branch now conflicts in hack/cozytest.sh, hack/select-e2e.sh, hack/bats-no-exit-trap.bats and hack/cozytest-capture-gate.bats. Please drop 06817c1e3 and rebase the first commit alone.
The first commit applies to main without conflicts. Main still has the exit-code guard at oidc-rbac-job.yaml:217. On a trial merge of 356a377b8 onto current main, helm unittest in packages/apps/kubernetes passes 317/317. Putting main's template back fails only your new case, all four assertions.
The trailer needs a rewrite too. Main now accepts only Assisted-by: LLM, and the Commit trailers job in pre-commit.yml runs hack/check-commit-trailers.sh over the PR commits. Run against this branch it rejects both commits on Assisted-By: Claude <[email protected]>. When the branch was cut, contributing.md still asked for that form, so this is not on you, but the rebased commit will not pass without the change.
The PR body becomes the merge commit message. After the rebase, please remove the part about deleting the two suites and the four reworded comments, and the Closes #3638 line, since main already did that work. The red E2E Tests on this head is from before the fork e2e lane was fixed, not from the diff.
`kubectl api-resources --api-group=<absent group>` exits 0 and prints an empty list, so guarding on the exit code always fell through. The delete then failed with `the server doesn't have a resource type "keycloakclient"` — `--ignore-not-found` covers a missing object, not an unknown type. Because the oidc-bootstrap Job is a post-install/post-upgrade Helm hook, that failure blocked the Helm upgrade of every `kubernetes-<cluster>` release on any cluster without the EDP Keycloak operator CRDs, which is the default configuration (`oidc.mode: None`). Capture the discovery output once and gate each delete on its own resource type, matching the probe idiom already used by the platform migrations and the ouroboros cleanup hook. Fixes cozystack#3516 Signed-off-by: Mattia Eleuteri <[email protected]> Assisted-by: LLM
06817c1 to
06400ac
Compare
|
Aleksei Sviridkin (@lexfrei) Rebased. The trailer is rewritten to The PR body no longer mentions the suite deletion, the four reworded comments or |
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
mattia-eleuteri LGTM.
I checked the rebase on my side. The trailer check passes on this commit and still rejects the old head. With main's template put back, only your new case fails. #4538 never touched oidc-rbac-job.yaml, so there is nothing to reconcile with main. The fork e2e run on this head passed both kubernetes suites.
|
Successfully created backport PR for |
What this PR does
Fixes #3516.
packages/apps/kubernetes/templates/oidc-rbac-job.yaml: themode=Nonecleanup path of theoidc-bootstrapJob guarded its Keycloak deletes withif kubectl api-resources --api-group=v1.edp.epam.com >/dev/null 2>&1. That command exits 0 for an absent API group (it simply prints an empty list), so the guard always fell through and the delete failed witherror: the server doesn't have a resource type "keycloakclient"—--ignore-not-foundcovers a missing object, not an unknown type. Since the Job is apost-install,post-upgradeHelm hook withbackoffLimit: 6, this blocked the Helm upgrade of everykubernetes-<cluster>release on any cluster without the EDP Keycloak operator CRDs, i.e. at the chart defaultoidc.mode: None.The probe now captures the discovery output once and gates each delete on its own resource type being present, matching the idiom already used in
packages/core/platform/images/migrations/migrations/{34,38,39}andpackages/system/ouroboros/.../cleanup-hook.yaml.api-resourcesis kept (rather thanget crd) on purpose: it hits discovery, whichsystem:discoverygrants to every authenticated principal, so the namespaced Job Role needs no cluster-scoped CRD read.packages/apps/kubernetes/tests/oidc_test.yaml: new unit test asserting the rendered script probes by output and that the exit-code form does not come back. All four of its assertions fail against the pre-fix template.cmd/check-readinessand the platform migrations were checked too: they already test the output, not the exit code.Validation
helm unittest packages/apps/kuberneteson the branch rebased onto currentmain: 317/317 pass. Puttingmain's template back fails only the new case, all 4 assertions, so it is a real regression guard.make generateinpackages/apps/kubernetes: no diff.mode=Nonescript and ransh -n/shellcheck -s sh— clean (only pre-existingSC3040forpipefailand one pre-existingSC2086).kubectlreproducing the two real behaviors (api-resourcesexits 0 with empty output for an absent group;delete <unknown type>exits 1 despite--ignore-not-found): the pre-fix script exits 1 withthe server doesn't have a resource type "keycloakclient", the fixed script exits 0 with the CRDs absent and still issues both deletes with the CRDs present.Downstream repositories
The diff touches no
values.schema.jsonand no behaviour the docs describe: the template change restores the documentedoidc.mode: Nonepath rather than altering it.Release note
Summary by CodeRabbit