From b25dea8366a4349872ab980cbc9596ffb42b3999 Mon Sep 17 00:00:00 2001 From: Kristian Klausen Date: Fri, 28 Oct 2022 14:14:57 +0200 Subject: [PATCH] Add support for Kustomize components Fix #753 Signed-off-by: Kristian Klausen --- api/v1beta2/kustomization_types.go | 4 +++ api/v1beta2/zz_generated.deepcopy.go | 5 ++++ ...mize.toolkit.fluxcd.io_kustomizations.yaml | 6 +++++ docs/api/kustomize.md | 24 +++++++++++++++++ docs/spec/v1beta2/kustomization.md | 26 +++++++++++++++++++ go.mod | 2 +- go.sum | 4 +-- 7 files changed, 68 insertions(+), 3 deletions(-) diff --git a/api/v1beta2/kustomization_types.go b/api/v1beta2/kustomization_types.go index 09a5739b..6b307ff8 100644 --- a/api/v1beta2/kustomization_types.go +++ b/api/v1beta2/kustomization_types.go @@ -153,6 +153,10 @@ type KustomizationSpec struct { // +kubebuilder:validation:Enum=none;client;server // +optional Validation string `json:"validation,omitempty"` + + // Components specifies relative paths to specifications of other Components + // +optional + Components []string `json:"components,omitempty"` } // Decryption defines how decryption is handled for Kubernetes manifests. diff --git a/api/v1beta2/zz_generated.deepcopy.go b/api/v1beta2/zz_generated.deepcopy.go index 93ab196c..0ef46eab 100644 --- a/api/v1beta2/zz_generated.deepcopy.go +++ b/api/v1beta2/zz_generated.deepcopy.go @@ -187,6 +187,11 @@ func (in *KustomizationSpec) DeepCopyInto(out *KustomizationSpec) { *out = new(v1.Duration) **out = **in } + if in.Components != nil { + in, out := &in.Components, &out.Components + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KustomizationSpec. diff --git a/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml b/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml index 0b4cc2a0..13a3cc30 100644 --- a/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml +++ b/config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml @@ -585,6 +585,12 @@ spec: description: KustomizationSpec defines the configuration to calculate the desired state from a Source using Kustomize. properties: + components: + description: Components specifies relative paths to specifications + of other Components + items: + type: string + type: array decryption: description: Decrypt Kubernetes secrets before applying them on the cluster. diff --git a/docs/api/kustomize.md b/docs/api/kustomize.md index a12e5d0f..bd2c8cd5 100644 --- a/docs/api/kustomize.md +++ b/docs/api/kustomize.md @@ -367,6 +367,18 @@ string

Deprecated: Not used in v1beta2.

+ + +components
+ +[]string + + + +(Optional) +

Components specifies relative paths to specifications of other Components

+ + @@ -816,6 +828,18 @@ string

Deprecated: Not used in v1beta2.

+ + +components
+ +[]string + + + +(Optional) +

Components specifies relative paths to specifications of other Components

+ + diff --git a/docs/spec/v1beta2/kustomization.md b/docs/spec/v1beta2/kustomization.md index f45e5edc..23ec2853 100644 --- a/docs/spec/v1beta2/kustomization.md +++ b/docs/spec/v1beta2/kustomization.md @@ -556,6 +556,7 @@ offering support for the following Kustomize directives: - [namespace](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/namespace/) - [patches](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/patches/) - [images](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/images/) +- [components](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/components/) ### Target namespace @@ -654,6 +655,31 @@ spec: digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3 ``` +### Components + +To add [Kustomize `components` entries](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/components/) +to the configuration, and use reusable pieces of configuration logic that can +be included from multiple overlays, `spec.components` can be defined: + +```yaml +apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 +kind: Kustomization +metadata: + name: podinfo + namespace: flux-system +spec: + # ...omitted for brevity + components: + - ingress + - tls +``` + +**Note:** The component paths must be local and relative. + +**Warning:** Components are a alpha feature in Kustomize and are therefore +considered experimental in Flux. No guarantees are provided and the feature may +be modified in backwards incompatible ways or removed without warning. + ## Variable substitution With `spec.postBuild.substitute` you can provide a map of key/value pairs holding the diff --git a/go.mod b/go.mod index 5d16fbb9..6bfd9f44 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/fluxcd/pkg/apis/kustomize v0.7.0 github.com/fluxcd/pkg/apis/meta v0.18.0 github.com/fluxcd/pkg/http/fetch v0.3.0 - github.com/fluxcd/pkg/kustomize v0.10.0 + github.com/fluxcd/pkg/kustomize v0.11.0 github.com/fluxcd/pkg/runtime v0.24.0 github.com/fluxcd/pkg/ssa v0.22.0 github.com/fluxcd/pkg/tar v0.2.0 diff --git a/go.sum b/go.sum index c75236fa..14f8379c 100644 --- a/go.sum +++ b/go.sum @@ -236,8 +236,8 @@ github.com/fluxcd/pkg/apis/meta v0.18.0 h1:s0LeulWcQ4DxVX6805vgDTxlA6bAYk+Lq1QHS github.com/fluxcd/pkg/apis/meta v0.18.0/go.mod h1:pYvXRFi1UKNNrGR34jw3uqOnMXw9X6dTkML8j5Z7tis= github.com/fluxcd/pkg/http/fetch v0.3.0 h1:/mLj0IzTx+GhR09etzMJsBoNQ0qeOx9cSdeUgRB+oqM= github.com/fluxcd/pkg/http/fetch v0.3.0/go.mod h1:dHTDYIeL0ZAQ9mHM6ZS4VProxho+Atm73MHJ55yj0Sg= -github.com/fluxcd/pkg/kustomize v0.10.0 h1:EG5MbYrLtxeCiZxeFUgvyBhFZaXnKfeqqpg7O+J7o3s= -github.com/fluxcd/pkg/kustomize v0.10.0/go.mod h1:awHID4OKe2/WAfTFg4u0fURXZPUkrIslSZNSPX9MEFQ= +github.com/fluxcd/pkg/kustomize v0.11.0 h1:zseS9LRUuzhP/7KamccmsOgYpJAdhqtsf+2wN/CHF3I= +github.com/fluxcd/pkg/kustomize v0.11.0/go.mod h1:awHID4OKe2/WAfTFg4u0fURXZPUkrIslSZNSPX9MEFQ= github.com/fluxcd/pkg/runtime v0.24.0 h1:rQmm5Xq8K7f8xcPj1oNOInM1x4YwmgTucZJOP51Xmr4= github.com/fluxcd/pkg/runtime v0.24.0/go.mod h1:I2T+HWVNzX0cxm9TgH+SVNHTwqlmEDiSke43JXsq9iY= github.com/fluxcd/pkg/ssa v0.22.0 h1:HvJTuiYLZMxCjin7bAqBgnc2RjSqEfYrMbV5yINoM64=