Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configMapGenarator merge behaviour only allows for one override, ignores subsequent overrides #5250

Closed
Gekalash opened this issue Jul 26, 2023 · 9 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/support Categorizes issue or PR as a support question. triage/duplicate Indicates an issue is a duplicate of other open issue. triage/needs-information Indicates an issue needs more information in order to work on it.

Comments

@Gekalash
Copy link

What happened?

configMapGenarator merge behaviour changed between Kustomize v4 and Kustomize v5.
In v4, multiple overrides could be applied to the same value in the configMapGenerator, with the last one applied becoming the final value.
In v5, only the first override is applied, and any subsequent ones are ignored.

What did you expect to happen?

Expected compatible manifests to produce the same results when rendered with Kustomize v4 and v5.

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

# base/kustomization.yaml
configMapGenerator:
  - name: literals-configmap
    literals:
      - literal_variable_one=base-value
# component/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

configMapGenerator:
  - name: literals-configmap
    behavior: merge
    literals:
      - literal_variable_one=component-value
      - literal_variable_two=component-value-two
# overlay/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../base

components:
  - ../component

configMapGenerator:
  - name: literals-configmap
    behavior: merge
    literals:
      - literal_variable_one=overlay-value
      - literal_variable_two=overlay-value-two

Expected output

apiVersion: v1
data:
  literal_variable_one: overlay-value
  literal_variable_two: overlay-value-two
kind: ConfigMap
metadata:
  name: literals-configmap-6t592hc2f7

Actual output

apiVersion: v1
data:
  literal_variable_one: component-value
  literal_variable_two: component-value-two
kind: ConfigMap
metadata:
  name: literals-configmap-b8d9m4h5k2

Kustomize version

5.1.0

Operating system

MacOS

@Gekalash Gekalash added the kind/bug Categorizes issue or PR as related to a bug. label Jul 26, 2023
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jul 26, 2023
@valaparthvi
Copy link

/assign valaparthvi

@natasha41575
Copy link
Contributor

Thanks @valaparthvi! Please see if you can reproduce the issue by comparing the output of kustomize build on v4 vs v5.

@annasong20
Copy link
Contributor

I suspect this has to do with #5170. merge behavior is probably the same, but components is run after configMapGenerator. If @Gekalash cannot workaround this order change, please leave your feedback at #5170.

@valaparthvi please continue to try to reproduce.

@Gekalash
Copy link
Author

A workaround could be – implement the overrides from the conifgMapGenerator as a component, and import it that way, but that's clunky in my particular situation where I have an assortment of overlays that share many things in common, and I only override a thing or two differently for each overlay. So this workaround strategy would imply creating a large number of use-only-once components. That is, undesirable.
I'll see if I can make a PR with a test case that reproduces this issue in an automated way

Gekalash added a commit to Gekalash/kustomize that referenced this issue Aug 14, 2023
Gekalash added a commit to Gekalash/kustomize that referenced this issue Aug 15, 2023
@valaparthvi
Copy link

I can reproduce this.

$ tree                            
.
├── base
│   └── kustomization.yaml
├── component
│   └── kustomization.yaml
└── overlay
    └── kustomization.yaml

3 directories, 3 files
Kustomize 4 output

$ kustomize4 build ./overlay            
apiVersion: v1
data:
  literal_variable_one: overlay-value
  literal_variable_two: overlay-value-two
kind: ConfigMap
metadata:
  name: literals-configmap-6t592hc2f7

Kustomize 5 output

$ kustomize5 build ./overlay  
apiVersion: v1
data:
  literal_variable_one: component-value
  literal_variable_two: component-value-two
kind: ConfigMap
metadata:
  name: literals-configmap-b8d9m4h5k2

@annasong20
Copy link
Contributor

Hi @Gekalash, we have confirmed that the issues is not in the configMapGenerator field.

We tried to run your example with only the configMapGenerator in the overlay, and that merged correctly. Next, as @valaparthvi confirmed, with both the components and configMapGenerator calls in the overlay, the components merge values won in the end because components are now executed after generators and transformers.

This was documented in this Kustomize release. As stated there, #4402 should solve your use case because you'll be able to specify the order that Kustomize fields run in. However, if its implementation is not fast enough for your use case, we invite you to leave feedback on #5141. If there is enough demand there, we'd be interested in coming up with a temporary solution.

Regarding your proposal

A workaround could be – implement the overrides from the conifgMapGenerator as a component, and import it that way

could you provide us with more information? If you want the override values from the overlay configMapGenerator, we're wondering why you can't just leave out the Component. Is it because the Component contains other relevant changes? Some more context could be helpful.

/kind duplicate
/triage needs-information

@k8s-ci-robot k8s-ci-robot added the triage/needs-information Indicates an issue needs more information in order to work on it. label Aug 30, 2023
@k8s-ci-robot
Copy link
Contributor

@annasong20: The label(s) kind/duplicate cannot be applied, because the repository doesn't have them.

In response to this:

Hi @Gekalash, we have confirmed that the issues is not in the configMapGenerator field.

We tried to run your example with only the configMapGenerator in the overlay, and that merged correctly. Next, as @valaparthvi confirmed, with both the components and configMapGenerator calls in the overlay, the components merge values won in the end because components are now executed after generators and transformers.

This was documented in this Kustomize release. As stated there, #4402 should solve your use case because you'll be able to specify the order that Kustomize fields run in. However, if its implementation is not fast enough for your use case, we invite you to leave feedback on #5141. If there is enough demand there, we'd be interested in coming up with a temporary solution.

Regarding your proposal

A workaround could be – implement the overrides from the conifgMapGenerator as a component, and import it that way

could you provide us with more information? If you want the override values from the overlay configMapGenerator, we're wondering why you can't just leave out the Component. Is it because the Component contains other relevant changes? Some more context could be helpful.

/kind duplicate
/triage needs-information

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Aug 30, 2023
@annasong20
Copy link
Contributor

/kind support
/triage duplicate

@k8s-ci-robot k8s-ci-robot added kind/support Categorizes issue or PR as a support question. triage/duplicate Indicates an issue is a duplicate of other open issue. labels Aug 30, 2023
@natasha41575
Copy link
Contributor

Let us know if you have any more information about your use case. Closing this as we are tracking the component/generator ordering in other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. kind/support Categorizes issue or PR as a support question. triage/duplicate Indicates an issue is a duplicate of other open issue. triage/needs-information Indicates an issue needs more information in order to work on it.
Projects
None yet
Development

No branches or pull requests

5 participants