Files
cozystack/pkg/cmd/server
Aleksei Sviridkin ec8088e54c fix(api): skip an invalid ApplicationDefinition instead of failing startup (#5357)
## What this PR does

Refs #4976. This covers the startup half of that issue. Admission-time
validation is left for a follow-up, so the issue should stay open.

`resourceConfigFrom` built one resource per ApplicationDefinition and
returned the first error from `buildResourceFromCRD`. A single
definition with an unparseable `release.cozystack.io/*` annotation
therefore stopped cozystack-api for every tenant. The definition
controller rolls cozystack-api when those annotations change, so the bad
definition also triggered the rollout that then failed. Since #4308 a
connected repository can install definitions, so this is no longer only
an operator's own mistake.

Changes:
- `resourceConfigFrom` no longer returns on the first error. It leaves
the definition out of the served kinds, logs `Skipping invalid
ApplicationDefinition "<name>": <reason>`, and returns the errors so
tests can check them. This matches how a definition that loses its kind
to an older one is already left out.
- `buildResourceFromCRD` now also rejects an `openAPISchema` that isn't
valid JSON. `BuildPostProcessV2/V3` parse every served kind's schema
with `patchSpec` and fail the whole OpenAPI spec on one that doesn't
parse. Rejecting it here leaves only that kind out.
- The comment that called a bad annotation "a loud startup failure" is
updated.

Things I deliberately left out:
- Platform and repository definitions are treated the same. The issue
left open whether a broken platform definition should still fail hard.
Skipping keeps the API up either way, and the log line names the
definition, but I'm happy to make platform definitions fatal if you
prefer.
- Nothing surfaces the problem on the definition itself (an event or
status condition). cozystack-api doesn't write to ApplicationDefinitions
today, and that seemed like a separate change.
- Admission validation in
`internal/lineagecontrollerwebhook/appdef_validator.go` (point 1 of the
suggested fix). Its `failurePolicy: Ignore` means it couldn't be the
only guard anyway.

### How I checked it

- Added `TestResourceConfigFromSkipsInvalidDefinition` next to
`TestResourceConfigFromRegistersOwnerOnly`. It uses two valid
definitions, one with `release.cozystack.io/helm-install-timeout: ten
minutes`, and one with a truncated `openAPISchema`. Only the two valid
kinds are served, and both broken ones are reported with their names.
- `go vet ./pkg/cmd/server/` and `go test ./pkg/cmd/server/` pass.
- I haven't run this against a cluster.

### Screenshots

Not a UI change.

### Downstream repositories

- [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:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

This only changes how cozystack-api starts up. No API, values or CRD
changes.

### Release note

```release-note
fix(api): an ApplicationDefinition with an unparseable release.cozystack.io/* annotation or an invalid openAPISchema is now skipped and logged instead of stopping cozystack-api from starting.
```


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

## Summary by CodeRabbit

* **Bug Fixes**
* The server can start when an application definition has an invalid
timeout setting, malformed OpenAPI schema JSON, or other
resource-construction error. Invalid definitions are skipped and
reported, while valid definitions continue to be loaded and served. This
prevents a single invalid definition from blocking startup or preventing
other valid application definitions from being available.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-23 14:55:02 +03:00
..