Skip to content

Using edit add label with the --without-selector flag without pre-existing labels causes an error #5978

@DGoldfayn

Description

@DGoldfayn

What happened?

When using:

kustomize --stack-trace edit add label --without-selector test1:a test2:b

On a kustomization.yaml without pre-existing

labels:
  - pairs:
      environment: dev

causes the following error:

Error: label test2 already in kustomization file. Use --force to override.

IMPORTANT:

The following permutations allow it to work:

  • Use the --force flag
  • Omit the --without-selector flag
  • Have pre-existing labels in the kustomization.yaml (see above)

What did you expect to happen?

The labels should be added like so:

labels:
- pairs:
    test1: a
    test2: b

How can we reproduce it (as minimally and precisely as possible)?

# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources.yaml
# resources.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-object
data:
  placeholder: data

You can omit resources.yaml the error happens on an empty kustomization file too.

Expected output

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources.yaml
labels:
- pairs:
    test1: a
    test2: b

Actual output

Error: label test2 already in kustomization file. Use --force to override.

Kustomize version

5.7.1

Operating system

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions