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

Kustomize API Proposal: Add an example with components #2438

Merged
merged 7 commits into from
May 18, 2020

Conversation

apyrgio
Copy link
Contributor

@apyrgio apyrgio commented May 5, 2020

Add a WIP example that showcases how components can be used. This example is purposefully similar to the multibases example, to showcase what's the current shortcoming of overlays, namely that we currently can't combine overlays that point to the same common base. Also, this example uses the KustomizationPatch notation to define a component, as seen in #2168.

For convenience, you can see the rendered example here.

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

Hi @apyrgio. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 5, 2020
@k8s-ci-robot k8s-ci-robot requested review from mengqiy and monopole May 5, 2020 13:13
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 5, 2020
@apyrgio apyrgio changed the title Add an example with components WIP: Add an example with components May 5, 2020
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 5, 2020
@apyrgio
Copy link
Contributor Author

apyrgio commented May 5, 2020

For those who are not aware of the on-going discussion on this subject, let me add a preface:

This PR has been sent as a follow-up to a live discussion regarding composition support in Kustomize (#1251). See here for more details. Its purpose is to showcase how components would work, based on @pgpx's #2168 PR.

Feel free to comment on anything that seems off with this design, or if there's a use-case that you feel is not covered.

For instance, what I feel is not covered is the handling of relative paths. In this example, it's the secrets for LDAP/reCAPTCHA/etc. Since components are reusable, and probably provided by the upstream, they should be treated as read-only. So, we shouldn't store files in them so that the generators can pick them up. Instead, it may be better to resolve the file paths relative to the top-level overlay.

This of course is of lesser importance to the actual issue, but I'm mentioning it here for completeness.

@apyrgio
Copy link
Contributor Author

apyrgio commented May 5, 2020

Also, in case it's not clear. For those wandering if the example would work if we simply switched:

kind: KustomizationPatch

with:

kind: Kustomization

resources:
  - ../../base

the answer is:

$ kustomize build overlays/dev
Error: accumulating resources: recursed merging from path '../../components/recaptcha': may not add resource with an already registered id: apps_v1_Deployment|~X|example

The reason is that Kustomize processes overlays in parallel, so if two overlays point to the same base, it will create two copies of it but will not be able to merge them.

@apyrgio apyrgio force-pushed the feature-components-docs branch from 96034d1 to b5c3b87 Compare May 6, 2020 07:33
Add a WIP example that showcases how components can be used.
@apyrgio apyrgio force-pushed the feature-components-docs branch from b5c3b87 to 6063a6b Compare May 6, 2020 07:44
@monopole
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 May 12, 2020
Describe in more detail the solution with stock kustomize variants to
better showcase the benefits of kustomize components.

Plus, revamp certain parts of the example with minor fixes.
@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 May 13, 2020
Rename all `KustomizationPatch` instances to
`v1alpha1/KustomizationPatch`, to reflect that it's an alpha feature.
@ioandr
Copy link
Contributor

ioandr commented May 13, 2020

Hey there,

this is an update with regard to the action item from the previous community meeting: as agreed, with @apyrgio we have worked on a second iteration of the example document that describes Κustomize components.

We now provide 2 solutions to the same problem, one without and one with Kustomize components. We hope that they adequately highlight the value of the composition feature.

cc @pwittrock @monopole

@pwittrock
Copy link
Contributor

@ioandr Thanks!

mkdir -p $RECAPTCHA

cat <<EOF >$RECAPTCHA/kustomization.yaml
kind: v1alpha1/KustomizationPatch
Copy link
Contributor

Choose a reason for hiding this comment

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

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.


cat <<EOF >$COMMUNITY/kustomization.yaml
kind: Kustomization
resources:
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably makes sense to have components separate from resources.

components:
- ../../components/external_db
- ../../components/recaptcha

Copy link
Contributor

Choose a reason for hiding this comment

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

Our approach was to stay as close as possible to the existing interface of kustomization files.

Since the bases keyword was also absorbed by resources quite recently we believe it is more straight forward to have the resources keyword cover all cases, including components.
Aside, such a change might have implications in the size and complexity of #2168.

In any case, we are definitely open to iterate on this and reach a common understanding.

Copy link
Contributor

Choose a reason for hiding this comment

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

A Component (aka KustomizationPatch) effectively become the parent resource of the resources that come before it in the resources list. They could be moved to a separate components list, which I think could then be evaluated as if it was appended to the end of the resources list. I guess this would make things a little clearer (and maybe opportunities for checking that only the correct types are in each list), and probably wouldn't make the code that much more complicated. The disadvantage is that you wouldn't be able to add any resources to be evaluated after the components, but I can't think of any examples that would actually need that (and the examples don't), so maybe that isn't a real concern?

