Skip to content

Bases deprecated - multiple resources in kustomization.yaml causes previous to be overwritten #5547

@dippydocus

Description

@dippydocus

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 resources field
  • 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: 80

Actual 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

Kustomize version

v5.3.0

Operating system

MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.triage/needs-informationIndicates an issue needs more information in order to work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions