Skip to content

fix(platform): order cozystack-basics after the APIs its admission policies type-check - #2842

Merged
Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
daniil/fix-vap-typecheck-bootstrap-deadlock
Jun 9, 2026
Merged

Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
daniil/fix-vap-typecheck-bootstrap-deadlock

Conversation

@myasnikovdaniil

@myasnikovdaniil myasnikovdaniil commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

cozystack-basics ships cluster-wide ValidatingAdmissionPolicies — the gateway / route / tenant host policies — that match tenants.apps.cozystack.io (served by cozystack-api) and the Gateway API types (gateways, httproutes, tlsroutes). kube-controller-manager's ValidatingAdmissionPolicy status type-checker panics with a nil-pointer dereference in k8s.io/apiserver/pkg/cel/openapi when it type-checks a policy against a matched type whose schema it cannot resolve yet.

During a cold install this is a deadlock. cozystack-basics can install before cozystack-api is Ready; the tenant-host policy is created; KCM panics type-checking it against the not-yet-served tenants schema and CrashLoops; that stalls cert/token issuance, so cozystack-api never starts and the schema never resolves — KCM keeps crashing and every HelmRelease times out on DependencyNotReady.

This adds dependsOn edges so cozystack-basics installs only after cozystack-engine (which serves tenants.apps.cozystack.io via cozystack-api) and gateway-api-crds are Ready. The policies are then never created before the APIs they type-check are served.

A template capability gate (.Capabilities.APIVersions.Has) was considered and rejected: operator-generated HelmReleases run without drift detection, so helm-controller is checksum-driven — it would render the policy out at first install and never re-add it once the API appears, silently dropping the protection. Ordering via dependsOn gates the first install on Ready, which is reliable.

No cycle risk: nothing dependsOn cozystack-basics, and no cozystack-engine component consumes a cozystack-basics output, so engine becomes Ready independently.

Includes a helm-unittest regression test asserting the dependsOn edges stay.

The underlying nil-pointer panic is an upstream Kubernetes bug (the best-effort status type-checker should never crash kube-controller-manager); it is unguarded as of the current release and will be reported separately. This change removes the trigger on the cozystack side.

Release note

fix(platform): order cozystack-basics after the APIs its admission policies type-check, fixing a cold-install deadlock where kube-controller-manager could crash type-checking policies against APIs (tenants, Gateway API) not yet served

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved cluster stability by implementing proper dependency ordering for validation policies during initialization, preventing resource configuration conflicts.
  • Tests

    • Added integration tests to validate cluster-wide policy dependencies and ordering, ensuring continuous system stability verification.

…licies type-check

cozystack-basics ships cluster-wide ValidatingAdmissionPolicies matching
tenants.apps.cozystack.io and the Gateway API types. KCM's VAP status
type-checker panics on a nil schema when it type-checks a policy against a
matched type that isn't resolvable yet; during a cold install this crashes
KCM, which stalls cert/token issuance, so cozystack-api never starts and the
tenants schema never resolves — a bootstrap deadlock.

Add dependsOn edges so the package installs only after cozystack-engine
(cozystack-api) and gateway-api-crds are Ready. Drift detection is off on
operator-generated HelmReleases, so a template capability gate would drop the
policy at first install and never re-add it; ordering is the reliable fix.

Assisted-By: Claude <[email protected]>
Signed-off-by: Myasnikov Daniil <[email protected]>
@github-actions github-actions Bot added size/M This PR changes 30-99 lines, ignoring generated files area/platform Issues or PRs related to platform infrastructure (bundle, flux, talos, installer) kind/bug Categorizes issue or PR as related to a bug labels Jun 8, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a cold-install deadlock where the kube-controller-manager would crash due to a nil-pointer dereference when validating admission policies against APIs that had not yet been served. By enforcing explicit dependency ordering, we ensure that 'cozystack-basics' only initializes after the necessary engine and gateway components are ready, preventing the race condition that led to the crash loop.

Highlights

  • Dependency Ordering: Added 'cozystack.cozystack-engine' and 'cozystack.gateway-api-crds' to the 'dependsOn' list for 'cozystack-basics' to ensure admission policies are not created before their corresponding APIs are available.
  • Regression Testing: Added a new helm-unittest file to verify that the required dependency edges remain present in the configuration.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 924c2542-d5af-4117-ae5f-2b47c29c5de9

