-
Notifications
You must be signed in to change notification settings - Fork 330
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 replicalimits ConstraintTemplate to handle scaling to zero properly. Fixes #419 #427
Fix replicalimits ConstraintTemplate to handle scaling to zero properly. Fixes #419 #427
Conversation
…ly. Fixes open-policy-agent#419 Signed-off-by: Paul Krizak <[email protected]>
I'm going to need some help here. I thought that I followed the instructions properly for modifying the source code. But I found that |
Hi @skaven81 the separate |
+ + example-scale-allowed+ +```yaml +apiVersion: autoscaling/v1 +kind: Scale +metadata:
+ example-disallowed@@ -172,6 +194,168 @@ Usage kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/library/general/replicalimits/samples/replicalimits/example_disallowed.yaml ```+ + + example-scale-disallowed+ +```yaml +apiVersion: autoscaling/v1 +kind: Scale +metadata:
+
+
+
+
+
+ Please run 'make generate generate-website-docs generate-artifacthub-artifacts' to generate the templates and docs
|
When I run The website docs did get regenerated, and they're in my commit: 33b39e1#diff-578c418f3682058d7a372ca0fd2d3dafb3cd57c31df54872bbc81890ad63b261 There's something missing from the contribution process that regular contributors must be doing without thinking about it, but isn't explicit in the documentation. Here's what I did:
Step 3 was almost certainly wrong. But the documentation (https://github.com/open-policy-agent/gatekeeper-library#development) makes no mention of how to build the tests, and the Makefile doesn't seem to have anything in there that touches |
Hi @skaven81 - Sorry any confusion, the I did a quick test run of |
Signed-off-by: Paul Krizak <[email protected]>
OK I re-ran |
There was a problem hiding this 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 @skaven81!
@@ -51,23 +51,39 @@ empty = { | |||
} | |||
|
|||
review(replicas) = output { | |||
replicas > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It might be nice to support a test where spec.replicas
is specifically set to 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule just below with replicas == 0
is what tests that, by blanking out spec
(that's what the whole PR is about). I agree that having an additional test that explicitly checks spec.replicas=0
would be good, but it would require a rather large refactoring of the source-to-tests logic to allow for review(replicas)
to return two different objects when replicas=0
. In fact, that very idea (a Rego function that returns multiple values for the same input) is strictly forbidden by Rego. So the whole thing would need to be reworked from scratch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, I see no evidence that src_test.rego
is even being read by anything -- it certainly doesn't seem to be generating the tests under library/general/replicalimits
, so I suppose I could add such a test manually and it would likely still pass all the CI tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @skaven81 - The Rego tests under src/general/replicalimits/
do not build the KRM tests under library/general/replicalimits/
, however they are run by theCI / Unit test on {}
using the opa test
command for each folder under src/
- this is basically the same as running ./test.sh
locally.
Signed-off-by: Paul Krizak <[email protected]>
Needs a fresh make generate-all
- Thanks!
…N=3.11.5 -f build/gomplate/Dockerfile -t gomplate-container . Sending build context to Docker daemon 6.362MB Step 1/6 : FROM golang:1.20@sha256:cfc9d1b07b1ef4f7a4571f0b60a99646a92ef76adb7d9943f4cb7b606c6554e2 ---> e69c1df674bc Step 2/6 : ARG GOMPLATE_VERSION ---> Using cache ---> 751f5c31a643 Step 3/6 : RUN go install github.com/hairyhenderson/gomplate/v3/cmd/gomplate@v${GOMPLATE_VERSION} ---> Using cache ---> d93d01668b95 Step 4/6 : RUN mkdir /gatekeeper-library ---> Using cache ---> 7e08e5a42a41 Step 5/6 : WORKDIR /gatekeeper-library ---> Using cache ---> 2f47b827d027 Step 6/6 : ENTRYPOINT ["/bin/bash"] ---> Using cache ---> 72ede59d508b Successfully built 72ede59d508b Successfully tagged gomplate-container:latest docker run \ -u 1000:1000 \ -v /tmp/gatekeeper-library:/gatekeeper-library \ gomplate-container ./scripts/generate.sh Generating library/pod-security-policy/selinux/template.yaml Generating library/pod-security-policy/host-filesystem/template.yaml Generating library/pod-security-policy/forbidden-sysctls/template.yaml Generating library/pod-security-policy/users/template.yaml Generating library/pod-security-policy/fsgroup/template.yaml Generating library/pod-security-policy/host-network-ports/template.yaml Generating library/pod-security-policy/flexvolume-drivers/template.yaml Generating library/pod-security-policy/privileged-containers/template.yaml Generating library/pod-security-policy/allow-privilege-escalation/template.yaml Generating library/pod-security-policy/apparmor/template.yaml Generating library/pod-security-policy/capabilities/template.yaml Generating library/pod-security-policy/host-namespaces/template.yaml Generating library/pod-security-policy/seccomp/template.yaml Generating library/pod-security-policy/proc-mount/template.yaml Generating library/pod-security-policy/volumes/template.yaml Generating library/pod-security-policy/read-only-root-filesystem/template.yaml Generating library/general/allowedrepos/template.yaml Generating library/general/containerlimits/template.yaml Generating library/general/block-wildcard-ingress/template.yaml Generating library/general/disallowedrepos/template.yaml Generating library/general/poddisruptionbudget/template.yaml Generating library/general/uniqueingresshost/template.yaml Generating library/general/containerrequests/template.yaml Generating library/general/block-endpoint-edit-default-role/template.yaml Generating library/general/uniqueserviceselector/template.yaml Generating library/general/block-loadbalancer-services/template.yaml Generating library/general/replicalimits/template.yaml Generating library/general/horizontalpodautoscaler/template.yaml Generating library/general/externalip/template.yaml Generating library/general/imagedigests/template.yaml Generating library/general/httpsonly/template.yaml Generating library/general/block-nodeport-services/template.yaml Generating library/general/storageclass/template.yaml Generating library/general/automount-serviceaccount-token/template.yaml Generating library/general/ephemeralstoragelimit/template.yaml Generating library/general/disallowedtags/template.yaml Generating library/general/requiredlabels/template.yaml Generating library/general/noupdateserviceaccount/template.yaml Generating library/general/verifydeprecatedapi/template.yaml Generating library/general/requiredannotations/template.yaml Generating library/general/disallowanonymous/template.yaml Generating library/general/containerresources/template.yaml Generating library/general/containerresourceratios/template.yaml Generating library/general/requiredprobes/template.yaml cd /tmp/gatekeeper-library/scripts/website; go run generate.go Generating markdown for /tmp/gatekeeper-library/library/general/allowedrepos Generating markdown for /tmp/gatekeeper-library/library/general/automount-serviceaccount-token Generating markdown for /tmp/gatekeeper-library/library/general/block-endpoint-edit-default-role Generating markdown for /tmp/gatekeeper-library/library/general/block-loadbalancer-services Generating markdown for /tmp/gatekeeper-library/library/general/block-nodeport-services Generating markdown for /tmp/gatekeeper-library/library/general/block-wildcard-ingress Generating markdown for /tmp/gatekeeper-library/library/general/containerlimits Generating markdown for /tmp/gatekeeper-library/library/general/containerrequests Generating markdown for /tmp/gatekeeper-library/library/general/containerresourceratios Generating markdown for /tmp/gatekeeper-library/library/general/containerresources Generating markdown for /tmp/gatekeeper-library/library/general/disallowanonymous Generating markdown for /tmp/gatekeeper-library/library/general/disallowedrepos Generating markdown for /tmp/gatekeeper-library/library/general/disallowedtags Generating markdown for /tmp/gatekeeper-library/library/general/ephemeralstoragelimit Generating markdown for /tmp/gatekeeper-library/library/general/externalip Generating markdown for /tmp/gatekeeper-library/library/general/horizontalpodautoscaler Generating markdown for /tmp/gatekeeper-library/library/general/httpsonly Generating markdown for /tmp/gatekeeper-library/library/general/imagedigests Generating markdown for /tmp/gatekeeper-library/library/general/noupdateserviceaccount Generating markdown for /tmp/gatekeeper-library/library/general/poddisruptionbudget Generating markdown for /tmp/gatekeeper-library/library/general/replicalimits Generating markdown for /tmp/gatekeeper-library/library/general/requiredannotations Generating markdown for /tmp/gatekeeper-library/library/general/requiredlabels Generating markdown for /tmp/gatekeeper-library/library/general/requiredprobes Generating markdown for /tmp/gatekeeper-library/library/general/storageclass Generating markdown for /tmp/gatekeeper-library/library/general/uniqueingresshost Generating markdown for /tmp/gatekeeper-library/library/general/uniqueserviceselector Generating markdown for /tmp/gatekeeper-library/library/general/verifydeprecatedapi Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/allow-privilege-escalation Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/apparmor Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/capabilities Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/flexvolume-drivers Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/forbidden-sysctls Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/fsgroup Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/host-filesystem Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/host-namespaces Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/host-network-ports Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/privileged-containers Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/proc-mount Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/read-only-root-filesystem Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/seccomp Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/selinux Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/users Generating markdown for /tmp/gatekeeper-library/library/pod-security-policy/volumes Generating markdown for /tmp/gatekeeper-library/mutation/pod-security-policy/allow-privilege-escalation Generating markdown for /tmp/gatekeeper-library/mutation/pod-security-policy/capabilities Generating markdown for /tmp/gatekeeper-library/mutation/pod-security-policy/read-only-root-filesystem Generating markdown for /tmp/gatekeeper-library/mutation/pod-security-policy/seccomp Generating markdown for /tmp/gatekeeper-library/mutation/pod-security-policy/selinux Generating markdown for /tmp/gatekeeper-library/mutation/pod-security-policy/users Updating README.md Updating PSP README.md Updating sidebar cd /tmp/gatekeeper-library/scripts/artifacthub; go run hub.go Generating artifact hub content for /tmp/gatekeeper-library/library/general/allowedrepos Generating artifact hub content for /tmp/gatekeeper-library/library/general/automount-serviceaccount-token Generating artifact hub content for /tmp/gatekeeper-library/library/general/block-endpoint-edit-default-role Generating artifact hub content for /tmp/gatekeeper-library/library/general/block-loadbalancer-services Generating artifact hub content for /tmp/gatekeeper-library/library/general/block-nodeport-services Generating artifact hub content for /tmp/gatekeeper-library/library/general/block-wildcard-ingress Generating artifact hub content for /tmp/gatekeeper-library/library/general/containerlimits Generating artifact hub content for /tmp/gatekeeper-library/library/general/containerrequests Generating artifact hub content for /tmp/gatekeeper-library/library/general/containerresourceratios Generating artifact hub content for /tmp/gatekeeper-library/library/general/containerresources Generating artifact hub content for /tmp/gatekeeper-library/library/general/disallowanonymous Generating artifact hub content for /tmp/gatekeeper-library/library/general/disallowedrepos Generating artifact hub content for /tmp/gatekeeper-library/library/general/disallowedtags Generating artifact hub content for /tmp/gatekeeper-library/library/general/ephemeralstoragelimit Generating artifact hub content for /tmp/gatekeeper-library/library/general/externalip Generating artifact hub content for /tmp/gatekeeper-library/library/general/horizontalpodautoscaler Generating artifact hub content for /tmp/gatekeeper-library/library/general/httpsonly Generating artifact hub content for /tmp/gatekeeper-library/library/general/imagedigests Generating artifact hub content for /tmp/gatekeeper-library/library/general/noupdateserviceaccount Generating artifact hub content for /tmp/gatekeeper-library/library/general/poddisruptionbudget Generating artifact hub content for /tmp/gatekeeper-library/library/general/replicalimits Generating artifact hub content for /tmp/gatekeeper-library/library/general/requiredannotations Generating artifact hub content for /tmp/gatekeeper-library/library/general/requiredlabels Generating artifact hub content for /tmp/gatekeeper-library/library/general/requiredprobes Generating artifact hub content for /tmp/gatekeeper-library/library/general/storageclass Generating artifact hub content for /tmp/gatekeeper-library/library/general/uniqueingresshost Generating artifact hub content for /tmp/gatekeeper-library/library/general/uniqueserviceselector Generating artifact hub content for /tmp/gatekeeper-library/library/general/verifydeprecatedapi Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/allow-privilege-escalation Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/apparmor Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/capabilities Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/flexvolume-drivers Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/forbidden-sysctls Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/fsgroup Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/host-filesystem Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/host-namespaces Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/host-network-ports Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/privileged-containers Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/proc-mount Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/read-only-root-filesystem Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/seccomp Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/selinux Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/users Generating artifact hub content for /tmp/gatekeeper-library/library/pod-security-policy/volumes Signed-off-by: Paul Krizak <[email protected]>
0e3ed95
to
90ee21f
Compare
Co-authored-by: Andrew Peabody <[email protected]> Signed-off-by: Paul Krizak <[email protected]>
Signed-off-by: Paul Krizak <[email protected]>
Signed-off-by: Paul Krizak <[email protected]>
4072071
to
d1851d2
Compare
I don't know why we keep dancing back and forth on this. Every time I fix my branch so that the tests all complete successfully, somebody comes along and does a merge from master which reverts some of my changes, and the tests start failing again. Somebody please just spend 10 minutes to manually review the actual PR and merge it in, instead of depending on the automation alone. |
@skaven81 Thank you for the PR and apologies for the back and forth. The merge from main didnt show any conflicts. If you see any, can you please help update the conflicts? We will review this today. Error from CI:
Looks like a previously merged PR updated the template version https://github.com/open-policy-agent/gatekeeper-library/pull/429/files#diff-c3f23f7cfeabf9bf68a4be9f0d84eb695dcaf8b31f3cdcbdaaa6aa269fcbb823L7. Can you please bump it again? Thank you! |
@apeabody other than the template version, LGTY? |
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. |
What this PR does / why we need it: The
replicalimits
ConstraintTemplate has two bugs that are fixed in this PR. First, theinput_replica_limit()
function contained a reference to globalinput.review.object.spec
instead of using the localspec
argument. Second, whenkubectl scale <resource> --replicas=0
is issued, aScale
resource is created with an emptyspec: { }
, notspec: { replicas: 0 }
. Usingobject.get()
with a default value of0
ensures that the ConstraintTemplate works properly in this condition.,Which issue(s) does this PR fix:
Fixes #419