From 9bdf4effd102b006509c980d279e453beda27588 Mon Sep 17 00:00:00 2001
From: Vincent Dely
Date: Tue, 5 May 2026 02:04:10 +0200
Subject: [PATCH] feat(api): allow dependencies on any Kubernetes resource
Kustomizations can now depend on any Kubernetes object, improving
flexibility in release ordering and readiness behavior.
Signed-off-by: Vincent Dely
---
api/v1/kustomization_types.go | 2 +-
api/v1/reference_types.go | 23 +-
api/v1/zz_generated.deepcopy.go | 9 +-
...mize.toolkit.fluxcd.io_kustomizations.yaml | 27 ++-
docs/api/v1/kustomize.md | 51 +++-
.../controller/kustomization_controller.go | 90 ++++++--
.../kustomization_dependson_test.go | 217 +++++++++++++++++-
7 files changed, 380 insertions(+), 39 deletions(-)
diff --git a/api/v1/kustomization_types.go b/api/v1/kustomization_types.go
index 6bd217c3a..8e4f50d0f 100644
--- a/api/v1/kustomization_types.go
+++ b/api/v1/kustomization_types.go
@@ -50,7 +50,7 @@ type KustomizationSpec struct {
CommonMetadata *CommonMetadata `json:"commonMetadata,omitempty"`
// DependsOn may contain a DependencyReference slice
- // with references to Kustomization resources that must be ready before this
+ // with references to Kubernetes resources that must be ready before this
// Kustomization can be reconciled.
// +optional
DependsOn []DependencyReference `json:"dependsOn,omitempty"`
diff --git a/api/v1/reference_types.go b/api/v1/reference_types.go
index 07eb3b701..0ebdd9723 100644
--- a/api/v1/reference_types.go
+++ b/api/v1/reference_types.go
@@ -51,17 +51,32 @@ func (s *CrossNamespaceSourceReference) String() string {
return fmt.Sprintf("%s/%s", s.Kind, s.Name)
}
-// DependencyReference defines a Kustomization dependency on another Kustomization resource.
+// DependencyReference defines a Kustomization dependency on a Kubernetes resource.
+// When the dependency is a Kustomization, defaults are applied during reconciliation.
type DependencyReference struct {
- // Name of the referent.
+ // APIVersion of the resource to depend on, defaults to the Kustomization API
+ // group version when the dependency is a Kustomization.
+ // +optional
+ APIVersion string `json:"apiVersion,omitempty"`
+
+ // Kind of the resource to depend on, defaults to Kustomization.
+ // +optional
+ Kind string `json:"kind,omitempty"`
+
+ // Name of the resource to depend on.
// +required
Name string `json:"name"`
- // Namespace of the referent, defaults to the namespace of the Kustomization
- // resource object that contains the reference.
+ // Namespace of the resource to depend on, defaults to the namespace of the
+ // Kustomization resource object that contains the reference.
// +optional
Namespace string `json:"namespace,omitempty"`
+ // Ready checks if the resource Ready status condition is true, defaults to
+ // true when the dependency is a Kustomization.
+ // +optional
+ Ready *bool `json:"ready,omitempty"`
+
// ReadyExpr is a CEL expression that can be used to assess the readiness
// of a dependency. When specified, the built-in readiness check
// is replaced by the logic defined in the CEL expression.
diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go
index 231b5b525..f63570e18 100644
--- a/api/v1/zz_generated.deepcopy.go
+++ b/api/v1/zz_generated.deepcopy.go
@@ -94,6 +94,11 @@ func (in *Decryption) DeepCopy() *Decryption {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DependencyReference) DeepCopyInto(out *DependencyReference) {
*out = *in
+ if in.Ready != nil {
+ in, out := &in.Ready, &out.Ready
+ *out = new(bool)
+ **out = **in
+ }
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DependencyReference.
@@ -176,7 +181,9 @@ func (in *KustomizationSpec) DeepCopyInto(out *KustomizationSpec) {
if in.DependsOn != nil {
in, out := &in.DependsOn, &out.DependsOn
*out = make([]DependencyReference, len(*in))
- copy(*out, *in)
+ for i := range *in {
+ (*in)[i].DeepCopyInto(&(*out)[i])
+ }
}
if in.Decryption != nil {
in, out := &in.Decryption, &out.Decryption
diff --git a/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml b/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml
index beeff81f0..20c6feafa 100644
--- a/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml
+++ b/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml
@@ -137,20 +137,35 @@ spec:
dependsOn:
description: |-
DependsOn may contain a DependencyReference slice
- with references to Kustomization resources that must be ready before this
+ with references to Kubernetes resources that must be ready before this
Kustomization can be reconciled.
items:
- description: DependencyReference defines a Kustomization dependency
- on another Kustomization resource.
+ description: |-
+ DependencyReference defines a Kustomization dependency on a Kubernetes resource.
+ When the dependency is a Kustomization, defaults are applied during reconciliation.
properties:
+ apiVersion:
+ description: |-
+ APIVersion of the resource to depend on, defaults to the Kustomization API
+ group version when the dependency is a Kustomization.
+ type: string
+ kind:
+ description: Kind of the resource to depend on, defaults to
+ Kustomization.
+ type: string
name:
- description: Name of the referent.
+ description: Name of the resource to depend on.
type: string
namespace:
description: |-
- Namespace of the referent, defaults to the namespace of the Kustomization
- resource object that contains the reference.
+ Namespace of the resource to depend on, defaults to the namespace of the
+ Kustomization resource object that contains the reference.
type: string
+ ready:
+ description: |-
+ Ready checks if the resource Ready status condition is true, defaults to
+ true when the dependency is a Kustomization.
+ type: boolean
readyExpr:
description: |-
ReadyExpr is a CEL expression that can be used to assess the readiness
diff --git a/docs/api/v1/kustomize.md b/docs/api/v1/kustomize.md
index 11624c6c1..260d485f2 100644
--- a/docs/api/v1/kustomize.md
+++ b/docs/api/v1/kustomize.md
@@ -97,7 +97,7 @@ overridden if its key matches a common one.
(Optional)
DependsOn may contain a DependencyReference slice
-with references to Kustomization resources that must be ready before this
+with references to Kubernetes resources that must be ready before this
Kustomization can be reconciled.
|
@@ -653,7 +653,8 @@ field.
(Appears on:
KustomizationSpec)
-DependencyReference defines a Kustomization dependency on another Kustomization resource.
+DependencyReference defines a Kustomization dependency on a Kubernetes resource.
+When the dependency is a Kustomization, defaults are applied during reconciliation.