-
Notifications
You must be signed in to change notification settings - Fork 335
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(*): automate policy generation #4197
Conversation
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Codecov Report
@@ Coverage Diff @@
## master #4197 +/- ##
==========================================
- Coverage 55.82% 55.65% -0.18%
==========================================
Files 931 938 +7
Lines 56485 56654 +169
==========================================
- Hits 31534 31531 -3
- Misses 22435 22606 +171
- Partials 2516 2517 +1
Continue to review full report at Codecov.
|
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
``` | ||
|
||
2. Create a proto file for new policy in `pkg/plugins/policies/donothingpolicy/api/v1alpha1`. For example | ||
donothingpolicy.proto: |
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.
maybe best just to link to the file
|
||
# we don't want expressions to be expanded with yq, that's why we're intentionally using single quotes | ||
# shellcheck disable=SC2016 | ||
yq e '.spec.versions[] | select (.name == "'"${VERSION}"'") | .schema.openAPIV3Schema.properties.spec | del(.type) | del(.description)' \ |
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.
May be my bash skills but this is an effort to read IMO, isn't ${VERSION}
still expanded here since it's outside of the single quotes? Is this different from:
".spec.versions[] | select (.name == \"${VERSION}\") | .schema.openAPIV3Schema.properties.spec | del(.type) | del(.description)"
?
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.
I tried the option you proposed, but for some reason, it doesn't work. It just ignores escaping (debug mode output):
+ yq e '.spec.versions[] | select (.name == \"${VERSION}\") | .schema.openAPIV3Schema.properties.spec | del(.type) | del(.description)' pkg/plugins/policies/donothingpolicy/k8s/crd/kuma.io_donothingpolicies.yaml
+ yq eval-all -i '. as $item ireduce ({}; . * $item )' pkg/plugins/policies/donothingpolicy/api/v1alpha1/schema.yaml -
Error: parsing expression: Lexer error: could not match text starting at 1:37 failing at 1:38.
unmatched text: "\\"
I can leave a comment about why we need "'"
:
- the first double quote is needed because
yq select
expects something likeselect (.name == "v1alpha1")
- single quote is required to close the first single quote
- now when we outside of single quotes we simply use bash expression
"${VERSION}"
, that's why the last double quote is here
|
||
cp "${SCHEMA_TEMPLATE}" "${POLICIES_API_DIR}"/schema.yaml | ||
|
||
if [ "$(find "${POLICIES_CRD_DIR}" -type f | wc -l | xargs echo)" != 1 ]; then |
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.
if [ "$(find "${POLICIES_CRD_DIR}" -type f | wc -l | xargs echo)" != 1 ]; then | |
if [ "$(find "${POLICIES_CRD_DIR}" -type f | wc -l)" != 1 ]; then |
Doesn't wc -l
already return one line with one number?
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.
I don't know why but it's \t1
instead of just 1
, I didn't find another way to get rid of the tab
) | ||
|
||
// CustomResourceTemplate for creating a Kubernetes CRD to wrap a Kuma resource. | ||
var CustomResourceTemplate = template.Must(template.New("custom-resource").Parse(` |
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.
Dn't we already generate CRDs from Kuma resources? @parkanzky is that what you meant?
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.
Yes, we do in tools/resource-gen/main.go
, but it doesn't make sense to reuse the template for 2 reasons:
- templates are different, because
Spec
fields are different - we want to get rid of
tools/resource-gen/main.go
in the future because instead of accepting proto as an input, it imports all protos and generates resources for everything at once. It won't work well if you haveproto
files inside plugins directories
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
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.
This is a great start IMO.
Things that are missing (but can be done in a follow up PR):
- script to ease bootstrapping a new polciy
- way to combine all openAPI spec with a root one with the other apis
- how to actually do something with this polciy (hooks)
- did we agree of having CRDs namespace bound?
- did we agree on moving
mesh
to be a label and not a field?
description: Kuma API | ||
|
||
paths: | ||
/meshes/{mesh}/{{ WsPath }}/{name}: |
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.
Would it be possible to nest the new endpoints under /policies
or something like this? We're now in a place where we can add a lot of different paths at the root. It seems dangerous to have something on /
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.
Maybe good time to start prefix it with version?
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.
You mean http API version?
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.
Maybe though we'd still need a policy prefix or equivalent right?
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.
btw, I didn't touch the code that generates API endpoints, so simple change of templates/endpoints.yaml
is not enough. I'd keep this change until we implement first policy using generators
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com> Signed-off-by: Paul Parkanzky <paul.parkanzky@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Summary
Introduce
protoc-gen-kumapolicy
and the number of Makefile targets to generate the following resources:Issues resolved
N/A
Documentation
Testing
Backwards compatibility
- [ ] UpdateUPGRADE.md
with any steps users will need to take when upgrading.- [ ] Addbackport-to-stable
label if the code follows our backporting policy