Skip to content

feat(api): extend DependencyReference type to support any Kubernetes resource#1229

Draft
vecil wants to merge 3 commits into
fluxcd:mainfrom
vecil:feat/extend-dependencyreference-type
Draft

feat(api): extend DependencyReference type to support any Kubernetes resource#1229
vecil wants to merge 3 commits into
fluxcd:mainfrom
vecil:feat/extend-dependencyreference-type

Conversation

@vecil

@vecil vecil commented Jun 4, 2026

Copy link
Copy Markdown

Summary

The shared DependencyReference type now supports depending on any Kubernetes object, improving flexibility in release ordering and readiness handling.

Dependencies can reference arbitrary Kubernetes resources and are considered satisfied based on either existence or readiness (via the new ready field). The runtime/dependency sort package has been updated to operate on typed references, so dependencies across different apiVersion/kind combinations are correctly ordered and cycle-checked. The new TypedNamespacedObjectReference type carries the same shape as the previous NamespacedObjectReference plus the apiVersion and kind fields, and MakeDependsOn now parses the new apiVersion/Kind/[namespace/]name[:ready][@readyExpr] format.

Changes include:

  • Extend DependencyReference with optional apiVersion, kind, and ready fields, and add a TypedNamespacedObjectReference type for typed cross-resource references
  • Extend MakeDependsOn to parse apiVersion/Kind/[namespace/]name[:ready][@readyExpr] strings, with backward-compatible parsing of the existing name and namespace/name formats
  • Render the new fields in DependencyReference.String() so dependencies round-trip correctly
  • Update runtime/dependency.Sort to return TypedNamespacedObjectReference, require GetAPIVersion()/GetKind() on the Dependent interface, and only default the dependency namespace when the kind matches the parent
  • Improve tests to cover arbitrary resource types, the ready toggle, and cross-kind dependency graphs

Relates fluxcd/flux2#5879

@vecil vecil changed the title feat(api): extend DependencyReference type to support any Kubernetes … feat(api): extend DependencyReference type to support any Kubernetes resource Jun 4, 2026
Comment thread runtime/dependency/sort.go
Comment thread apis/meta/reference_types.go Outdated
Comment on lines +87 to +96
// APIVersion of the resource to depend on, defaults to the API group version of the
// Flux Applier API resource (Kustomization or HelmRelease) that contains the reference
// when the dependency is of the same kind.
// +optional
APIVersion string `json:"apiVersion,omitempty"`

// Kind of the resource to depend on, defaults to the kind of the
// Flux Applier API resource (Kustomization or HelmRelease) that contains the reference.
// +optional
Kind string `json:"kind,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because most API types would normally require a custom ReadyExpr anyway, we would like to make it so that if the API group (ignoring the version) or the kind differ from the type managed by the respective controller, then ReadyExpr becomes mandatory.

This means everything except Kustomization will require ReadyExpr in kustomize-controller, and everything except HelmRelease will require ReadyExpr in helm-controller.

Maybe we can add xvalidation rule with a CEL expression to the DependsOn field in each controller to enforce this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If the ReadyExpr-only approach is adopted, this proposal would provide a clear separation of behavior between HR-to-HR/KS-to-KS and cross-resource dependencies, and would reduce the cognitive load of writing such dependency rules 👍

@vecil vecil Jun 7, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

On second thought, I have the feeling this proposal would introduce additional complexity when defining dependencies on resource types other than Appliers. Built-in readiness checks based on fluxcd/cli-utils/pkg/kstatus/status types and functions may already cover many use cases.

However, the proposed xvalidation rule introduces a limitation: it would require readyExpr to always be set, even when no custom check is desired. This prevents relying solely on built-in readiness checks in cases where they would otherwise be sufficient.

  • When the AdditiveCELDependencyCheck feature gate is enabled, built-in readiness checks will always run alongside required readyExpr, with only the overhead of specifying a value (e.g. "true").
  • When the gate is disabled, requiring readyExpr via xvalidation would prevent users from relying on built-in readiness checks alone.

@matheuscscp

Copy link
Copy Markdown
Member

@vecil I think we can try and implement as much as possible of this feature in this repo. Besides the new types/fields in apis/meta, we can add also more logic to runtime/dependency as much as possible to slim down the code in the controllers. Unfotunately we will need the xvalidations in the respective DependsOn struct fields of each controller due to them being different, as they depend on the respective type managed by that controller. But I think a large part of the code could be implemented in runtime/dependency, maybe even existing code in the controllers.

One more thing: we need the schema validations that will be applied via xvalidations in the DependsOn struct fields of each controller to also be checked in the Reconcile() loop, this is a standard we have all across Flux to keep validation tight and error messages clear. This is so old API servers not supporting xvalidation still get guarded asynchronously after admission.

…resource

Dependencies can now be expressed on any Kubernetes object, improving
flexibility in release ordering and readiness behavior.

Signed-off-by: Vincent Dely <vincent.dely@ik.me>
@vecil vecil force-pushed the feat/extend-dependencyreference-type branch from 6d1005a to eac54d9 Compare June 7, 2026 10:21
…values

The `Ready` field is removed from the `DependencyReference` type.
To perform an existence check on a dependency, `ReadyExpr` can be
set to `"true"`, effectively disabling readiness checks.

Tests now use the `dep` variable as expected by Applier controllers.

Signed-off-by: Vincent Dely <vincent.dely@ik.me>
@vecil vecil force-pushed the feat/extend-dependencyreference-type branch from eac54d9 to 4712b5a Compare June 7, 2026 10:28
…nto shared SDK

Dependency checking is consolidated into runtime/dependency so
helm-controller and kustomize-controller share the same implementation.

Signed-off-by: Vincent Dely <vincent.dely@ik.me>
Assisted-by: opencode/minimax-m3-free, opencode/mimo-v2.5-free
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants