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: Gator sync test support #3098

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

anlandu
Copy link
Member

@anlandu anlandu commented Oct 21, 2023

What this PR does / why we need it:
Certain templates require replicating into OPA to enable correct evaluation. These templates can use the annotation metadata.gatekeeper.sh/requires-sync-data to indicate which resources need to be synced. This template annotation is descriptive, not prescriptive. The prescription of which resources to sync is done in SyncSet resources and/or the Gatekeeper Config resource. The management of these various requirements can get challenging as the number of templates requiring replicated data increases.

gator sync test aims to mitigate this challenge by enabling the user to verify their sync configuration is correct. The user passes in any number of Constraint Templates, SyncSets, and a Gatekeeper Config object, along with a GVK manifest listing the GVKs supported by the cluster under test, and the command will determine which requirements enumerated by the Constraint Templates are unfulfilled by the given SyncSet(s), Config, and/or manifest.

PRD

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):
xref #2393

Special notes for your reviewer:

@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2023

Codecov Report

Attention: Patch coverage is 35.79545% with 226 lines in your changes are missing coverage. Please review.

Project coverage is 46.43%. Comparing base (3350319) to head (935b85b).
Report is 58 commits behind head on master.

Files Patch % Lines
apis/gvkmanifest/v1alpha1/zz_generated.deepcopy.go 0.00% 105 Missing ⚠️
pkg/gator/reader/read_resources.go 0.00% 58 Missing ⚠️
cmd/gator/sync/test/test.go 0.00% 25 Missing ⚠️
pkg/gator/sync/test/test.go 79.34% 12 Missing and 7 partials ⚠️
pkg/cachemanager/parser/syncannotationreader.go 30.00% 14 Missing ⚠️
cmd/gator/sync/sync.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3098      +/-   ##
==========================================
- Coverage   54.49%   46.43%   -8.06%     
==========================================
  Files         134      225      +91     
  Lines       12329    15112    +2783     
==========================================
+ Hits         6719     7018     +299     
- Misses       5116     7283    +2167     
- Partials      494      811     +317     
Flag Coverage Δ
unittests 46.43% <35.79%> (-8.06%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anlandu
Copy link
Member Author

anlandu commented Oct 23, 2023

@julianKatz @acpana

@julianKatz julianKatz self-requested a review October 23, 2023 20:21
Copy link
Contributor

@acpana acpana left a comment

Choose a reason for hiding this comment

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

This looks really good 💯 !! Thanks for working on it.

A few questions and suggestions.

cmd/gator/sync/sync.go Outdated Show resolved Hide resolved
cmd/gator/sync/sync.go Outdated Show resolved Hide resolved
cmd/gator/sync/sync.go Outdated Show resolved Hide resolved
cmd/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
cmd/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
pkg/gator/sync/verify/verify_test.go Outdated Show resolved Hide resolved
pkg/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
pkg/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
pkg/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
pkg/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
@anlandu anlandu requested a review from acpana October 23, 2023 20:48
cmd/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
cmd/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
cmd/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
pkg/gator/fixtures/fixtures.go Show resolved Hide resolved
pkg/gator/fixtures/fixtures.go Outdated Show resolved Hide resolved
pkg/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
pkg/gator/sync/verify/verify.go Outdated Show resolved Hide resolved
pkg/gator/sync/verify/verify_test.go Outdated Show resolved Hide resolved
website/docs/gator.md Outdated Show resolved Hide resolved
website/docs/gator.md Outdated Show resolved Hide resolved
@anlandu anlandu requested a review from a team as a code owner November 4, 2023 00:19
@anlandu anlandu changed the title feat: Gator sync verify support feat: Gator sync test support Nov 9, 2023
Signed-off-by: Anlan Du <[email protected]>
@anlandu
Copy link
Member Author

anlandu commented Jan 3, 2024

@ritazh Definitely! I'll finish up these last comments next week.

Signed-off-by: Anlan Du <[email protected]>
Comment on lines -176 to -185
func isTemplate(u *unstructured.Unstructured) bool {
gvk := u.GroupVersionKind()
return gvk.Group == templatesv1.SchemeGroupVersion.Group && gvk.Kind == "ConstraintTemplate"
}

func isConstraint(u *unstructured.Unstructured) bool {
gvk := u.GroupVersionKind()
return gvk.Group == "constraints.gatekeeper.sh"
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not have helper methods like these in the code somewhere already? Perhaps not but they seem to straightforward and helpful i'd be surprised.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a great question lol, do you remember seeing anything back when these were written in the gator test PR

website/docs/gator.md Outdated Show resolved Hide resolved
website/docs/gator.md Outdated Show resolved Hide resolved
pkg/gator/sync/test/test_test.go Outdated Show resolved Hide resolved
anlandu and others added 4 commits January 17, 2024 13:22
Copy link
Contributor

@acpana acpana left a comment

Choose a reason for hiding this comment

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

LGTM modulo small nit around testing

@anlandu
Copy link
Member Author

anlandu commented Jan 22, 2024

Thanks for all the comments so far, let me know if you have any thoughts @ritazh @sozercan @maxsmythe!

Copy link

stale bot commented Mar 22, 2024

This issue 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 Mar 22, 2024
@stale stale bot removed the stale label Apr 5, 2024
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.

None yet

7 participants