Kustomize - how to apply values on variables used in the base overlay ConfigMap?

49 Views Asked by At

I have the following file structure:

.
├── base/
│   ├── some_image_1/
│   │   ├── ...
│   │   ├── kustomization.yaml
│   │   └── config-map-image-1.yaml
│   ├── some_image_2/
│   │   └── ...
│   ├── some_image_3/
│   ├── ...
│   ├── global-config-map.yaml
│   └── kustomization.yaml
└── overlays/
    ├── dev/
    │   ├── kustomization.yaml
    │   └── dev-configmap.yaml
    └── prod/
        └── ...

config-map-image-1.yaml contains variables used in it's deployments which will be overridden by the global-config-map.yaml. The values there also have variables, that will be overridden in each overlay. So something like this:

# config-map-image-1.yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: image-1-configmap
data:
  CUSTOM_CSS_BUCKET: $(BUCKET_CONF)


# global-config-map.yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: global-configmap
data:
  BUCKET_CONF: "config-bucket-$(ENV)-environment"


# dev-configmap.yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: dev-configmap
data:
  ENV: "dev"

The kustomization.yaml for each image is pretty basic, along the lines of:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ...

configurations:
- ...

patchesStrategicMerge:
- config-map-image-1.yaml

(Or without patchesStrategicMerge and config map in resources).

The root kustomization.yaml of the base is more complicated, because it uses vars (and replacements, configurations, patches too). The values from the global-config-map.yaml are used in the vars section too:

# base's root kustomize.yaml
...
resources:
- global-config-map.yaml
- ...

...

vars:
- fieldref:
    fieldPath: data.BUCKET_CONF
  name: BUCKET_CONF
  objref:
    apiVersion: v1
    kind: ConfigMap
    name: global-configmap
...

The kustomization.yaml of the dev overlay is:

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: gnp-beeplugin-dev
resources:
- dev-configmap.yaml
- ../../base

configurations:
- configs.yaml

vars:
- name: ENV
  objref:
    apiVersion: v1
    kind: ConfigMap
    name: dev-configmap
  fieldref:
    fieldPath: data.ENV

configs.yaml contains:

varReference:
- path: data
  kind: ConfigMap

How should I properly define the kustomization.yaml for each overlay? How should I modify the kustomization.yaml of the base overlay?

Currently, when I run kustomize build on the base overlay I receive, in short:

# result from base
apiVersion: v1
kind: ConfigMap
metadata:
  name: image-1-configmap
data:
  CUSTOM_CSS_BUCKET: config-bucket-$(ENV)-environment
....

apiVersion: v1
kind: ConfigMap
metadata:
  name: global-configmap
data:
  BUCKET_CONF: config-bucket-$(ENV)-environment

Which is fine and expected, but when I run kustomize build from the dev overlay, the only place the values change correctly are in global-configmap and no where else. I would expect the CUSTOM_CSS_BUCKET value to contain dev and not $(ENV).

What am I missing? How can I apply the dev-configmap before global-configmap is applied on all the images?

Kustomize version: v5.3.0

0

There are 0 best solutions below