-
Notifications
You must be signed in to change notification settings - Fork 29
feat(typescript): add tutorial for writing policies with typescript/javascript #663
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
base: main
Are you sure you want to change the base?
Conversation
…avascript Signed-off-by: Esosa Ohangbon <[email protected]>
✅ Deploy Preview for docs-kubewarden-io ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
A minor few suggestions for consideration. From a few sources. I'll have another run through when they have been incorporated. Thank you. Looking good.
Co-authored-by: Daria Vladykina <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: Daria Vladykina <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: Daria Vladykina <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: Daria Vladykina <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: Daria Vladykina <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
done! @jhkrug |
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 @esosaoh. I think this is the last set of changes. Just all for consistency and taking note of some terminology suggestions from the checkers. Nearly there. Thanks!
docs/tutorials/writing-policies/typescript/01-intro-typescript.md
Outdated
Show resolved
Hide resolved
docs/tutorials/writing-policies/typescript/01-intro-typescript.md
Outdated
Show resolved
Hide resolved
docs/tutorials/writing-policies/typescript/01-intro-typescript.md
Outdated
Show resolved
Hide resolved
docs/tutorials/writing-policies/typescript/01-intro-typescript.md
Outdated
Show resolved
Hide resolved
docs/tutorials/writing-policies/typescript/01-intro-typescript.md
Outdated
Show resolved
Hide resolved
docs/tutorials/writing-policies/typescript/03-policy-settings.md
Outdated
Show resolved
Hide resolved
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 can't get the tutorial to work at the moment.
docs/tutorials/writing-policies/typescript/01-intro-typescript.md
Outdated
Show resolved
Hide resolved
## Testing | ||
|
||
Provided the necessary tools are in place, the `make all` command builds the `annotated-policy.wasm` target. The command `make e2e` runs tests using `bats` with `kwctl`. | ||
|
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.
When trying make all
I am unsuccessful. Any suggestions?
Using
[~/projects/suse/kubewarden/testing/test-js-policy][main|u=]
‽ node --version
v24.0.1
[~/projects/suse/kubewarden/testing/test-js-policy][main|u=]
‽ javy --version
javy 6.0.0
[~/projects/suse/kubewarden/testing/test-js-policy][main|u=]
‽ kwctl --version
kwctl 1.28.1
Use the `info` command to display system information.
[~/projects/suse/kubewarden/testing/test-js-policy][main|u=]
‽ bats --version
Bats 1.12.0
[~/projects/suse/kubewarden/testing/test-js-policy][main|u=]
‽
I get:
⸘ git remote -v
origin [email protected]:jhkrug/test-js-policy.git (fetch)
origin [email protected]:jhkrug/test-js-policy.git (push)
[~/projects/suse/kubewarden/testing/test-js-policy][main|u=]
⸘ make clean
npm cache clean --force
npm warn using --force Recommended protections disabled.
rm -f policy.wasm annotated-policy.wasm
rm -rf dist dist-ts node_modules package-lock.json
[~/projects/suse/kubewarden/testing/test-js-policy][main *|u=]
‽ make all
npm install
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
added 399 packages, and audited 400 packages in 14s
59 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
npm run build
> [email protected] build
> npx webpack --config webpack.config.cjs
asset bundled.js 5.52 KiB [emitted] [minimized] (name: main)
asset types.d.ts 430 bytes [emitted]
asset index.d.ts 11 bytes [emitted]
./src/index.ts 3.84 KiB [built] [code generated]
./node_modules/kubewarden-policy-sdk/dist/bundle.js 3.85 KiB [built] [code generated]
webpack 5.101.3 compiled successfully in 1530 ms
npm install
added 1 package, and audited 401 packages in 996ms
59 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
javy build dist/bundled.js -C plugin=node_modules/kubewarden-policy-sdk/plugin/javy-plugin-kubewarden.wasm -o policy.wasm
Error: Could not process plugin: Using unsupported legacy plugin API
make: *** [Makefile:16: policy.wasm] Error 1
[~/projects/suse/kubewarden/testing/test-js-policy][main|u=]
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.
@esosaoh can you please check and list the needed changes for this to work?
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 Javy team has provided documentation with a steps to migrate to v2.0.0 of the javy-plugin-api
: https://crates.io/crates/javy-plugin-api
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.
Everything is going to be sorted out once:
- update javy plugin policy-sdk-js#234 is merged
- a new version of kwctl is tagged to include some fixes
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.
@flavio we need to tag a new version of the sdk when kwctl 1.30
is released
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Co-authored-by: John Krug <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
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.
LGTM, I've left some minor comments.
I think we have to wait for kwctl 1.30 to be out before publishing this doc
- **No Node.js APIs**: Standard Node.js modules like `fs`, `http`, or `crypto` aren't available. | ||
- **Limited standard library**: Only core JavaScript features and explicitly enabled APIs are accessible. | ||
- **Single-threaded execution**: No support for Web Workers or multi-threading. | ||
- **STDOUT restrictions**: Writing to STDOUT breaks policies - use STDERR for logging instead. |
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 not really a Javy limitation, but rather something that we impose to all our WASI policies. Let's see if we can mention that somewhere else, to avoid confusion
|
||
Writing Kubewarden policies requires: | ||
|
||
- **Node.js**: Version 18 or higher. |
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 unordered list is structured in this way: <name of the dep> - <why do we need it>
.
Can we sort that out also for this outlier? The version remark is already provided below, inside of the warning box.
## Testing | ||
|
||
Provided the necessary tools are in place, the `make all` command builds the `annotated-policy.wasm` target. The command `make e2e` runs tests using `bats` with `kwctl`. | ||
|
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.
Everything is going to be sorted out once:
- update javy plugin policy-sdk-js#234 is merged
- a new version of kwctl is tagged to include some fixes
Recall, you need these tools on your development machine: | ||
|
||
- **`bats`**: Used to write the tests and automate their execution. | ||
- **`kwctl`**: CLI tool provided by Kubewarden to run its policies outside of Kubernetes, among other actions. It's covered in [the testing policies section](../../testing-policies/index.md) of the documentation. |
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.
reminder: here we will have to tell the user they have to use kwctl 1.30 or later
|
||
- **Node.js**: Version 18 or higher with npm for dependency management. | ||
- [**`bats`**](https://github.com/bats-core/bats-core): Used to write the tests and automate their execution. | ||
- [**`kwctl`**](https://github.com/kubewarden/kwctl/releases): CLI tool provided by Kubewarden to run its policies outside of Kubernetes, among other actions. It's covered in [the testing policies section](../../testing-policies/index.md) of the documentation. |
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.
reminder: here we will have to tell the user they have to use kwctl 1.30 or later
Co-authored-by: Flavio Castelli <[email protected]> Signed-off-by: Esosa Ohangbon <[email protected]>
Noting that the documented examples do not work, presumably as using kwctl 1.29 and waiting for 1.30. Or something else?:
|
A bit more. I tried this with kwctl Still have the error from javy:
I don't think the make command is getting as far as using kwctl |
Description
Fix kubewarden/policy-sdk-js#190
Test
To test this pull request, you can run the following commands:
Additional Information
Tradeoff
Potential improvement