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 value testing to the assign mutator #1113

Merged
merged 6 commits into from
Feb 9, 2021

Conversation

maxsmythe
Copy link
Contributor

What this PR does / why we need it:

This PR adds value testing to the assign mutator, per the mutation design.

Note that the schema of the value tests has been changed slightly, I now assume a format like:

spec:
   parameters:
      assignIf:
         in: ["one", "two"]
         notIn: ["three"]

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes #1080

Special notes for your reviewer:

@maxsmythe
Copy link
Contributor Author

note that this change depends on #1101

@codecov-io
Copy link

Codecov Report

Merging #1113 (42e6141) into master (db5a580) will increase coverage by 0.79%.
The diff coverage is 66.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1113      +/-   ##
==========================================
+ Coverage   47.84%   48.63%   +0.79%     
==========================================
  Files          62       63       +1     
  Lines        4264     4369     +105     
==========================================
+ Hits         2040     2125      +85     
- Misses       1966     1989      +23     
+ Partials      258      255       -3     
Flag Coverage Δ
unittests 48.63% <66.50%> (+0.79%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/mutation/assign_mutator.go 40.31% <58.97%> (+12.24%) ⬆️
pkg/mutation/assignmeta_mutator.go 46.66% <66.66%> (+0.95%) ⬆️
pkg/mutation/path/tester/tester.go 67.56% <67.56%> (ø)
pkg/mutation/mutation_function.go 75.40% <73.41%> (+9.96%) ⬆️
...onstrainttemplate/constrainttemplate_controller.go 55.66% <0.00%> (+2.91%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db5a580...42e6141. Read the comment docs.

@maxsmythe maxsmythe force-pushed the valuetest branch 2 times, most recently from 1686141 to ae1a67e Compare February 6, 2021 03:32
Copy link
Contributor

@shomron shomron left a comment

Choose a reason for hiding this comment

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

LGTM

// IfNotIn Only mutate if the current value is NOT in the supplied list
IfNotIn []string `json:"ifNotIn,omitempty"`

// once https://github.com/kubernetes-sigs/controller-tools/pull/528
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to have been merged - should this PR be updated or will that be a followup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

follow-up. It's been merged, but I don't know if a version of the tool with that feature included has been released.

Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
@@ -25,6 +25,9 @@ func mutate(mutator types.Mutator, tester *path.Tester, obj *unstructured.Unstru
type mutatorState struct {
mutator types.Mutator
tester *path.Tester
// valueTest takes the input value and whether that value already existed.
// It returns true if the value should be mutated
valueTest func(interface{}, bool) bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious - was this made pluggable to facilitate testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the AssignMetadata mutator, which currently has no value test b/c it already requires target values to be undefined.

@maxsmythe maxsmythe merged commit 001f4c3 into open-policy-agent:master Feb 9, 2021
jdolce pushed a commit to jdolce/gatekeeper that referenced this pull request Feb 12, 2021
* Add locking, deepcopy path tester memoization

Signed-off-by: Max Smythe <smythe@google.com>

* Add path parsing error context

Signed-off-by: Max Smythe <smythe@google.com>

* Tester should also have a DeepCopy method

Signed-off-by: Max Smythe <smythe@google.com>

* Eager initialize path tester, guard against nil

Signed-off-by: Max Smythe <smythe@google.com>

* Add value test to assign mutator

Signed-off-by: Max Smythe <smythe@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mutation: Add Value Tests to Assign Mutators
3 participants