I have sizeLimit property under emptyDir set to 2Gi in my template base file. I want to remove the sizelimit and just have emptyDir: {}. I've been unable to achieve this using Kustomization overlays. I will detail my folder structure and kustomization yamls below.
Folder Structure:
application
├── majorbase
│ ├── kustomization.yaml
│ └── resources
│ └── web-template.yaml
├── minorbase
│ ├── kustomization.yaml
│ └── resources
└── myoverlays
├── kustomization.yaml
└── resources
└── my-new-web.yaml
The folder myoverlays contains the following contents in it's kustomization.yaml file
bases:
- ../minorbase
patchesStrategicMerge:
- resources/my-new-web.yaml
The folder minorbase contains the following contents in it's kustomization.yaml file
bases:
- ../majorbase
The folder majorbase contains the following contents in it's kustomization.yaml file
resources:
- resources/web-template.yaml
The section I want to edit looks like this in the majorbase/template.
volumes:
- name: test-vol
emptyDir:
sizeLimit: "2Gi"
The above configuration needs to be updated using overlays as below.
volumes:
- name: test-vol
emptyDir: {}
This is where my problem lies. Kustomization just picks the 2Gi value mentioned in the base whenever I remove the sizelimit in my overlays. When I mention different value to sizeLimit such as "1Gi" in my overlays file, kustomization is picking up the change. What is the cause of this behaviour? Is it possible to achieve what I'm trying to do here?
NB: This answer assumes a recent version of Kustomize (I'm running 4.5.2 locally). Your examples are using deprecated syntax (the bases section was deprecated in version 2.1.0, for example).
Your problem is that you're using a strategicMerge patch, and you're merging and empty map ({}) with {"sizeLimit": "26gi"}. If you merge an empty map with anything, it's a no-op: you end up with the "anything".
To explicitly delete an element, you have a few choices.
You can use the $patch: replace directive (you can find an example of that here) to have Kustomize replace the emptyDir element, rather than merging the contents. That would look like:
apiVersion: v1
kind: Pod
metadata:
name: example
spec:
volumes:
- name: test-vol
emptyDir:
$patch: replace
The corresponding kustomization.yaml might look something like:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
patches:
- path: resources/my-new-web.yaml
Alternately, you can use a JSONPatch patch, which is good for explicitly deleting fields:
- path: /spec/volumes/0/emptyDir/sizeLimit
op: remove
Where kustomization.yaml would look like:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ....//base
patches:
- target:
kind: Pod
name: example
path: resources/my-new-web.yaml
You can find a complete runnable demonstration of this here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With