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

fix: skip empty k8s resources #2247

Merged
merged 1 commit into from Aug 30, 2022
Merged

Conversation

qa-ship-it
Copy link
Contributor

What this PR does / why we need it:

While using the Gator CLI (v3.9.0) to test helm rendered k8s resources against our Gatekeeper constraints we ran into the following error: auditing objects: adding data of GVK "/, Kind=": admission.k8s.gatekeeper.sh: invalid request object: resource has no version
After investigation we found out that the error was due to a input file like the following one:

---
# Source: some/templates/file.yaml
name: object1
attrs:
  - attr1
  - attr2
---
# Source: some/templates/file.yaml
# only containing some comment
---
# Source: some/templates/file.yaml
name: object2
labels:
  - label1
  - label2

Apparently Gator CLI attempts to parse above snippet as 3 seperate YAML documents, looking for k8s resources inside them, which won't work as the second one containing only the comment cannot be parsed into a valid k8s resource at all.
This PR suggests skipping empty k8s resources.

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.

LGTM, thank you for the fix!

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2022

Codecov Report

Merging #2247 (1540232) into master (510da53) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2247      +/-   ##
==========================================
- Coverage   54.57%   54.55%   -0.03%     
==========================================
  Files         111      111              
  Lines        9554     9556       +2     
==========================================
- Hits         5214     5213       -1     
+ Misses       3946     3943       -3     
- Partials      394      400       +6     
Flag Coverage Δ
unittests 54.55% <100.00%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
pkg/gator/read_constraints.go 86.32% <100.00%> (+11.54%) ⬆️
...onstrainttemplate/constrainttemplate_controller.go 56.83% <0.00%> (-3.12%) ⬇️
pkg/readiness/object_tracker.go 82.91% <0.00%> (-1.07%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Marko Grgic <marko.grgic@qaware.de>
Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for the PR! 🎉

@ritazh ritazh merged commit 7bde011 into open-policy-agent:master Aug 30, 2022
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

4 participants