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

Kustomizations introduced by components are not applied to adjacent generated resources #5141

Closed
djmcgreal-cc opened this issue Apr 20, 2023 · 6 comments · Fixed by #5170
Closed
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@djmcgreal-cc
Copy link

djmcgreal-cc commented Apr 20, 2023

What happened?

See reproduction where generated resource is not modified by an adjacent component whereas the non-generated adjacent resource is.

What did you expect to happen?

That the generated resource would behave the same as the non-generated resources.

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

kustomization.yaml:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - resource.yaml

components:
  - component

configMapGenerator:
  - name: generated-resource
    literals:
      - key=value
    options:
      disableNameSuffixHash: true

resource.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: adjacent-resource
data:
  blah: hello

component/kustomization.yaml:

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
nameSuffix: -modified

Expected output

apiVersion: v1
data:
  blah: hello
kind: ConfigMap
metadata:
  name: adjacent-resource-modified
---
apiVersion: v1
data:
  key: value
kind: ConfigMap
metadata:
  name: generated-resource-modified

Actual output

apiVersion: v1
data:
  blah: hello
kind: ConfigMap
metadata:
  name: adjacent-resource-modified
---
apiVersion: v1
data:
  key: value
kind: ConfigMap
metadata:
  name: generated-resource

Kustomize version

v5.0.1, also {Version:kustomize/v4.5.5 GitCommit:daa3e5e2c2d3a4b8c94021a7384bfb06734bcd26 BuildDate:2022-05-20T20:21:22Z GoOs:darwin GoArch:amd64}

Operating system

MacOS

@djmcgreal-cc djmcgreal-cc added the kind/bug Categorizes issue or PR as related to a bug. label Apr 20, 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 Apr 20, 2023
@natasha41575
Copy link
Contributor

/triage accepted

I think that components should be applied to both resources declared under resources and those that are generated.

/assign @koba1t

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 10, 2023
@djmcgreal-cc
Copy link
Author

We also discovered that generators apply their name translations to helm manifests whereas when specified inline as [configMap|secret]Generators, manifests referencing the generated resources that are loaded through helm are not modified. Though we then found that we cannot resolve the circumstance described in the initial post by using generators, I wonder if it speaks to a wider issue with loading ordering?

@djmcgreal-cc
Copy link
Author

Oh, there's already a PR so maybe not :)

@annasong20
Copy link
Contributor

I found the question that this issue spawns of "Why are components run after resources but before all generators and transformers?" very interesting. I ended up reading the components KEP and figured I'd share and collect my thoughts here.

Kustomize intentionally processes components immediately after resources. I assume that this is because the authors proposed components to specify different operations on the same set of resources, and so it was natural to process components after the target resources. The authors probably also wanted to replicate the kustomization experience for components by allowing users to add additional generators and apply transformers to the components.

As pointed out by this issue, there are difficulties with the current processing order. I imagine potential complaints with processing components after generators and transformers, as in #5170, might be

  • if the output of generators is needed by all components, it should be in resources
  • if the output of generators is needed by particular components, it should be specified in those components
  • users need to move generators that they don't want transformed by components to an overlay, thus splitting their application across multiple kustomize layers
  • users need to move transformers they want to apply on top of components to an overlay, thus splitting their application across multiple layers

I don't know which processing order will make the most sense, but I guess we can experiment moving around components, given that the feature is still in alpha.

@ephesused
Copy link
Contributor

ephesused commented Jun 6, 2023

Fundamentally, I think the question on sequence relates to one's vision on what constitutes the base configuration. My inference is that the original designers did not see generated and transformed resources as part of the base, so that's why components were processed prior to generators and transformers. If generated and transformed resources are considered part of the base, then moving components after generators and transformers makes sense.

I think that any sequence choice is going to have confusing aspects. The key is to ensure the choice is documented and explained, so that users can understand what to expect.

This change is a breaking one for our kustomizations. For example, we have configmaps defined in a component that are merged in a generator in the top-level kustomization.yaml. We will have to invert that pattern (or adjust in some other way) in order to move to a newer version of kustomize.

@natasha41575
Copy link
Contributor

natasha41575 commented Jun 19, 2023

Thank you @ephesused for sharing your perspective, it is very helpful to hear how users are using components. I agree that the sequence will be confusing in any case, and that we need to document it better.

I see generators as part of the base. With #4402 in particular, we will be required to see resources and generators as the same, as resources itself will become a generator, which is needed for the upcoming Composition API. That issue will also make components a generator, so it is not so much about the order of resources, components, and generators per se (as they will all be generators), but we will still need to decide on a reasonable default ordering. We discussed this and feel that it makes sense to see resources from resources the same as resources from other generators, so have elected to move components to running after generators for now - so the order will be resources, then all other generators, then components. Transformers will be applied last, on top of all of these generated resources. We made this change very cautiously and with a lot of discussion and thought, as we want to avoid causing friction for users migrating. But given that Components is in alpha, I think now is the time to make such breaking changes if we are ever going to do it.

That said, we do have someone working on #4402, which will make the ordering of resources, components, and other generators customizable. My hope is that we can have that available soon, to unblock anyone who needs this feature to update.

renovate bot added a commit to scottames/dots that referenced this issue Jun 19, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
|
[kubernetes-sigs/kustomize](https://togithub.com/kubernetes-sigs/kustomize)
| minor | `v5.0.3` -> `v5.1.0` |
| [zellij-org/zellij](https://togithub.com/zellij-org/zellij) | patch |
`v0.37.0` -> `v0.37.1` |

---

### Release Notes

<details>
<summary>kubernetes-sigs/kustomize</summary>

###
[`v5.1.0`](https://togithub.com/kubernetes-sigs/kustomize/releases/tag/kustomize/v5.1.0)

[Compare
Source](https://togithub.com/kubernetes-sigs/kustomize/compare/kustomize/v5.0.3...kustomize/v5.1.0)

##### Highlights

Components are now applied after generators:
[kubernetes-sigs/kustomize#5170

We made this change cautiously as we want to avoid user friction when
updating kustomize; however we felt that it is a bug that resources from
`resources` and resources from generators are treated differently. Given
that components is currently an alpha feature, we felt that now was the
time to adjust if ever.

We are currently working on on
[kubernetes-sigs/kustomize#4402,
which will make the ordering of `resources`, `components`, and
`generators` customizable in the kustomization file. Please use that
issue for tracking if you are blocked from upgrading kustomize for this
reason, and we hope to have it available soon.

See
[kubernetes-sigs/kustomize#5141
for more detailed discussion.

##### Bug fixes:


[#&#8203;5030](https://togithub.com/kubernetes-sigs/kustomize/issues/5030):
`kustomize edit` will return an error if there is no matching path

[#&#8203;5170](https://togithub.com/kubernetes-sigs/kustomize/issues/5170):
components are now applied after generators

##### Dependency updates


[#&#8203;5186](https://togithub.com/kubernetes-sigs/kustomize/issues/5186):
Update gnostic dependency with gnostic-models

[#&#8203;5187](https://togithub.com/kubernetes-sigs/kustomize/issues/5187):
Bump to go 1.20

[#&#8203;5212](https://togithub.com/kubernetes-sigs/kustomize/issues/5212):
pin to kyaml v0.14.3

[#&#8203;5213](https://togithub.com/kubernetes-sigs/kustomize/issues/5213):
pin to cmd/config v0.11.3

[#&#8203;5214](https://togithub.com/kubernetes-sigs/kustomize/issues/5214):
pin to api 0.14.0

</details>

<details>
<summary>zellij-org/zellij</summary>

###
[`v0.37.1`](https://togithub.com/zellij-org/zellij/releases/tag/v0.37.1)

[Compare
Source](https://togithub.com/zellij-org/zellij/compare/v0.37.0...v0.37.1)

##### RELEASE IN PROGRESS

Thank you for your patience!

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/scottames/dots).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMzEuMCIsInVwZGF0ZWRJblZlciI6IjM1LjEzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants