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

Make ordering configurable #4019

Merged

Conversation

yanniszark
Copy link
Contributor

@yanniszark yanniszark commented Jun 30, 2021

Resolves #3913

Make kustomize's ordering of resources customizable from the kustomization.yaml file.

My changes in a nutshell:

  1. Add the fields to the kustomization struct
  2. Extend the LegacyResourceOrderingPlugin to be configurable in its ordering.
  3. Wire it up with the new fields.

We may also want to delete the now unused IdSlice code, but I've leaven it up to the reviewer to guide me on this.

cc @KnVerey @monopole

ALLOW_MODULE_SPAN

@k8s-ci-robot
Copy link
Contributor

@yanniszark: 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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 30, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @yanniszark. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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 added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 30, 2021
@yanniszark yanniszark force-pushed the feature-configurable-ordering branch from e2feb0f to 324895e Compare June 30, 2021 17:05
@natasha41575 natasha41575 added the tide/merge-method-merge Denotes a PR that should use a standard merge by tide when it merges. label Jun 30, 2021
@natasha41575
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 30, 2021
@natasha41575
Copy link
Contributor

As a note, you can run the command make prow-presubmit-check to run all the tests here locally.

@natasha41575 natasha41575 added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. and removed tide/merge-method-merge Denotes a PR that should use a standard merge by tide when it merges. labels Jun 30, 2021
@yanniszark
Copy link
Contributor Author

/retest

1 similar comment
@natasha41575
Copy link
Contributor

/retest

@natasha41575
Copy link
Contributor

I might have to unpin some modules for the presubmit to pass. I'll try to make some time to do that tomorrow!

@yanniszark yanniszark force-pushed the feature-configurable-ordering branch 3 times, most recently from 23d16df to 431b40e Compare July 6, 2021 13:53
@yanniszark
Copy link
Contributor Author

@natasha41575 I'm a bit perplexed by what happened.
The presubmit in the PR fails with:

go: sigs.k8s.io/kustomize/plugin/builtin/legacyordertransformer: package sigs.k8s.io/kustomize/kyaml/resid imported from implicitly required module; to add missing requirements, run:
	go get sigs.k8s.io/kustomize/kyaml/resid@v0.11.0
make: *** [Makefile:183: api/builtins/LegacyOrderTransformer.go] Error 1

I pinned it down to the unit tests of the legacy order transformer.
However, this made little sense to me, because that particular module (kyaml) is replaced with the local version.
Perhaps you have more insight on this?

@yanniszark
Copy link
Contributor Author

yanniszark commented Jul 6, 2021

BTW, I added a test and fixed the behavior of the plugin to follow these rules:

  • If there is no legacySortOptions field set, use the existing legacy sort options.
  • If there is a legacySortOptions field present, use its options. orderFirst and orderLast are empty by default.

Test failed because I needed to split changes spanning different modules into separate commits.
Hopefully tests will pass now.

@natasha41575
Copy link
Contributor

natasha41575 commented Jul 7, 2021

I pinned it down to the unit tests of the legacy order transformer.
However, this made little sense to me, because that particular module (kyaml) is replaced with the local version.
Perhaps you have more insight on this?

We ran into this problem too but didn't know why :) but as long as it works now that's fine. I'm running the workflows now, I'll take a closer look at this PR this week.

@natasha41575
Copy link
Contributor

Could you add an e2e test in api/krusty (feel free to create a new file for it, and use the other files in that folder as examples) to demonstrate how one would use this in a kustomization file?

Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

EDIT: I need to read through the issue more carefully actually, you can disregard this comment.

I don't know if having two separate top-level fields is necessary, so I commented on the issue.

@yanniszark yanniszark force-pushed the feature-configurable-ordering branch from 431b40e to 370634b Compare July 27, 2021 21:29
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 27, 2021
@yanniszark yanniszark force-pushed the feature-configurable-ordering branch from 370634b to bb9e19d Compare July 27, 2021 22:33
yanniszark and others added 4 commits December 2, 2022 16:10
Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>
Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
@yanniszark yanniszark force-pushed the feature-configurable-ordering branch from 8f14277 to e581778 Compare December 2, 2022 21:11
@yanniszark
Copy link
Contributor Author

@KnVerey done! Let's see if it passes now :)

@KnVerey
Copy link
Contributor

KnVerey commented Dec 2, 2022

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KnVerey, yanniszark

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 Dec 2, 2022
@k8s-ci-robot k8s-ci-robot merged commit a502717 into kubernetes-sigs:master Dec 2, 2022
@yanniszark
Copy link
Contributor Author

@natasha41575 @KnVerey many thanks for all the help in getting this change in :)

@KnVerey
Copy link
Contributor

KnVerey commented Dec 2, 2022

Thank YOU for all your hard work on this feature!

@natasha41575
Copy link
Contributor

I am so happy to see this in! Amazing work and thank you, both of you for seeing this through!

elisshafer pushed a commit to elisshafer/kustomize that referenced this pull request Dec 8, 2022
* api: Add new types for customizeable resource ordering

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>

* plugins: Implement SortOrderTransformer plugin

Implement the SortOrderTransformer plugin. This plugin allows the user
to customize the order that kustomize will output resources in.

The API for the plugin is the following:

sortOptions:
  order: legacy | fifo
  legacySortOptions:
    orderFirst:
    - {GVK}
    orderLast:
    - {GVK}

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>

* plugins: Add boilerplate and generate code for new SortOrderTransformer

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>

* build: Add option to denote if the reorder flag was set by the user

We want to take different actions if the reorder flag was set by the
user or filled by the default value. Thus, we propagate this information
from build to the krusty options.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

* api/krusty: Ensure sort ordering works with CLI flag and kustomization

Sort order can be defined in two places:
- (new) kustomization file
- (old) CLI flag
We want the kustomization file to take precedence over the CLI flag.

Eventually, we may want to move away from having a CLI flag altogether:
kubernetes-sigs#3947

Case 1: Sort order set in kustomization file AND in CLI flag.
Print a warning and let the kustomization file take precedence.

Case 2: Sort order set in CLI flag only or not at all.
Follow the CLI flag (defaults to legacy) and reorder at the end.

Case 3: Sort order set in kustomization file only.
Simply build the kustomization.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

* krusty: Add e2e test for SortOrderTransformer

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>

* plugins: Purge LegacyOrderTransformer

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

* Update go.work.sum

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

* review: Make review changes

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>
Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
@natasha41575
Copy link
Contributor

@yanniszark Do you have time to write up some docs before this feature is released next Friday 12/16? The docs live here: https://github.com/kubernetes-sigs/cli-experimental/tree/master/site/content/en/references/kustomize/kustomization

If you are unable to, just let us know and we can try to write something up ourselves.

@yanniszark
Copy link
Contributor Author

@natasha41575 yes I will make sure to do so! I will try to parse the current structure and infer the necessary docs to write, but please feel free to tell me what you would expect as a good set of documentation for this feature.

yanniszark added a commit to yanniszark/cli-experimental that referenced this pull request Dec 9, 2022
Kustomize has a new field called "sortOptions" to sort resources:
kubernetes-sigs/kustomize#3913
kubernetes-sigs/kustomize#4019

Document what it does and how to use it.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
yanniszark added a commit to yanniszark/cli-experimental that referenced this pull request Dec 9, 2022
Kustomize has a new field called "sortOptions" to sort resources:
kubernetes-sigs/kustomize#3913
kubernetes-sigs/kustomize#4019

Document what it does and how to use it.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
yanniszark added a commit to yanniszark/cli-experimental that referenced this pull request Jan 11, 2023
Kustomize has a new field called "sortOptions" to sort resources:
kubernetes-sigs/kustomize#3913
kubernetes-sigs/kustomize#4019

Document what it does and how to use it.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
yanniszark added a commit to yanniszark/cli-experimental that referenced this pull request Jan 11, 2023
Kustomize has a new field called "sortOptions" to sort resources:
kubernetes-sigs/kustomize#3913
kubernetes-sigs/kustomize#4019

Document what it does and how to use it.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
yanniszark added a commit to yanniszark/cli-experimental that referenced this pull request Jan 11, 2023
Kustomize has a new field called "sortOptions" to sort resources:
kubernetes-sigs/kustomize#3913
kubernetes-sigs/kustomize#4019

Document what it does and how to use it.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
cailyn-codes pushed a commit to cailyn-codes/kustomize that referenced this pull request Jan 12, 2023
* api: Add new types for customizeable resource ordering

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>

* plugins: Implement SortOrderTransformer plugin

Implement the SortOrderTransformer plugin. This plugin allows the user
to customize the order that kustomize will output resources in.

The API for the plugin is the following:

sortOptions:
  order: legacy | fifo
  legacySortOptions:
    orderFirst:
    - {GVK}
    orderLast:
    - {GVK}

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>

* plugins: Add boilerplate and generate code for new SortOrderTransformer

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>

* build: Add option to denote if the reorder flag was set by the user

We want to take different actions if the reorder flag was set by the
user or filled by the default value. Thus, we propagate this information
from build to the krusty options.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

* api/krusty: Ensure sort ordering works with CLI flag and kustomization

Sort order can be defined in two places:
- (new) kustomization file
- (old) CLI flag
We want the kustomization file to take precedence over the CLI flag.

Eventually, we may want to move away from having a CLI flag altogether:
kubernetes-sigs#3947

Case 1: Sort order set in kustomization file AND in CLI flag.
Print a warning and let the kustomization file take precedence.

Case 2: Sort order set in CLI flag only or not at all.
Follow the CLI flag (defaults to legacy) and reorder at the end.

Case 3: Sort order set in kustomization file only.
Simply build the kustomization.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

* krusty: Add e2e test for SortOrderTransformer

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>

* plugins: Purge LegacyOrderTransformer

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

* Update go.work.sum

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

* review: Make review changes

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>

Signed-off-by: Yannis Zarkadas <yanniszark@arrikto.com>
Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
@dstraub
Copy link

dstraub commented Mar 9, 2023

In generell, we like this approach.
But how could we use 'fifo' with resources and generators ?
The resources are orderd, but configmaps/secrets created by generators appears at the end.

We have only one exception the the 'legacy' order: Node isn't in the legacy list and comes at least.
But we have to adjust node labels before everything else.

@lindhe
Copy link

lindhe commented Jul 17, 2023

It says in the documentation:

This field is the endorsed way to sort resources. It should be used instead of the --reorder CLI flag, which is deprecated.

It is a bit unclear to me if that just means that it is the endorsed way to set the ordering options (instead of the --reorder flag), or if it is the endorsed way of sorting (i.e. one should set sortOptions.order=fifo to use the new recommended way of working).

Can someone please clarify this to me?

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ 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.

Make legacy resource ordering customizable in the kustomization.yaml file
9 participants