Aleksei Sviridkin 47df27de57 fix(api): let one ApplicationDefinition own each application kind (#4424)
## What this PR does

Nothing enforced that `spec.application.kind` is unique across
ApplicationDefinitions, and every consumer that maps a kind back to a
definition resolved a duplicate its own way. The chartRef reconciler
selected HelmReleases by the kind label alone and let every definition
rewrite every release of its kind; the lineage webhook and the CA
projection reconciler took whichever definition came first in an
unordered list; cozystack-api registered one resource per definition. A
second definition declaring a kind already in use could therefore
repoint that kind's tenant releases at its own artifact, whatever the
definition was named. Fixes #4361.

This adds one ownership rule, in `internal/shared/appdefowner`: the
definition created first owns the kind, with ties broken by name. Every
Go consumer goes through it:

- the chartRef reconciler rewrites releases only for the owner of their
kind, emits a `KindClaimed` Warning event on a definition that is not
the owner, and re-reconciles the next owner when the current one is
deleted or changes kind;
- cozystack-api registers the owner only and logs the definitions it
leaves out; its restart hash now moves when ownership moves, while a
cluster without duplicate kinds hashes exactly as before, so the upgrade
itself does not restart the API;
- the lineage webhook and the CA projection reconciler resolve the
owner, and the CA projection watch now also reacts to a kind change;
- the lineage webhook gains a validating endpoint that refuses a new
ApplicationDefinition whose kind another definition already declares. An
update that keeps its kind is allowed, so a duplicate that predates the
check keeps upgrading, and so is a second definition from the same Helm
release, because a release that renames its definition object creates
the new one before it deletes the old one. It is registered with
`failurePolicy: Ignore`, and a failure to read the existing definitions
lets the request through with a warning instead of an error answer,
which Ignore would not cover: ApplicationDefinitions ship with the
platform, so the check must never block an install or upgrade, and the
ownership rule holds whatever it lets through.

Two decisions differ from the wording of the issue, deliberately:

- a duplicate kind is not a fail-stop at cozystack-api start-up. One
malformed or duplicate definition taking the API down for every tenant
is the problem #4359's design comment calls out, so the API serves the
owner and logs the rest instead;
- "created first owns" rather than "the platform's definition owns". It
needs no notion of provenance, and a definition that arrives later can
never take a kind over. The consequence worth knowing: deleting the
owner hands its releases to the next definition declaring that kind.

Known gaps left for follow-ups, both pre-existing:

- the dashboard console (`packages/system/dashboard/images/console`)
still picks the first definition matching a kind or plural in the list
it receives. It switches no release, but with a duplicate present it can
show the duplicate's form;
- `plural` collisions are not checked: a definition with a new kind but
an existing plural still takes the plural's endpoint at registration.
Existing releases are not reachable through it, since List and Get
filter by the kind label.

Tests cover the rule itself, each consumer, the webhook (create, update
keeping and changing kind) and the chart; every guard was
mutation-checked term by term.

### Screenshots

Not a UI change.

### Downstream repositories

The change alters `ApplicationDefinition` semantics (kind uniqueness and
ownership), which the trigger map routes to `cozystack/website`
(`content/en/docs/next/cozystack-api/application-definitions.md`). The
follow-up there is not opened yet; it needs the maintainers to settle
the behaviour first. No other repository in the map is reached: no CRD,
kind, plural, prefix or values change.

- [ ] 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:

### Release note

```release-note
fix(api): an application kind is now owned by one ApplicationDefinition, the one created first. A second definition declaring a kind already in use is refused at admission, and one that predates the check no longer manages that kind's releases or its API registration.
```


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

* **New Features**
* Application kinds now have a consistent owner: the earliest-created
definition takes precedence, with name used to break timestamp ties.
* New definitions that claim a kind already owned by another definition
are rejected. Existing duplicates can keep their current kind, and
definitions from the same Helm release can be renamed.
* **Bug Fixes**
* Runtime configuration and Helm releases now use the owning definition,
preventing duplicates from replacing its configuration.
  * Ownership changes trigger affected definitions to be reconciled.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-25 13:31:24 +04: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 52%
Shell 34%
TypeScript 6.8%
Go Template 4.7%
Makefile 1.3%
Other 1.1%