Description
Summary
Having the possibility to define an application with optional spec.source.kustomize.components/patches[]
items.
Motivation
Here is my usecase: I use an applicationSet to define a set of (mostly) common apps over several clusters. Some of those apps are Helm charts, some are kustomize base, etc.
I need to have common settings at different "generalization levels" (currently : global, zone, prod_level, cluster-specific).
All of my apps are defined in a git repository and have the following structure
app
├── clusters
├── prlvl
└── zones
Where all of clusters,prlvl,zones are optional.
This works well with helm apps with the following template:
template:
metadata: {}
spec:
destination: {}
project: default
sources:
- repoURL: "{{ repository }}"
targetRevision: "{{ version }}"
chart: "{{ chart }}"
helm:
releaseName: "{{ values.application }}"
ignoreMissingValueFiles: true
valueFiles:
- "$values/{{ values.application}}/values.yml"
- "$values/{{ values.application}}/zones/{{ values.zone }}/values.yml"
- "$values/{{ values.application}}/prlvl/{{ values.prlvl }}/values.yml"
- "$values/{{ values.application}}/clusters/{{ values.cluster }}/values.yml"
- repoURL: "<REDACTED>.git"
targetRevision: feat/merged_config
ref: values
However, I'm not sure how to make that works in a similiar way for kustomize apps. My current template:
template:
metadata: {}
spec:
destination: {}
project: default
source:
repoURL: "<REDACTED>.git"
path: "{{ values.application }}"
targetRevision: feat/merged_config
kustomize:
components:
- zones/{{ values.zone }}
- prlvl/{{ values.prlvl }}
- clusters/{{ values.cluster }}
But this trigger a Sync error when one the components is missing.
N.B : both template are part of one applicationSet, and attached to top-level generators (which are pretty involved themselves, but that's not relevant to that part, I think).
Proposal
I think ignoreMissingValueFiles
is a good candidate to use as an example. The application controller could check if the components
/ patches
exists before passing them to kustomize edit, and prune them out if they don't.
FYI, this is the message with my current template:
ComparisonError
Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = Unknown desc = Manifest generation error (cached): `kustomize edit add component zones/phm prlvl/pr clusters/prsatk8s` failed exit status 1: Error: zones/<REDACTED> has no match: must build at directory: not a valid directory: evalsymlink failure on '<path to cached source>/google-site-verif/zones/phm' : lstat <path to cached source>/google-site-verif/zones: no such file or directory Usage: kustomize edit add component [flags] Examples: add component {filepath} Flags: -h, --help help for component Global Flags: --stack-trace print a stack-trace on error