📥 Commits

Reviewing files that changed from the base of the PR and between 36b07dd and 03f1e7a.

📒 Files selected for processing (2)
  • packages/core/platform/sources/cozystack-basics.yaml
  • packages/core/platform/tests/sources_basics_dependson_test.yaml

📝 Walkthrough

Walkthrough

This PR fixes ValidatingAdmissionPolicy ordering issues by adding explicit dependsOn declarations to the cozystack-basics package source, ensuring prerequisite CRD packages are created before cluster-wide admission policies are applied. A new integration test verifies these dependencies remain in place.

Changes

ValidatingAdmissionPolicy ordering

Layer / File(s) Summary
Add dependency declarations to cozystack-basics manifest
packages/core/platform/sources/cozystack-basics.yaml
Introduces dependsOn section with cozystack.cozystack-engine and cozystack.gateway-api-crds to prevent kube-controller-manager deadlock by ensuring schema resolution order.
Validate dependency edges with integration test
packages/core/platform/tests/sources_basics_dependson_test.yaml
New test asserts spec.variants[0].dependsOn includes required packages, preventing regression of the ordering fix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

kind/bug, size/XS, area/platform

Suggested reviewers

  • kvaps
  • lllamnyp
  • androndo
  • IvanHunters
  • sircthulhu

Poem

🐰 A deadlock dodged with dependencies neat,
The basics now wait for the engines to meet,
Gateway APIs ready, the order's precise,
Admission policies blessed by your test's device.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title precisely describes the main change: ordering cozystack-basics to depend on APIs its ValidatingAdmissionPolicies type-check against, which directly addresses the cold-install deadlock issue resolved by the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch daniil/fix-vap-typecheck-bootstrap-deadlock

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds cozystack-engine and gateway-api-crds as dependencies for cozystack-basics to prevent a deadlock caused by kube-controller-manager panicking when type-checking ValidatingAdmissionPolicies before their corresponding schemas are resolved. It also introduces a regression test to verify these dependencies. The reviewer requests confirmation on whether this change preserves backward compatibility for existing installations during upgrades, in accordance with the repository style guide for changes to packages/core/platform/.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +33 to +34
- cozystack.cozystack-engine
- cozystack.gateway-api-crds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository style guide, any changes to packages/core/platform/ require a corresponding migration update or an explicit note/verification that backward compatibility is preserved for existing installations. While the PR description explains why there is no cycle risk, please explicitly confirm if this change preserves backward compatibility for existing clusters during upgrades without requiring a migration hook update.

References
  1. Changes to packages/core/platform/ require a corresponding migration update or an explicit note that backward compatibility is preserved. (link)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — adds dependsOn edges so cozystack-basics installs only after the APIs its ValidatingAdmissionPolicies match are served, removing the cold-install deadlock at its trigger; ships a regression test pinning the edges.

Business context: cozystack-basics ships cluster-wide VAPs matching tenants.apps.cozystack.io and the Gateway API types; on a cold install it can land before cozystack-api/gateway-api-crds are Ready, kube-controller-manager's VAP status type-checker nil-panics against the unresolvable schema and CrashLoops, which stalls cert/token issuance so the API never starts — a self-sustaining deadlock that times out every HelmRelease.

Verified: all three dependsOn targets exist as platform sources (cozystack-engine, gateway-api-crds, tenant-application); cozystack-basics is a dependency-graph leaf and the engine consumes none of its outputs, so the new edges add no cycle; the regression test asserts the edges. No migration is needed despite touching a platform source — dependsOn is a declarative HelmRelease field that Flux reconciles on upgrade, and on an existing cluster the targets are already Ready, so the edge is satisfied immediately with no imperative transformation to run (the deadlock is cold-install-only). The capability-gate alternative is correctly rejected: operator-generated HelmReleases are checksum-driven with drift detection off, so a .Capabilities.APIVersions.Has gate would render the policy out at first install and never re-add it once the API appears.

Non-blocking: the underlying KCM nil-panic is an upstream Kubernetes bug (the best-effort status type-checker should degrade, not crash kube-controller-manager); the PR notes it will be reported separately — worth filing so the platform-side ordering stays a defense-in-depth measure rather than the only guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform Issues or PRs related to platform infrastructure (bundle, flux, talos, installer) kind/bug Categorizes issue or PR as related to a bug size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants