-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Implement "kind: Component" to support composition #2168
Implement "kind: Component" to support composition #2168
Conversation
Welcome @pgpx! |
@droot - sorry, I requested a review from Liujingfang1 as the robot suggested, and it cancelled you for some reason! |
My two cents on this PR: Of all the solutions currently proposed on issue #1251, from a bird's eye view this solution seems to be the least intrusive and most flexible one, for people that want patch reuse or composition. You can check out some examples by @pgpx here:
Now, I suppose this PR begs the following questions: 1. Is this approach inline with the way kustomize reuses things? I'd say that it's inline, in the sense that kustomize has three reusable units; overlays, plugins, patches. This PR slightly enhances the first one, so it's compatible with commands like 2. Is there a better approach in the near-term future? Unless I'm missing a discussion, there doesn't seem to be something new in this front. 3. Do we have to support it forever? If this approach seems viable, but we're unsure if it's the best in the long run, why don't we guard it behind an alpha flag? There's already an environment variable for alpha commands, we can add one for features as well or unify them. So, if we're ok with the above, can we push this forward? If it's any indication, the issue from which the PR originated (#1251) has 30 people in favor of some sort of composition support, and there's a steady influx of new issues and Slack discussions that are related to this problem. |
@pgpx @apyrgio From what I can tell, I believe this wouldn't support multiple |
@chancez I think it is probably better to just create a new issue, because if you look at the code changes for this PR you'll see that they don't change that much - mostly concerned with modifying the resource accumulators. Your proposal would probably need changes in different areas, because they would change how Kustomization files are located (either nested within a parent or with a name other than kustomization.yaml). Also, your problem mainly seems to be the global nature of the |
It's been awhile since there was any significant activity on this PR, so I'm probing for news: @pwittrock: I see that this PR has been tagged as "Under consideration" about two weeks ago. Is there anything new on that front? Please share any reservations on this thread, so that we can get the discussion going forward. |
7a17233
to
40b650f
Compare
I rebased last weekend, though I don't think that CI has reported for some reason. |
Is it possible to add a Similar to this: https://github.com/danielsdeleo/deep_merge#selected-options-details # parent
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- a
- b
- c
- patch1
---
# patch1
apiVersion: kustomize.config.k8s.io/v1beta1
kind: KustomizationPatch
resources:
- --a
- --c
- d
- e results in: # parent
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- b
- d
- e I would also like to see this leveraged for namePrefix/nameSuffix exclusions: # base
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- a
- b
- c
---
# overlay
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: "prod-"
exclude:
- a resulting in resources: a # (any resources contained within a... so if a contained a svc,deployment,etc they would all not have a prefix)
prod-b
prod-c |
@cdenneen Right now the KustomizationPatch effectively just moves resources from the parent Kustomization, so wouldn't provide anything like |
That's what I was thinking when I suggested @cdenneen take a look at this issue in slack. I also believe my proposal #2256 would make this even easier because you could have multiple Kustomizations in the same file, each using a different combination of |
/approve @pgpx @apyrgio @monopole Thanks everyone for your persistence on this. Really liking how this is coming together. Most of my comments are nits, only blocking issues from my end are the additional test cases (not the table test refactor). Could we target merging this after the next sig-cli meeting if there are no blocking issues? (this coming Wednesday). Adding approval now. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pgpx, 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 |
8b4289c
to
98cb7fc
Compare
`, | ||
}, | ||
|
||
"multiple-bases-can-add-the-same-component-if-it-doesn-not-define-named-entities": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (non-blocking): if-it-doesn-not
-> if-it-does-not
}, | ||
// See how nameSuffix "-b" is also added to the resources included by "comp-a" because they are in the | ||
// accumulator when "comp-b" is accumulated. In practice we could use simple Kustomizations for this example. | ||
"components-can-add-the-same-base-if-the-first-renames-resources": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an interesting but weird case. I understand why it works this way, but found it a bit counter intuitive from a usage perspective -- something to follow up on before v1beta1. consider adding a TODO: figure out if this is the right behavior
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" | ||
) | ||
|
||
type FileGen func(kusttest_test.Harness) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
@pgpx thanks for the updates |
/lgtm |
@pwittrock @monopole Hi, sorry, but it looks like the master build doesn't work - I think that a new version of the api module needs to be released (because of the added |
Yes, the API needs to be released and updated in kustomize. You can test it by using the replace directive in the kustomize go.mod and building locally |
Thanks - |
@pwittrock sorry - do I need to do anything to update the API version, or will that happen automatically/done by someone else during the release? |
@monopole I think a new version of the api module needs to be released in order for this PR to work, but it looks like that will be needed anyway for subsequent changes in master. Sorry - I somehow missed this when I pushed originally. |
Closes #1251
Note that a little more work is needed on this WIP, and I would appreciate some feedback:
KustomizationPatch
should be changed. @apyrgio suggestedKustomizationComponent
, or maybeKustomizationComposer
,KustomizationComposite
,KustomizationSlice
?This PR allows 'patches/components' to be (re)used in a way that avoids diamond inheritance problems and with minimal impact to Kustomize's file format.
Normally a Kustomization file can only modify resources that are defined in its child resources, which means that it is difficult to introduce modifications that might be reused across different environments because there might not be a single Kustomization file that is used by each environment. For example:
This PR introduces the KustomizationPatch file, which has exactly the same syntax as a Kustomization file, other than a different
kind
. Whenever it is used in theresources
list of a parent, it takes all of the resources that came before it and adds them to the start of its own resources list - effectively inserting itself into the resource tree and gaining access to all of those child resources.For example, given:
This is effectively the same as:
This applies recursively, so as @apyrgio said, thi is a for Kustomize to support composition by internally converting a list of overlays (KustomizationPatches) to a chain of overlays. He made some other useful comments in the issue.
The implementation seems to be quite simple - just swapping the child KustomizationPatch's (empty) resource accumulator with its parent's when resources are being accumulated. I did make some assumptions that do seem to hold: