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

Maintain resources in a list. #1154

Merged

Conversation

monopole
Copy link
Contributor

@monopole monopole commented Jun 6, 2019

Since kustomize started, resource order in the
output has been determined by a final sort, and
hasn't been influenced by the order implied by
resource file names, resource object names, or the
order declared in the resources and bases
fields of a kustomization file.

Beyond the final sort, order wasn't given much
thought, since a cluster is notionally an
unordered set of resource objects, and the apply
operation sends objects into the cluster to face an
unknowable set of race conditions involving custom
resource setup that controllers simply have to
deal with.

In practice, however, order matters - e.g.
Namespace "objects" must be applied first,
before objects can be applied "in" that namespace.

There have been proposals to allow different sorts
to replace the one built into kustomize, but the
new plugin system is supposed to be general enough
to allow a sorting transformer plugin, so users
can sort however they like via a plugin. However,
for that to be possible, resource order has to be
stable from transformation step to transformation step.
Moreover, the transformers themselves, which are
expressed as k8s resources, have to be maintained
in a specific order, as they are non-commutative.

This need for order makes the internal data
structure of kustomize, a map, much less
attractive from a code complexity point of view.

This PR replaces the core map with a list, a step
towards preserving resource order as specified in
kustomization files (related: #756 #821), as a
no-sort way to control ordering, and as a
necessary condition to allow transformer plugins.

Removing the heretofore far too mutable map is
also a necessary step to removing a map key hack
(a mutable ID key that holds prefix/suffix mods)
that, along with general map usage, has been
involved in many closed bugs but is still causing
pain (#316 #710 #800 #972 #1028 #1082 #1142).

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 6, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: monopole

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 Jun 6, 2019
@k8s-ci-robot k8s-ci-robot requested review from droot and mengqiy June 6, 2019 18:09
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 6, 2019
@monopole monopole requested review from Liujingfang1, damienr74 and barney-s and removed request for droot and mengqiy June 6, 2019 18:17
@@ -33,66 +33,70 @@ import (
"sigs.k8s.io/kustomize/pkg/types"
)

func makeResAccumulator() (*ResAccumulator, *resource.Factory, error) {
func makeResAccumulator(t *testing.T) (*ResAccumulator, *resource.Factory, error) {
ra := MakeEmptyAccumulator()
err := ra.MergeConfig(config.MakeDefaultConfig())
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to modify this to t.Fatalf(...) since the other error is handled that way an this code is duplicated in every test that uses makeResAccumulator? You could completely remove the error return and just call Fatalf on error.

Not really that important, just code cleanup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, done.

@monopole monopole force-pushed the maintainResourcesInLoadOrder branch from ca99a95 to 4162dbc Compare June 6, 2019 22:58
@damienr74
Copy link
Contributor

/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 6, 2019
@k8s-ci-robot k8s-ci-robot merged commit c094780 into kubernetes-sigs:master Jun 6, 2019
@monopole monopole deleted the maintainResourcesInLoadOrder branch June 9, 2019 15:45
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants