Skip to content

[cozystack] Major Architecture Refactoring - #1641

Closed
Andrei Kvapil (kvaps) wants to merge 48 commits into
mainfrom
refactor-engine
Closed

Andrei Kvapil (kvaps) wants to merge 48 commits into
mainfrom
refactor-engine

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Nov 18, 2025 •

Copy link
Copy Markdown
Member

Overview

This PR introduces a significant architectural refactoring of Cozystack, moving from a static bundle-based configuration system to a dynamic, Kubernetes-native resource-driven architecture using custom resources and operators.

Major Changes

1. Introduction of New Custom Resources

Bundle API (cozystack.io/v1alpha1.Bundle)

  • Purpose: Replaces static YAML bundle definitions with a dynamic Kubernetes resource
  • Features:
    • Defines collections of Helm releases (packages) that can be installed together
    • Supports bundle dependencies via dependsOn mechanism
    • Allows defining dependency targets for cross-bundle references
    • Supports artifact generation for Helm charts
    • Includes library chart support
    • Configurable deletion policies (Delete/Orphan)
    • Base path configuration for source repositories

Platform API (cozystack.io/v1alpha1.Platform)

  • Purpose: Manages the core Cozystack platform installation
  • Features:
    • Declarative platform configuration
    • Source reference for platform charts
    • Helm values support
    • Configurable reconciliation intervals

2. New Cozystack Operator Component

  • New Component: cozystack-operator (separate from cozystack-controller)
  • Responsibilities:
    • Reconciles Bundle resources and creates corresponding HelmReleases
    • Reconciles Platform resources
    • Manages ArtifactGenerators for bundle artifacts
    • Handles namespace creation and management
    • Resolves bundle dependencies
    • Manages telemetry collection (moved from cozystack-controller)

3. ApplicationDefinition Refactoring

  • Replaced: CozystackResourceDefinition controller with ApplicationDefinition controller
  • Changes:
    • Simplified application definition management
    • Removed lookups for apps in platform controller
    • Better integration with the new bundle system

4. Artifact Generation System

  • New Feature: ArtifactGenerators and ExternalArtifacts
  • Purpose:
    • Build Helm charts from source repositories as artifacts
    • Reference artifacts in ApplicationDefinitions and bundles
    • Support OCI registry as artifact source
  • Implementation:
    • Uses FluxCD's source-watcher for artifact generation
    • Artifacts can be referenced by name in bundles and applications
    • Supports both GitRepository and OCIRepository sources

5. FluxCD Integration Improvements

  • Flux Version: Updated to FluxCD 2.7.x
  • New Package: flux-aio (All-In-One) package added to core
  • Source Watcher: Enabled and integrated for artifact generation
  • Network Policies: Disabled for Flux components to avoid probe issues
  • Embedded Manifests: Flux installation manifests embedded in operator

6. Bundle Architecture Migration

  • Old System: Static YAML files defining bundles (e.g., distro-full.yaml, paas-full.yaml)
  • New System: Bundle resources with structured definitions
  • New Bundle Structure:
    • iaas/bundle.yaml - Infrastructure-as-a-Service bundle
    • naas/bundle.yaml - Network-as-a-Service bundle
    • paas/bundle.yaml - Platform-as-a-Service bundle
    • system/bundle-*.yaml - System bundles (minimal, hosted, full)
  • Benefits:
    • Dynamic bundle management
    • Better dependency resolution
    • Easier customization and extension

7. Platform Package Restructuring

  • Templates Refactored:
    • Removed direct HelmRelease and HelmRepository templates
    • Added bundle-based templates
    • Migration hook for upgrading existing installations
    • ApplicationDefinitions template for managing apps
  • New Features:
    • Version tracking
    • Better namespace management

8. Migration System

  • New Component: Migration system for upgrading existing installations
  • Location: packages/core/platform/images/migrations/
  • Features:
    • Migration scripts (migrations 1-22)
    • Migration hook for automatic execution
    • Handles transition from old bundle system to new resource-based system

9. Telemetry Relocation

  • Moved: Telemetry collection from cozystack-controller to cozystack-operator
  • Rationale: Better separation of concerns, operator handles platform-level operations

10. Build System Improvements

  • Makefiles: Moved from scripts/ to hack/ directory
  • Common Scripts: Centralized in hack/ for better organization
  • Build Process: Updated to support new operator component

11. API and Controller Changes

  • API Server:
    • Updated to work with ApplicationDefinitions instead of CozystackResourceDefinitions
    • Improved label-based resource identification
    • Better integration with new bundle system
  • Controllers:
    • Removed: system_helm_reconciler.go, tenant_helm_reconciler.go
    • Added: namespace_helm_reconciler.go, applicationdefinition_controller.go
    • Simplified reconciliation logic

12. Application Package Updates

  • ExternalArtifacts: All application packages updated to use ExternalArtifacts instead of direct chart references
  • Consistency: Standardized artifact naming and referencing
  • Dependencies: Better dependency management between packages

