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

components are applied after generators, before transformers #5170

Conversation

koba1t
Copy link
Member

@koba1t koba1t commented May 10, 2023

fix: #5141

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 10, 2023
@natasha41575 natasha41575 requested review from natasha41575 and annasong20 and removed request for annasong20 and yuwenma May 26, 2023 17:33
@natasha41575
Copy link
Contributor

/approve

@annasong20, when you give this PR a review could you also build off the branch to be a second verifier that it fixes #5141?

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: koba1t, natasha41575

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 26, 2023
Copy link
Contributor

@annasong20 annasong20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only readability comments. Great spacing and go.work.sum fixes.

@@ -238,6 +234,11 @@ func (kt *KustTarget) accumulateTarget(ra *accumulator.ResAccumulator) (
return nil, errors.WrapPrefixf(
err, "merging vars %v", kt.kustomization.Vars)
}
// components are accumulated last.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this comment, can we explain why "components are accumulated last"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add a comment at
983165a.
Do you think this comment is enough to explain it?

input []FileGen
expectedOutput string
}{
"a": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename the test to something more descriptive? For example, "after generators".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh!
Sorry, I forgot to fix the test name.

Copy link
Member Author

@koba1t koba1t May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it at 0c38baa.

@annasong20
Copy link
Contributor

@annasong20, when you give this PR a review could you also build off the branch to be a second verifier that it fixes #5141?

Fixes the issue!

@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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.

@koba1t
Copy link
Member Author

koba1t commented May 31, 2023

Hi @annasong20

I have done a fix.
Could you recheck it?

@natasha41575
Copy link
Contributor

/hold

For discussion

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 31, 2023
@natasha41575 natasha41575 removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 31, 2023
@@ -238,6 +234,12 @@ func (kt *KustTarget) accumulateTarget(ra *accumulator.ResAccumulator) (
return nil, errors.WrapPrefixf(
err, "merging vars %v", kt.kustomization.Vars)
}
// components are accumulated last.
// components are expected to execute after reading resources, adding generators, and applying transformers.
ra, err = kt.accumulateComponents(ra, kt.kustomization.Components)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in meeting, we decided to move this to after generators, but before transformers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koba1t I'll review the PR again after this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@annasong20
I moved the code and added a test case. 1d0a14d
Could you recheck it?

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 31, 2023
@annasong20
Copy link
Contributor

/tide merge-method-squash
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 2, 2023
@annasong20
Copy link
Contributor

/label tide/merge-method-squash
/unhold

@k8s-ci-robot k8s-ci-robot added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jun 2, 2023
@k8s-ci-robot k8s-ci-robot merged commit 0add0f9 into kubernetes-sigs:master Jun 2, 2023
8 checks passed
@koba1t koba1t deleted the change/components_apply_after_all_generator_and_transformer_applied branch June 2, 2023 21:57
@ephesused
Copy link
Contributor

FYI, we are seeing some kustomize build failures associated with this commit. I'm working to isolate the source and create a simple test case.

@ephesused
Copy link
Contributor

I believe the failures we're seeing are expected given this PR's description, but if someone is willing to confirm, I'd appreciate it. My understanding is that our current pattern (generate a configmap in the component and merge it in the top-level kustomization.yaml) will need to be inverted (generate a configmap in the top-level kustomization.yaml and merge it in the component). Is that accurate?

kustomization.yaml:

components:
- component-example
configMapGenerator:
- files:
  - datafile.txt
  name: cm-for-datafile
  behavior: merge

component-example/kustomization.yaml:

kind: Component

generators:
- generators.yaml

component-example/generators.yaml:

apiVersion: builtin
kind: ConfigMapGenerator
metadata:
  name: cm-for-datafile
labels:
  app.kubernetes.io/name: cm-for-datafile

datafile.txt is empty.

Results from kustomize builds before and after this commit:

[root@e7265ac0feda pr5170]# ../../kustomize-execs/branch-6ce0bf39/kustomize build .
apiVersion: v1
data:
  datafile.txt: ""
kind: ConfigMap
metadata:
  name: cm-for-datafile-hbfc9tkcd5
[root@e7265ac0feda pr5170]# ../../kustomize-execs/branch-0add0f95/kustomize build .
Error: merging from generator &{0xc0004381a0 <nil>}: id resid.ResId{Gvk:resid.Gvk{Group:"", Version:"v1", Kind:"ConfigMap", isClusterScoped:false}, Name:"cm-for-datafile", Namespace:""} does not exist; cannot merge or replace
[root@e7265ac0feda pr5170]#

@annasong20
Copy link
Contributor

My understanding is that our current pattern (generate a configmap in the component and merge it in the top-level kustomization.yaml) will need to be inverted (generate a configmap in the top-level kustomization.yaml and merge it in the component). Is that accurate?

@ephesused Yes, I believe that should solve the problem. Thank you for the detailing your setup and feel free to leave any feedback for this change at #5141.

renovate bot added a commit to scottames/dots that referenced this pull request 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>
@seh
Copy link
Contributor

seh commented Jun 20, 2023

@koba1t, the title of this PR is confusing: It doesn't match the comments in the code, and doesn't match the decisions reached in #5141. As far as I can tell, we're applying components before transformers. Is that correct?

@koba1t
Copy link
Member Author

koba1t commented Jun 20, 2023

/retitle components are applied after generators, before transformers

@k8s-ci-robot k8s-ci-robot changed the title change: components apply after all generators and transformers applied components are applied after generators, before transformers Jun 20, 2023
@koba1t
Copy link
Member Author

koba1t commented Jun 20, 2023

@seh

That's right. Thanks!

FrenchBen pushed a commit to FrenchBen/kustomize that referenced this pull request Jul 20, 2023
kubernetes-sigs#5170)

* change: components apply after all generator and transformer applied

* fix name for a test case

* add comment about when the components will be executed

* components are applied before transformer
vishnoianil added a commit to vishnoianil/nexodus that referenced this pull request Sep 16, 2023
…release

Kustomize release 5.1.0 (our CI job uses this version) made
the changes in the order of processing of resources, components
, generators and transformers. That requires that our top
level kustomization yamls should create the configmaps,
rather than replace it, because with 5.1.0, components will
be processed after generators, so there won't be any existing
configmap to replace.

Following issue has more details about it:
kubernetes-sigs/kustomize#5170

Signed-off-by: Anil Kumar Vishnoi <avishnoi@redhat.com>
vishnoianil added a commit to vishnoianil/nexodus that referenced this pull request Sep 28, 2023
Kustomize release 5.1.0 (our CI job uses this version) made the changes
in the order of processing of resources, components , generators and
transformers. That requires that our top level kustomization yamls
should create the configmaps, rather than replace it,
because with 5.1.0, components will be processed after generators,
 so there won't be any existing configmap to replace.

Following issue has more details about it: kubernetes-sigs/kustomize#5170

Signed-off-by: Anil Kumar Vishnoi <avishnoi@redhat.com>
vishnoianil added a commit to vishnoianil/nexodus that referenced this pull request Sep 28, 2023
Kustomize release 5.1.0 (our CI job uses this version) made the changes
in the order of processing of resources, components , generators and
transformers. That requires that our top level kustomization yamls
should create the configmaps, rather than replace it,
because with 5.1.0, components will be processed after generators,
so there won't be any existing configmap to replace.

Following issue has more details about it: kubernetes-sigs/kustomize#5170

Signed-off-by: Anil Kumar Vishnoi <avishnoi@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kustomizations introduced by components are not applied to adjacent generated resources
6 participants