feat(api): extend DependencyReference type to support any Kubernetes resource#1229
feat(api): extend DependencyReference type to support any Kubernetes resource#1229vecil wants to merge 3 commits into
Conversation
| // 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"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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
AdditiveCELDependencyCheckfeature gate is enabled, built-in readiness checks will always run alongside requiredreadyExpr, with only the overhead of specifying a value (e.g."true"). - When the gate is disabled, requiring
readyExprvia xvalidation would prevent users from relying on built-in readiness checks alone.
|
@vecil I think we can try and implement as much as possible of this feature in this repo. Besides the new types/fields in One more thing: we need the schema validations that will be applied via xvalidations in the |
…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>
6d1005a to
eac54d9
Compare
…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>
eac54d9 to
4712b5a
Compare
…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
Summary
The shared
DependencyReferencetype 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
readyfield). Theruntime/dependencysort package has been updated to operate on typed references, so dependencies across differentapiVersion/kindcombinations are correctly ordered and cycle-checked. The newTypedNamespacedObjectReferencetype carries the same shape as the previousNamespacedObjectReferenceplus theapiVersionandkindfields, andMakeDependsOnnow parses the newapiVersion/Kind/[namespace/]name[:ready][@readyExpr]format.Changes include:
DependencyReferencewith optionalapiVersion,kind, andreadyfields, and add aTypedNamespacedObjectReferencetype for typed cross-resource referencesMakeDependsOnto parseapiVersion/Kind/[namespace/]name[:ready][@readyExpr]strings, with backward-compatible parsing of the existingnameandnamespace/nameformatsDependencyReference.String()so dependencies round-trip correctlyruntime/dependency.Sortto returnTypedNamespacedObjectReference, requireGetAPIVersion()/GetKind()on theDependentinterface, and only default the dependency namespace when the kind matches the parentreadytoggle, and cross-kind dependency graphsRelates fluxcd/flux2#5879