Technical Details

New Dependencies

  • FluxCD source-watcher API v1beta1
  • Enhanced Helm controller integration
  • ArtifactGenerator CRD support

Removed Components

  • Static bundle YAML files
  • CozystackResourceDefinition CRD and controller
  • Old Helm reconciliation controllers
  • Direct Helm repository management in platform

New Components

  • Bundle and Platform CRDs
  • Cozystack operator
  • ArtifactGenerator reconciler
  • Migration system
  • Flux-aio package

Impact

This refactoring provides:

  1. Better Extensibility: Easier to add new bundles and applications
  2. Improved Maintainability: Kubernetes-native resources instead of static YAML
  3. Enhanced Flexibility: Dynamic bundle composition and dependencies
  4. Better Observability: Resource-based management enables better tracking
  5. Simplified Operations: Declarative platform and bundle management

Release note

[cozystack] refactor platform

@coderabbitai

coderabbitai Bot commented Nov 18, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

160 files out of 299 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-engine

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.

@kvaps Andrei Kvapil (kvaps) changed the title refactor engine [cozystack-operator] refactor platform chart Nov 18, 2025
@kvaps Andrei Kvapil (kvaps) changed the title [cozystack-operator] refactor platform chart [cozystack] refactor platform Nov 18, 2025
@kvaps
Andrei Kvapil (kvaps) force-pushed the refactor-engine branch 3 times, most recently from 3f9a966 to 98da8a4 Compare November 18, 2025 22:12
Signed-off-by: Andrei Kvapil <[email protected]>
@kvaps
Andrei Kvapil (kvaps) force-pushed the refactor-engine branch 2 times, most recently from 1b90089 to fb924e7 Compare November 19, 2025 14:01
Signed-off-by: Andrei Kvapil <[email protected]>
@kvaps
Andrei Kvapil (kvaps) force-pushed the refactor-engine branch 2 times, most recently from d8a115d to 71484d1 Compare November 19, 2025 14:28
Signed-off-by: Andrei Kvapil <[email protected]>
Signed-off-by: Andrei Kvapil <[email protected]>
Signed-off-by: Andrei Kvapil <[email protected]>
@kvaps
Andrei Kvapil (kvaps) force-pushed the refactor-engine branch 2 times, most recently from f33a75f to 977e633 Compare November 20, 2025 02:11
Signed-off-by: Andrei Kvapil <[email protected]>
@kvaps Andrei Kvapil (kvaps) changed the title [cozystack] refactor platform [cozystack] Major Architecture Refactoring Nov 25, 2025
@kvaps
Andrei Kvapil (kvaps) force-pushed the refactor-engine branch 6 times, most recently from fd54abd to 1e8de3c Compare November 26, 2025 08:02
@kingdonb

Kingdon Barrett (kingdonb) commented Nov 26, 2025 •

Copy link
Copy Markdown
Member

I'm not sure how well-supported the flux-aio distribution is. (For sure it will make the distribution incompatible with Flux Operator.) Are there other reasons for this switch than the CNI dependency?

I'm working on getting to be a Control Plane customer, to purchase Flux Enterprise - with Flux Operator it's very easy to drop in the Zero-CVE images distribution link. New flux patch releases (even without the Flux Enterprise) can be installed automatically and safely as soon as they become available, and we already do this with the 2.6.x, 2.7.x wildcard in our FluxInstance spec today. The old versions of Flux Operator can usually install newer Flux patch releases, I think, without upgrading Flux Operator first. (have to double check - this might not actually be true)

Still, Control Plane updates flux-operator with every Flux release, and it's the fastest way to get the latest version of Flux. With flux-aio, we will have to wait for Stefan Prodan to do the flux-aio release - which sometimes comes a bit later. For example, Flux 2.7.4 was released two days ago, but flux-aio is still on Flux 2.7.3. I don't think this is necessarily a deal-breaker but I want to take a breath and make some contact so I confirm that Flux-AIO is really going to be supported into the future before I let you make this change without comment :)

In reality, Flux 2.7 has been released for over a month and we're (Cozystack is) still on Flux 2.6, and that's partially conservativeness, I heard there were some regressions in the earlier 2.7 releases, but also partially just my fault, (been busy lately!) - I don't think Cozystack users have a high expectation of getting the latest Flux release instantly after it comes out, so maybe this is all fine.

If there are other reasons than CNI, I would like to understand them better before this architecture change is finalized.

I think that dropping the Flux Operator will also lose us the new (upcoming) Flux Status Page feature, that was announced at FluxCon.

@kingdonb

Kingdon Barrett (kingdonb) commented Nov 26, 2025 •

Copy link
Copy Markdown
Member

Also, I was excited to see the inclusion of ExternalArtifacts and the source-watcher in the updated architecture 💪

I should also mention:

Upgrade Procedure
Before upgrading to Flux v2.7, you need to run flux migrate on all clusters.

In case you haven't seen it in the Flux 2.7 upgrade notes:
https://github.com/stefanprodan/flux-aio/releases/tag/v2.7.3-0

https://github.com/fluxcd/flux2/releases/tag/v2.7.0#:~:text=S3%2Dcompatible%20storage.-,Upgrade%20procedure,-%E2%9A%A0%EF%B8%8F

The Flux Operator simplifies upgrades, see this section "Upgrade Procedure"

This is about migrating etcd storage. It isn't likely to have any impact on the way that Flux is used in Cozystack, based on the way it's currently used. Flux 2.7 is the first release to have this upgrade procedure requirement, the CLI now adds flux migrate - if you are using Flux Operator, it migrates the storage automatically. If you do not use it, you need to be aware of the new flux migrate command when doing a Flux upgrade. (Cozystack installer can run this in the migrate step, as it typically happens)

Anyway, in the general case, if your storage is in Git, and you upgrade your API versions on each resource by changing the API version in the file in the Git repository and pushing the change to Flux, that doesn't necessarily upgrade the storage version of the Flux resource in Etcd - until there is a change in resource version, Kubernetes will not touch the storage in etcd and the release will still be the same version, it is a "migrate-on-upgrade."

The flux migrate command forces the upgrade.

This is important when old beta APIs are finally deleted (really something that is maybe happening for the first time in Flux 2.7), in case the resources as they're defined in the cluster haven't changed since the API version moved from v1betaX to v1, then the storage won't be automatically migrated, and the upgrade will likely fail. It's just one extra step, not really a reason to not use flux-aio. I think that Stefan is going to continue building timoni and flux-aio - I think I can support this move. I just want to double-check and confirm everything so we're doing this as responsibly as possible.

@kingdonb

Copy link
Copy Markdown
Member

@kvaps
Andrei Kvapil (kvaps) force-pushed the refactor-engine branch 2 times, most recently from d6a8a40 to 49f86a9 Compare November 27, 2025 17:41
Signed-off-by: Andrei Kvapil <[email protected]>
@kingdonb

Copy link
Copy Markdown
Member

One major negative downside to removing Flux Operator, is it removes also the opportunity for Flux Enterprise users. (I just got my Flux Enterprise subscription, and am about to test enabling it on Cozystack)

This distro enables faster CVE responses, FIPS encryption, and other compliance checkboxes that would potentially be a blocker for example at my employer if they can't be covered. Flux Enterprise only covers these needs, Flux Upstream does just what the open source project supports. I'm not sure if your mind is made up about this already Andrei Kvapil (@kvaps)

@kingdonb

Kingdon Barrett (kingdonb) commented Dec 6, 2025 •

Copy link
Copy Markdown
Member

I guess this is free for the user to customize, if you will adopt flux-aio then I will support in my fork flux-operator and that is fine A-OK (it is a reversible decision and it will be easy enough for the user to switch it for themselves, whether they used a hypothetical distro-A or distro-B of Cozystack)

@kvaps

Andrei Kvapil (kvaps) commented Dec 6, 2025 •

Copy link
Copy Markdown
Member Author

Kingdon Barrett (@kingdonb) I'd like to preserve the opportunity of using flux enterprise with Cozystack.

Right now you have the option to disable flux management by cozystack-operator:

This way, you can install Flux manually via flux-operator and just let Cozystack use it.


Another idea is to provide oportunity to the user to specify kustomize patches for flux-aio. It could be preserved in Secret or ConfigMap. Would it be enough to install flux enterprise?

@kingdonb

Kingdon Barrett (kingdonb) commented Dec 6, 2025 •

Copy link
Copy Markdown
Member

I think so, yes. Have to come back to this when I can put hands on it. I had some troubles upgrading to 0.38 but they're all resolved now! The changelog is big this time 😅

BYO Flux sounds like a very reasonable interface! I think that flux-aio is probably also compatible with the images from the Flux Enterprise distribution, but that's something I'll need to check out for myself yet as well.

@kvaps

Andrei Kvapil (kvaps) commented Dec 9, 2025 •

Copy link
Copy Markdown
Member Author

We have decided to not merge this PR as-is, and go apply changes one-by-one.

The plan:

  • Migrate to flux-aio (kubectl apply from a script) + migration to remove the old Flux
  • Move the asset-server into a separate Deployment
  • Add labels to HelmReleases for CozystackResourceDefinitions, cozystack-controller, webhook, and the API server + migration (patch existing resources)
  • Get rid of lookups and drop hr reconcilers
  • Extract Talos into a separate component
  • cozystack-operator
  • remove the asset-server and switch to artifactgenerators and ocirepository/gitrepository + move Grafana dashboards into a separate Deployment
  • start installing the platform chart via Flux
  • move migrations into the platform chart

@kvaps

Copy link
Copy Markdown
Member Author

closed in favor #1816

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

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress kind/feature Categorizes issue or PR as related to a new feature size/XXL This PR changes 1000+ lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants