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

feat: add ability to restrict required-probes constraint to containers in pods selected by a service #273

Closed

Conversation

ctrought
Copy link
Contributor

@ctrought ctrought commented Jan 5, 2023

Signed-off-by: Craig Trought [email protected]

What this PR does / why we need it:
Adds a parameter to restrict enforcement of the constraint to containers in pods that are selected by a service with at least one matching targetPort. For workloads that do not accept incoming traffic in pods it's common to not have readiness probes. This will allow the user to avoid generating violations for pods that do not accept incoming traffic via services. To leverage this services must be cached. This is a non-breaking change as the original implementation without caching is still supported by omitting the new parameter.

Adds a parameter to set an optional custom violation string that is appended to the standard one. I can revert this if it's not desired for the library, but we like to tailor certain violation messages with additional context so having the ability to do that in the constraint itself provides us the flexibility to do that without needing to alter the constraint template itself.

Removes the pod name from the violation message to avoid issues with expanded objects that likely won't contain a name. Seen in open-policy-agent/gatekeeper#2485

@maxsmythe
Copy link
Contributor

The Rego LGTM, haven't taken a closer look at the rest yet.

@apeabody @ekitson

Here is an example of a constraint template where referential data is only needed for certain configurations.

@ctrought ctrought force-pushed the required-probes-only-services branch from 69d2913 to 2810758 Compare January 5, 2023 01:48
@JaydipGabani
Copy link
Contributor

Few nits, but otherwise LGTM

@sozercan
Copy link
Member

@ctrought thanks for the PR! Looks like there are conflicts, can you resolve when you get a chance?

@ctrought ctrought force-pushed the required-probes-only-services branch 5 times, most recently from 2128239 to 8d9bd22 Compare January 31, 2023 05:07
@ctrought ctrought force-pushed the required-probes-only-services branch from 8d9bd22 to 6f4b8ec Compare March 17, 2023 20:19
@ctrought
Copy link
Contributor Author

Thanks @sozercan , sorry for the delay.. I've resolved the merge conflicts.

@stale
Copy link

stale bot commented May 20, 2023

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 20, 2023
@apeabody apeabody removed the stale label May 22, 2023
apeabody
apeabody previously approved these changes May 26, 2023
Copy link
Contributor

@apeabody apeabody left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @ctrought!

@sozercan The CI is now passing

Makefile Outdated Show resolved Hide resolved
@apeabody
Copy link
Contributor

Thanks for the contribution @ctrought - When you get a chance, I think there are just a few very minor open items above.

ctrought and others added 4 commits June 20, 2023 10:31
…s in pods selected by a service

Signed-off-by: Craig Trought <[email protected]>
Co-authored-by: Jaydipkumar Arvindbhai Gabani <[email protected]>
Signed-off-by: Craig Trought <[email protected]>
Signed-off-by: Craig Trought <[email protected]>
Signed-off-by: Craig Trought <[email protected]>
@ctrought ctrought force-pushed the required-probes-only-services branch from 77cc8a2 to f7ae6f9 Compare June 20, 2023 14:43
@apeabody apeabody requested a review from maxsmythe June 30, 2023 15:21
Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

Rego code and idea LGTM (did not look at rest of PR structure, tests, etc., relying on other reviewers there)

@apeabody apeabody requested a review from sozercan July 24, 2023 16:03
@@ -8,5 +8,6 @@ spec:
- apiGroups: [""]
Copy link
Member

@sozercan sozercan Jul 25, 2023

Choose a reason for hiding this comment

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

seems like we have samples in artifacthub but not here? is that intended?

@@ -4,7 +4,17 @@ metadata:
name: k8srequiredprobes
annotations:
metadata.gatekeeper.sh/title: "Required Probes"
metadata.gatekeeper.sh/version: 1.0.0
metadata.gatekeeper.sh/version: 1.1.0
metadata.gatekeeper.sh/requires-sync-data: |
Copy link
Member

Choose a reason for hiding this comment

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

To clarify a bit around the UX, with the onlyServices parameter, it seems syncing service is optional, however does this annotation make syncing service a requirement?

Copy link
Contributor

Choose a reason for hiding this comment

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

@apeabody this is a good question. How do we deal with conditionally referential templates? Should we just have a separate template, instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Creating a separate template is an option, although I believe our goal should be to minimize the overall quantity of templates.

The current release Gatekeeper doesn't enforce requires-sync-data, and unmarshaling of the annotation was only added in v3.13.0-beta.1. Depending on the roadmap, this might not be a blocker if the future plan was only to add a warning by default if the "required" sync wasn't configured in gatekeeper?

@apeabody apeabody dismissed their stale review August 2, 2023 19:52

stale based on discussion

@ritazh
Copy link
Member

ritazh commented Aug 3, 2023

To clarify a bit around the UX, with the onlyServices parameter, it seems syncing service is optional, however does this annotation make syncing service a requirement?

Per today's community call, adding the requires-sync-data annotation to an existing template is a breaking change. The decision is to create a new template K8sRequiredProbesWithServices instead of bumping major version of the existing template, since v1 is still valuable to maintain and should not be deprecated.

@ctrought Can you please update this PR based on ^ Thank you!

@stale
Copy link

stale bot commented Oct 2, 2023

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 2, 2023
@stale stale bot closed this Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants