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

Enable fn framework container patches to work with more kinds #4113

Merged

Conversation

KnVerey
Copy link
Contributor

@KnVerey KnVerey commented Aug 10, 2021

Fixes a TODO in the fn framework: make container patches support more workload kinds. The perfect way to do this would be to traverse the openAPI schemas looking for embedded container. That would work for CRs too, IF we've been given schemas for them AND they use references rather than redefining the container spec. But since there is a very small set of well-known paths, this much simpler solution works equally well for the built-in workload kinds.

@k8s-ci-robot
Copy link
Contributor

@KnVerey: 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 the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 10, 2021
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 10, 2021
@KnVerey KnVerey requested a review from monopole August 10, 2021 23:14
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KnVerey

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 Aug 10, 2021
kyaml/yaml/fns.go Outdated Show resolved Hide resolved
@KnVerey KnVerey changed the title Kyaml container patch kinds Enable fn framework container patches to work with more kinds Aug 10, 2021
kyaml/yaml/fns.go Outdated Show resolved Hide resolved
var result *RNode
var err error
for _, path := range paths {
result, err = PathGetter{Path: path}.Filter(resource)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it really makes a difference, but should this use Lookup instead?

e.g. result, err = resource.Pipe(yaml.Lookup(path...))?

kyaml/openapi/kubernetesapi/openapiinfo.go Show resolved Hide resolved
@natasha41575
Copy link
Contributor

The perfect way to do this would be to traverse the openAPI schemas looking for embedded container.

Just as a general comment, I think we need to find a faster way to parse the OpenAPI schema. Many of the issues filed regarding performance degradation is because we switch something hardcoded over to parsing the OpenAPI documents.

@KnVerey KnVerey force-pushed the kyaml_container_patch_kinds branch from 7f869ea to f59f5f4 Compare August 16, 2021 17:21
@@ -168,8 +168,7 @@ func (cpt ContainerPatchTemplate) apply(matches []*yaml.RNode) error {
}

for i := range matches {
// TODO(knverey): Make this work for more Kinds and expose the helper for doing so.
containers, err := matches[i].Pipe(yaml.Lookup("spec", "template", "spec", "containers"))
containers, err := yaml.LookupFirstMatch(yaml.ConventionalContainerPaths).Filter(matches[i])
Copy link
Contributor

@natasha41575 natasha41575 Aug 16, 2021

Choose a reason for hiding this comment

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

What is the motivation for changing the way the filter is invoked? I believe you could have still used matches[i].Pipe(yaml.LookupFirstMatch(yaml.ConventionalContainerPaths)) so I'm wondering if there is a reason you prefer to call Filter directly rather than using Pipe?

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM other than this, but I'd like to understand the reasoning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No particular reason. As you noted, my helper originally wasn't a filter, so when I made it one, I fixed this call site by tacking Filter onto the end without looking back at the original diff. The only difference if you only have one Filter seems to be that Pipe short-circuits when given nil input, and special-cases root document nodes. Doesn't hurt to use it here, or in the helper. Since it raised questions for you, I'll change it.

@KnVerey KnVerey force-pushed the kyaml_container_patch_kinds branch from f59f5f4 to 75df1a5 Compare August 17, 2021 18:16
@natasha41575
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 Aug 17, 2021
@k8s-ci-robot k8s-ci-robot merged commit a2eaae5 into kubernetes-sigs:master Aug 17, 2021
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants