Reputation: 109
I have an application with different versions. The base resource file for each version is slightly different. But the patch which needs to be applied to the base file is same. What should be the best structure to apply the same patch to different base resource and have different output files respectively.
/base1/
/app-v1
/kustomization.yaml
/base2/
/app-v2
/kustomization.yaml
/overlays/
/dev/
/staging/
How should I specify the resource to make the overlay and patch in base kustomization.yaml which are same to v1 and v2 apply to the different base files?
Ideally, use different kustomize build
command for different base but using same patch file.
Upvotes: 2
Views: 6174
Reputation: 1992
You can use components: https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/1802-kustomize-components
Goals: ... Provide the implementation that allows users to define components, i.e., portable overlays that are able to modify a set of base resources without conflicts, since patches are serialized
This would apply /components/patch-bases/patch.yaml
to base1 and base2 in dev and staging:
/components/patch-bases/patch.yaml
<a patch>
/components/patch-bases/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
patches:
- path: patch.yaml
target: <selector matching all objects>
/overlays/dev/kustomization.yaml
bases:
- ../../base1
- ../../base2
components:
- ../../components/patch-bases
<overlay-specific stuff>
/overlays/staging/kustomization.yaml
bases:
- ../../base1
- ../../base2
components:
- ../../components/patch-bases
<overlay-specific stuff>
Upvotes: 0
Reputation: 5042
One way to do it would be to have a kustomization file in /overlays/
, including patches and configurations from dev/
and staging/
. Eg:
$> cat ./overlays/kustomization.yaml
resources:
- ./dev/foo.yaml
- ./staging/bar.yaml
patchesJson6902:
- target:
version: v1
groups: apps
kind: Deployment
name: my-app
patch: ./dev/patch-deploy.yaml
And include that overlays
folder from your base1 and base2 kustomization:
$> cat ./base1/kustomization.yaml
resources:
- ./app-v1/stuff.yaml
- ../overlays/
[...]
$> cat ./base2/kustomization.yaml
resources:
[...]
- ../overlays/
Then, you can run kustomization from either base folder, while they would all process the content of your overlays folder.
Upvotes: 1