-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
What happened?
The use of bases inkustomization.yaml files was deprecated in version v2.1.0. Instead users should make use of the resources field for both bases and resources.
If bases is replaced with resources due to the deprecation of bases and a resources already exists within the kustomization.yaml file, any previous occurrences gets replaced with the value of the final resources field.
This removes all previously defined resources which can in turn cause a lot of deletions.
While this may sound a bit silly, some businesses use Kustomize with extremely large codebases which include hundreds of resources/bases within the root kustomization file and perhaps almost as many further down the chain.
In our particular case, bases was updated to resources and as the file included so many more resources a duplicate resources field existed but was missed further down the file.
Unfortunately this was also not picked up during review.
The first occurrence included PVCs among other stateful resources that ended up being deleted.
The problem in this case was down to user error however I believe that there are several ways that this could be avoided.
- Validate that the files are valid YAML (if I understand correctly, you can't have duplicate map keys in YAML) and error
- Combine the contents of each
resourcesfield - Anything else?
It's a little worrying to think that there must be thousands of cases where the potential for this to occur is high. So although I completely understand that this is a case of someone being a bit dumb, overworked etc., I think it's worth trying to address.
What did you expect to happen?
Either fail with a message such as 'duplicate resources field in file '
or
Combine all values of resources into a single resources
How can we reproduce it (as minimally and precisely as possible)?
PR showing how to reproduce it in test
Expected output
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-deployment-bases
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80Actual output
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
name: nginx
ports:
- containerPort: 80Kustomize version
v5.3.0
Operating system
MacOS