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

add replacement filter to support replacmenttransformer #3735

Merged

Conversation

natasha41575
Copy link
Contributor

@natasha41575 natasha41575 commented Mar 17, 2021

Part of #3492

The existing, untested replacement transformer converts the resource to a map, applies the transformations, and then must convert it back to a resource. Instead of doing this, it will be better to directly transform the resource's underlying RNode and avoiding these conversions. Here is an implementation for a filter to do it. For now it is only handles simple cases, we can build on it after we have a simple version working.

Next steps would be to rewrite the replacement transformer plugin to use this filter, and move the plugin to the examples folder.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 17, 2021
@k8s-ci-robot k8s-ci-robot requested a review from droot March 17, 2021 20:57
@natasha41575 natasha41575 removed the request for review from droot March 17, 2021 20:58
@natasha41575 natasha41575 force-pushed the ReplacementFilter branch 2 times, most recently from e7cc1a1 to 35422be Compare March 18, 2021 20:13
api/filters/replacement/doc.go Outdated Show resolved Hide resolved
api/filters/replacement/example_test.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
@natasha41575 natasha41575 requested a review from KnVerey March 19, 2021 23:34
@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 Mar 19, 2021
Copy link
Contributor

@KnVerey KnVerey left a comment

Choose a reason for hiding this comment

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

I have a question about the feature set we want for the source/target fields, but it doesn't need to block this initial iteration from merging.

/lgtm

api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/types/replacement.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 20, 2021
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 22, 2021
@natasha41575
Copy link
Contributor Author

@monopole could you take a look? This still needs approval from someone on the kustomize maintainers list

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.

added comment above, request no new use of the Target struct.

@natasha41575
Copy link
Contributor Author

@monopole @KnVerey updated the PR to reflect the proposed config

I also added a field (fieldPaths) to make it possible for targets to have multiple fieldpaths. An example use case for this is in one of the tests, but if this functionality is not desired I can take it out. To keep the size of the PR down, I haven't yet implemented use of the deny or options field; I plan to do that in a later PR.

api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
@monopole
Copy link
Contributor

looks great, just minor nits. thanks for deferring Deny and fieldoptions.

@natasha41575 natasha41575 force-pushed the ReplacementFilter branch 2 times, most recently from 6e9034d to 7560846 Compare March 30, 2021 23:35
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 31, 2021
@natasha41575 natasha41575 requested a review from monopole March 31, 2021 20:05
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/types/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
api/filters/replacement/replacement.go Outdated Show resolved Hide resolved
Copy link
Contributor

@KnVerey KnVerey left a comment

Choose a reason for hiding this comment

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

I think we should add more test coverage, including regression cases for the empty namespace and missing group issues identified in the last round. But that can be done in follow-ups; there's already at least one other testing TODO. Found a few documentation typos, but they're about the deferred fields anyway.

/lgtm

Select *Selector `json:"select" yaml:"select"`

// From the allowed set, remove objects that match this.
// TODO (#3492): Remove matches listed in the exclude field
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TODO (#3492): Remove matches listed in the exclude field
// TODO (#3492): Remove matches listed in the Reject field

type ReplTarget struct {
ObjRef *Selector `json:"objref,omitempty" yaml:"objref,omitempty"`
FieldRefs []string `json:"fieldrefs,omitempty" yaml:"fieldrefs,omitempty"`
// FieldPath is a structured field path to the desired object
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// FieldPath is a structured field path to the desired object
// FieldOptions refine the interpretation of FieldPaths.

FieldRefs []string `json:"fieldrefs,omitempty" yaml:"fieldrefs,omitempty"`
// FieldPath is a structured field path to the desired object
// TODO (#3492): Implement use of these options, they are
// currently used
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// currently used
// currently unused

input string
replacements string
expected string
expectedErr bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Is using a bool for this the norm on this project? I'm used to matching against an error string when an error is expected, since there are typically multiple places an error could occur, and it's also nice to assert against what the user will actually see.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can update this on a followup PR (along with all the typos). Thanks so much for your help!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KnVerey, monopole, natasha41575

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

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/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.

4 participants