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 by pod status for mutators #1260

Merged
merged 5 commits into from
May 6, 2021

Conversation

maxsmythe
Copy link
Contributor

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

What this PR does / why we need it:

This adds byPod status for mutators. Testing is what's WIP, feel free to review the code itself.

It also refactors the mutation package some to avoid import cycles.

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 #

Special notes for your reviewer:

@codecov-commenter
Copy link

codecov-commenter commented Apr 17, 2021

Codecov Report

Merging #1260 (dc695d7) into master (aa20de6) will decrease coverage by 1.39%.
The diff coverage is 30.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1260      +/-   ##
==========================================
- Coverage   49.86%   48.47%   -1.40%     
==========================================
  Files          65       68       +3     
  Lines        4522     4879     +357     
==========================================
+ Hits         2255     2365     +110     
- Misses       1956     2161     +205     
- Partials      311      353      +42     
Flag Coverage Δ
unittests 48.47% <30.61%> (-1.40%) ⬇️

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

Impacted Files Coverage Δ
apis/status/v1beta1/constraintpodstatus_types.go 81.81% <ø> (ø)
...tatus/v1beta1/constrainttemplatepodstatus_types.go 77.77% <ø> (ø)
apis/status/v1beta1/zz_generated.deepcopy.go 0.00% <0.00%> (ø)
pkg/mutation/match/match.go 85.71% <ø> (ø)
pkg/mutation/match/zz_generated.deepcopy.go 0.00% <0.00%> (ø)
pkg/mutation/mutators/assignmeta_mutator.go 42.25% <0.00%> (ø)
pkg/mutation/mutators/core/mutation_function.go 61.53% <ø> (ø)
pkg/operations/operations.go 53.57% <ø> (ø)
pkg/util/pack.go 0.00% <0.00%> (ø)
...roller/assignmetadata/assignmetadata_controller.go 48.33% <43.03%> (ø)
... and 11 more

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 aa20de6...dc695d7. Read the comment docs.

@maxsmythe maxsmythe force-pushed the mutation-status branch 2 times, most recently from 2474e19 to 2b530f7 Compare April 24, 2021 05:22
@maxsmythe maxsmythe changed the title WIP: Add by pod status for mutators Add by pod status for mutators Apr 28, 2021
@maxsmythe
Copy link
Contributor Author

@ritazh @shomron @sozercan @mmirecki @fedepaol this is ready for review

@@ -162,7 +162,7 @@ install: manifests
kustomize build config/crd | kubectl apply -f -

deploy-mutation: patch-image
@grep -q -v 'enable-mutation' ./config/overlays/dev_mutation/manager_image_patch.yaml && sed -i '/- --operation=webhook/a \ \ \ \ \ \ \ \ - --enable-mutation=true' ./config/overlays/dev_mutation/manager_image_patch.yaml
@grep -q -v 'enable-mutation' ./config/overlays/dev_mutation/manager_image_patch.yaml && sed -i '/- --operation=webhook/a \ \ \ \ \ \ \ \ - --enable-mutation=true' ./config/overlays/dev_mutation/manager_image_patch.yaml && sed -i '/- --operation=status/a \ \ \ \ \ \ \ \ - --operation=mutation-status' ./config/overlays/dev_mutation/manager_image_patch.yaml
Copy link
Member

@ritazh ritazh Apr 29, 2021

Choose a reason for hiding this comment

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

TODO: need to update this in https://github.com/open-policy-agent/gatekeeper/blob/master/deploy/experimental/gatekeeper-mutation.yaml and helm chart when we have this in the next release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have a process for this? Should that be part of this PR?

Copy link
Member

Choose a reason for hiding this comment

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

Until #1190 is fixed, these updates need to done manually when we cut a release. Not part of this PR. For now, let's open an issue to track it and tag the upcoming milestone/release.

return nil, err
}
key := apiTypes.NamespacedName{Name: sName, Namespace: util.GetNamespace()}
if err := r.Get(context.TODO(), key, statusObj); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Should we use r.reader.Get here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto :)

if err != nil {
return nil, err
}
if err := r.Create(context.TODO(), statusObj); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

r.writer.Create?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto!!!! :)

tracker.Observe(assignMetadata)
tracker.TryCancelExpect(assignMetadata)
status.Status.Errors = append(status.Status.Errors, statusv1beta1.Error{Message: err.Error()})
if err2 := r.Update(ctx, status); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

r.writer.Update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reconcile struct doesn't have a reader/writer.

That was a change Oren made to certain controllers a while back "because the manager's default client bypasses the cache for unstructured resources" (per a comment he left).

This is not a concern for Assign/AssignMetadata as we are working with the typed client (not the unstructured client).

Default kubebuilder-generated code follows the present model of embedding the client in the reconciler struct. Since there is no functional difference, I'm ambivalent as to which is better. Do you prefer aligning with Kubebuilder or our other controllers?

Copy link
Member

Choose a reason for hiding this comment

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

This is not a concern for Assign/AssignMetadata as we are working with the typed client (not the unstructured client).

Agreed. Since this is not unstructured client, there's no functional difference. Let's keep it as is then.

log.Error(err, "Insert failed", "resource", request.NamespacedName)
tracker.TryCancelExpect(assignMetadata)
status.Status.Errors = append(status.Status.Errors, statusv1beta1.Error{Message: err.Error()})
if err2 := r.Update(ctx, status); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ditto :)

func (r *Reconciler) defaultGetPod() (*corev1.Pod, error) {
// require injection of GetPod in order to control what client we use to
// guarantee we don't inadvertently create a watch
panic("GetPod must be injected")
Copy link
Member

Choose a reason for hiding this comment

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

Should we also log here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Panic writes a core dump to stderr. Is there something specific you want to see with a log line.

FWIW this is a sanity check that the object is initialized properly, the pod wont run and our unit tests/e2e tests (should) fail if we hit this point

Copy link
Member

Choose a reason for hiding this comment

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

yea I was thinking at least log the pod name but yea the pod won't even come up so maybe it's a moot point.

@maxsmythe
Copy link
Contributor Author

Thanks for the reviews! Comments resolved except for those I had follow-up questions on.

@maxsmythe maxsmythe requested a review from ritazh April 30, 2021 01:54
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>
@maxsmythe
Copy link
Contributor Author

@ritazh @mmirecki any more comments or LGTY?

@maxsmythe maxsmythe merged commit 20a0e1a into open-policy-agent:master May 6, 2021
julianKatz pushed a commit to julianKatz/gatekeeper that referenced this pull request May 11, 2021
* Add by pod status for mutators

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

* Only enable mutation status if mutation is enabled

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

* Add tests

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

* Address PR comments

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.

4 participants