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

Kubernetes admission request generator #77

Closed
shayfisher opened this issue Oct 21, 2020 · 2 comments
Closed

Kubernetes admission request generator #77

shayfisher opened this issue Oct 21, 2020 · 2 comments

Comments

@shayfisher
Copy link

shayfisher commented Oct 21, 2020

When testing policies with k8s I think it would be beneficial to have some kind of admission request generator so I could test policies on my IDE (vscode) without deploying to a k8s env such as minikube.
Also, it would be helpful to get like a snapshot data json to simulate how OPA would cache information requested - e.g, if I ask OPA to cache v1/namespaces, how will the output data object will look like on a given environment on a given point in time.
If those are already available please tell me how to achieve this kind of data - it would accelerate my policy development process.
Thanks!
Awesome project!

@tsandall
Copy link
Member

Unfortunately neither of those exist at this point in time. For the admission request generator, you could write a simple function in your test suite to generate the appropriate structure, e.g:

package tests

# obviously this is not complete, but you get the picture
admission_review(obj) = {"request": {"object": obj}}

Then you can call this function your tests:

package example_test

import data.tests.admission_review

test_deny_foo_bar {
   result := data.example.deny_foo_bar with input as admission_review(...)
}

Also, it's worth pointing out that you can specify paths in with statements:

result := data.example.deny_foo_bar with input.request.object as ...

Sometimes this makes test fixtures easier to specify.

@shayfisher
Copy link
Author

Hi @tsandall ,
Thank your answering.

I will check it.

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

No branches or pull requests

2 participants