Copy link
Contributor

Choose a reason for hiding this comment

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

I implemented support for a components list on a separate branch in my fork - doesn't seem to bad, with most of the added complexity needed to limit each kind to their own list. The code definitely could do with a slightly more extensive refactor if components is preferred, but I didn't do that now just to minimise the extent of the changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is reasonable for now. It has an alpha apiVersion so we aren't commitment to keeping the API in this form.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should I merge that in to the main PR branch? I still need to make the change so make it use alpha instead of beta.

Copy link
Contributor

Choose a reason for hiding this comment

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

I rebased the components branch and added v1alpha1 support.

LDAP=$DEMO_HOME/components/ldap
mkdir -p $LDAP

cat <<EOF >$LDAP/kustomization.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

mkdir -p $EXT_DB

cat <<EOF >$EXT_DB/kustomization.yaml
kind: v1alpha1/KustomizationPatch # <-- Component notation
Copy link
Contributor

Choose a reason for hiding this comment

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

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

mkdir $BASE

cat <<EOF >$BASE/kustomization.yaml
resources:
Copy link
Contributor

Choose a reason for hiding this comment

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

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Customization

Copy link
Contributor

@ioandr ioandr May 14, 2020

Choose a reason for hiding this comment

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

Done, s/Customization/Kustomization

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, silly auto correct.

