Aleksei Sviridkin ff0752d8e9 fix(kubernetes): probe Keycloak CRDs by output in oidc-bootstrap cleanup (#3520)
## What this PR does

Fixes #3516.

- `packages/apps/kubernetes/templates/oidc-rbac-job.yaml`: the
`mode=None` cleanup path of the `oidc-bootstrap` Job guarded its
Keycloak deletes with `if 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 with `error: the server
doesn't have a resource type "keycloakclient"` — `--ignore-not-found`
covers a missing *object*, not an unknown *type*. Since the Job is a
`post-install,post-upgrade` Helm hook with `backoffLimit: 6`, this
blocked the Helm upgrade of every `kubernetes-<cluster>` release on any
cluster without the EDP Keycloak operator CRDs, i.e. at the chart
default `oidc.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}` and
`packages/system/ouroboros/.../cleanup-hook.yaml`. `api-resources` is
kept (rather than `get crd`) on purpose: it hits discovery, which
`system:discovery` grants 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-readiness` and the platform migrations were checked too: they
already test the output, not the exit code.

## Validation

- `helm unittest packages/apps/kubernetes` on the branch rebased onto
current `main`: 317/317 pass. Putting `main`'s template back fails only
the new case, all 4 assertions, so it is a real regression guard.
- `make generate` in `packages/apps/kubernetes`: no diff.
- Extracted the rendered `mode=None` script and ran `sh -n` /
`shellcheck -s sh` — clean (only pre-existing `SC3040` for `pipefail`
and one pre-existing `SC2086`).
- Executed the extracted script against a stub `kubectl` reproducing the
two real behaviors (`api-resources` exits 0 with empty output for an
absent group; `delete <unknown type>` exits 1 despite
`--ignore-not-found`): the pre-fix script exits 1 with `the 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

<!--
Cozystack is upstream for repositories that are NOT kept in sync with it
automatically, and nothing in CI compares the two sides, so a change
here can break them silently.

Which change forces what, and which file to touch, is the trigger map in
docs/agents/contributing.md under "Downstream Repositories". Walk it
before you tick anything.

IF YOU ARE AN AI AGENT OR AN LLM, THIS IS PART OF THE TASK, NOT A FORM
TO FILL IN:

1. Walk the trigger map against the actual diff of this PR, file by
file. Do not decide from the PR title or from your memory of what you
changed.
2. For every repository you tick, open the follow-up PR there and link
it on the same line. A ticked box with no link claims work that does not
exist, which is worse than an empty box. Search that repository for an
open PR or issue covering it first, and link that instead of filing a
duplicate.
3. When the follow-up is out of scope, or needs a decision that is not
yours to make, open an issue in that repository instead, link that, and
say so in the PR body. Do not push a speculative PR into another
repository just to fill a line here.
4. Do not tick "No downstream repository is affected" to make the
checklist go away. If you are unsure, leave every box empty and say so
in the PR body, so a human decides.
-->

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:

The diff touches no `values.schema.json` and no behaviour the docs
describe: the template change restores the documented `oidc.mode: None`
path rather than altering it.

## Release note

```release-note
fix(kubernetes): the oidc-bootstrap hook no longer fails on clusters without the Keycloak operator CRDs, which blocked Helm upgrades of kubernetes-* releases at oidc.mode=None
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* OIDC cleanup now skips deleting Keycloak resources when their resource
types are unavailable, preventing cleanup failures.
* **Tests**
* Added coverage for resource discovery and conditional cleanup
behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-29 14:26:00 +03:00
2025-10-08 09:43:34 +05:00
2024-02-08 12:04:32 +01:00

Cozystack Cozystack

GitHub Release Apache-2.0 License Commit activity OpenSSF Best Practices OpenSSF Scorecard CLOMonitor Support

Cozystack

Cozystack is a free and open-source platform and framework for building clouds.

Cozystack is a CNCF Sandbox project that was originally built and sponsored by Ænix.

With Cozystack, you can transform a bunch of servers into an intelligent system with a simple REST API for spawning Kubernetes clusters, Database-as-a-Service, virtual machines, load balancers, HTTP caching services, and other services with ease.

Use Cozystack to build your own cloud or provide a cost-effective development environment.

Cozystack user interface

Use-Cases

Documentation

The documentation is located on the cozystack.io website.

Read the Getting Started section for a quick start.

If you encounter any difficulties, start with the troubleshooting guide and work your way through the process that we've outlined.

Versioning

Versioning adheres to the Semantic Versioning principles.
A full list of the available releases is available in the GitHub repository's Release section.

Contributions

Contributions are highly appreciated and very welcomed!

In case of bugs, please check if the issue has already been opened by checking the GitHub Issues section. If it isn't, you can open a new one. A detailed report will help us replicate it, assess it, and work on a fix.

You are welcome to take on the fix yourself. Commits are used to generate the changelog, and their author will be referenced in it.

If you have a concrete feature request, open an issue. For a cross-cutting or architectural change, open a design proposal in the community repo. For questions or early ideas, use GitHub Discussions. See CONTRIBUTING.md for the full routing.

Community

You are welcome to join us in #cozystack, on either CNCF Slack (get an invite) or Kubernetes Slack (get an invite), in our Telegram group, and at our community meetings. Add them to your Google Calendar or iCal for convenience.

Project documents

Document What it covers
Governance How decisions are made and who makes them
Contributor Ladder How to grow from contributor to maintainer
Maintainers Who maintains the project
Code of Conduct What we expect of each other
Security Policy Reporting a vulnerability, and which releases get fixes
Adopters Who runs Cozystack in production
Roadmap Where the project is going

License

Cozystack is licensed under Apache 2.0.
The code is provided as-is with no warranties.

Commercial Support

A list of companies providing commercial support for this project can be found on official site.

Languages
Go 47.2%
Shell 37.6%
TypeScript 7%
Go Template 5.4%
Makefile 1.4%
Other 1.2%