EOF
```

Define a `community` overlay, that bundles the external DB and reCAPTCHA
Copy link
Contributor

Choose a reason for hiding this comment

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

overlay -> variant

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

files:
- ldappass.txt

patchesStrategicMerge:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use a configMapGenerator in one of the components to show that it would work as well? Something like the following (or use a files: generator):

Suggested change
patchesStrategicMerge:
configMapGenerator:
- name: conf
behavior: merge
literals:
- ldap.conf=|
endpoint=ldap://ldap.example.com
bindDN=cn=admin,dc=example,dc=com
pass=/var/run/secrets/ldap/ldappass.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, let's spice this up.

@pwittrock
Copy link
Contributor

Would you clarify in the doc if the ordering matters? I assume it doesn't, but would be good to clarify that resources behaves like a set.

@pwittrock
Copy link
Contributor

pwittrock commented May 14, 2020

Let's move forward with this as there have been no objections.

WDYT of the following proposal:

  • Create a KEP for this under kubernetes/enhancements. This gives visibility to folks who follow that repo
    • You don't need to fill out all the KEP sections. Delete those that don't seem relevant.
    • Copy and paste contents from this document into the KEP
    • Link the KEP in this PR description
    • Message sig-cli in Slack, mentioning @pwittrock and @soltysh
    • Post KEP to sig-cli mailing list
    • Add to next weeks sig-cli agenda
  • Update the implementation PR (don't block on the KEP, since this has already had extensive discussion)
    • Link the implementation PR (code) in the description of this PR (docs)
    • Add any tests that are missing
      • Test that ordering doesn't matter of resources, patches, components
      • Test for conflicting components -- e.g. specify different values for the same annotation, patch the same resource with different values
      • Test ordering with namePrefix / suffix
      • Test components specifying the same ConfigMap / Secret generator -- are they merged, overridden, error?
    • Update with changes from this PR
  • Show up to sig-cli meetings until the feature is completed and part of a release

After the above are complete, let's merge this PR so the new capabilities are documented.

Consider promoting your new feature on twitter.

@pwittrock
Copy link
Contributor

/lgtm

@pwittrock
Copy link
Contributor

/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apyrgio, pwittrock

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 14, 2020
@pgpx
Copy link
Contributor

pgpx commented May 14, 2020

@pwittrock The ordering of Components does matter, because they are applied to the resources and components that came before them in the list (resources or components). Other resources (Kustomizations and files) are independent of each other. I guess that might be another argument to use components because then we can say that the order is significant for that list, but resources can then behave as a set (otherwise if we just have resources then order will matter).

@pwittrock
Copy link
Contributor

Hm, my guess is that we want components to apply to all resources in the list -- otherwise I'd expect subtle bugs. Its not clear from looking at the resource list what is a resources vs a path vs a component.

Otherwise we might want a more explicit expression of what is applied and where.

Perhaps components should have a protocol as part of the URI so it is more clear.

kind: Kustomization
resources:
- https+component://github.com/....
- file+component://something

@apyrgio
Copy link
Contributor Author

apyrgio commented May 15, 2020

@pwittrock Indeed, it makes sense to spin this feature request into a separate KEP. Thanks for breaking down the process to steps, they seem pretty solid. We’ll follow them and try to have something ready by this Wednesday.

apyrgio added 2 commits May 15, 2020 15:01
Incorporate the suggestion of the separate "components" field, that will
hold references to resources of `Component` kind. Also, add a missing
reference to the base, in the Kustomization files of the variants.
@monopole
Copy link
Contributor

/hold
Looks good, no big objections, but would like clarity on resources:

Currently, it's a list, not a set, and don't want to change that accidentally.

@apyrgio
Copy link
Contributor Author

apyrgio commented May 15, 2020

It seems that the semantics of the components field are as important as how the Component kind will work, so let's weigh in on this:

I think we agree that components are a special case of overlays, that can modify the same set of resources without "cloning" them. In this example, the resources are the Deployment and ConfigMap, and the components extend those, without caring much for their order. However, if two components alter the same field, then we need a way to resolve this conflict. It seems that the most intuitive way to resolve it is by "applying" the components sequentially, which is what @pgpx's PR does.

Now, as for how we can communicate this to the users. I think that the proposal for a separate components field works well in this case, because we can put the components there and document that order matters. I also think that users can adapt to this field easily, because there's already a field that behaves similarly; the patches field. Thus, the elevator pitch to existing users could be, to some extent, "what patches do to resources, components do to kustomizations". Hopefully that clarifies things a bit.

Slightly alter the reCAPTCHA component to use a `configMapGenerator`,
instead of patching the base `ConfigMap` as in the rest of the
components, to show that this is supported as well.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 15, 2020
@apyrgio
Copy link
Contributor Author

apyrgio commented May 15, 2020

I have updated the example to demonstrate how the components field would work, and to correct some omissions.

@monopole
Copy link
Contributor

/lgtm

looks like fun, thanks for working on this.
The examples are terrific.

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

@monopole monopole left a comment

Choose a reason for hiding this comment

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

/lgtm

make ux happy

@monopole monopole merged commit 765a488 into kubernetes-sigs:master May 18, 2020
@apyrgio
Copy link
Contributor Author

apyrgio commented May 19, 2020

Just a quick note here; I'm a bit worried that there will be people who will go through the examples of Kustomize, see this example and try to use it. However, the corresponding functionality has not yet been merged. Should we warn in the example that this is a work in progress?

apyrgio added a commit to arrikto/kubernetes-enhancements that referenced this pull request May 20, 2020
This enhancement proposal introduces components, a new kind of
Kustomization that allows users to define reusable kustomizations.

Main discussion: kubernetes-sigs/kustomize#1251
User story that spawned this KEP: kubernetes-sigs/kustomize#2438
apyrgio added a commit to arrikto/kubernetes-enhancements that referenced this pull request May 20, 2020
This enhancement proposal introduces components, a new kind of
Kustomization that allows users to define reusable kustomizations.

Main discussion: kubernetes-sigs/kustomize#1251
User story that spawned this KEP: kubernetes-sigs/kustomize#2438
@apyrgio
Copy link
Contributor Author

apyrgio commented May 20, 2020

Me, @ioandr and @pgpx have written the requested KEP. See kubernetes/enhancements#1803 for more details.

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants