Skip to content

Conversation

esosaoh
Copy link
Contributor

@esosaoh esosaoh commented Sep 1, 2025

Description

Fix kubewarden/policy-sdk-js#190

Test

To test this pull request, you can run the following commands:

Additional Information

Tradeoff

Potential improvement

@esosaoh esosaoh requested a review from a team as a code owner September 1, 2025 04:29
@github-project-automation github-project-automation bot moved this to Pending review in Kubewarden Sep 1, 2025
Copy link

netlify bot commented Sep 1, 2025

Deploy Preview for docs-kubewarden-io ready!

Name Link
🔨 Latest commit 5fee132
🔍 Latest deploy log https://app.netlify.com/projects/docs-kubewarden-io/deploys/68edc42e777b1900089bfd51
😎 Deploy Preview https://deploy-preview-663--docs-kubewarden-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@jhkrug jhkrug added area/documentation Improvements or additions to documentation and removed area/documentation Improvements or additions to documentation labels Sep 3, 2025
Copy link
Contributor

@jhkrug jhkrug left a 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.

esosaoh and others added 5 commits September 3, 2025 22:21
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]>
@esosaoh
Copy link
Contributor Author

esosaoh commented Sep 18, 2025

done! @jhkrug

@jhkrug jhkrug moved this from In Progress to Pending review in Kubewarden Sep 19, 2025
Copy link
Contributor

@jhkrug jhkrug left a 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!

Copy link
Contributor

@jhkrug jhkrug left a 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.

## 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`.

Copy link
Contributor

@jhkrug jhkrug Sep 19, 2025

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=]

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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:

Copy link
Contributor Author

@esosaoh esosaoh Oct 14, 2025

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

@jhkrug jhkrug moved this from Pending review to In Progress in Kubewarden Sep 19, 2025
esosaoh and others added 14 commits September 21, 2025 21:34
@jvanz jvanz requested review from jhkrug and viccuad September 24, 2025 12:37
@jvanz jvanz moved this from In Progress to Pending review in Kubewarden Sep 24, 2025
@viccuad viccuad moved this from Pending review to In Progress in Kubewarden Sep 24, 2025
@viccuad viccuad moved this from In Progress to Pending review in Kubewarden Sep 29, 2025
@viccuad viccuad moved this from Pending review to In Progress in Kubewarden Sep 29, 2025
Copy link
Member

@flavio flavio left a 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.
Copy link
Member

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.
Copy link
Member

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`.

Copy link
Member

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:

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.
Copy link
Member

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.
Copy link
Member

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

@jhkrug
Copy link
Contributor

jhkrug commented Oct 15, 2025

Noting that the documented examples do not work, presumably as using kwctl 1.29 and waiting for 1.30. Or something else?:

[~/tmp/kw-ts-test/js-policy-template][main *|u=]
⸘ pwd
/home/jhk/tmp/kw-ts-test/js-policy-template
[~/tmp/kw-ts-test/js-policy-template][main *|u=]
⸘ npm install kubewarden-policy-sdk

up to date, audited 400 packages in 983ms

58 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[~/tmp/kw-ts-test/js-policy-template][main *|u=]
⸘ ls -l node_modules/kubewarden-policy-sdk/plugin/javy-plugin-kubewarden.wasm
-rw-r--r-- 1 jhk jhk 1146510 Oct 15 13:59 node_modules/kubewarden-policy-sdk/plugin/javy-plugin-kubewarden.wasm
[~/tmp/kw-ts-test/js-policy-template][main *|u=]
⸘ cat package.json
{
	"name": "kubewarden-js-policy-template",
	"version": "0.1.0",
	"description": "jhk docs test",
	"main": "src/index.js",
	"scripts": {
		"build": "npx webpack --config webpack.config.cjs",
		"test": "bats e2e.bats",
		"format": "prettier --write .",
		"format:check": "prettier --check ."
	},
	"devDependencies": {
		"@types/jest": "^30.0.0",
		"@types/node": "^24.2.0",
		"jest": "^30.0.5",
		"kubernetes-types": "^1.30.0",
		"prettier": "^3.6.2",
		"ts-jest": "^29.4.1",
		"ts-loader": "^9.5.2",
		"typescript": "^5.8.3",
		"webpack": "^5.x.x",
		"webpack-cli": "^5.1.4"
	},
	"keywords": [
		"kubewarden",
		"policy",
		"kubernetes",
		"wasm",
		"javascript"
	],
	"author": "Kubewarden",
	"repository": {
		"type": "git",
		"url": "https://github.com/jhkrug/js-policy-template.git"
	},
	"bugs": {
		"url": "https://github.com/jhkrug/js-policy-template/issues"
	},
	"dependencies": {
		"kubewarden-policy-sdk": "^0.1.1"
	}
}
[~/tmp/kw-ts-test/js-policy-template][main *|u=]
‽ make all
npm install

up to date, audited 400 packages in 833ms

58 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 [compared for emit] [minimized] (name: main)
asset types.d.ts 430 bytes [compared for emit]
asset index.d.ts 11 bytes [compared for emit]
./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 1420 ms
npm install

up to date, audited 400 packages in 979ms

58 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
[~/tmp/kw-ts-test/js-policy-template][main *|u=]
⸘ make e2e
npm install

up to date, audited 400 packages in 840ms

58 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 [compared for emit] [minimized] (name: main)
asset types.d.ts 430 bytes [compared for emit]
asset index.d.ts 11 bytes [compared for emit]
./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 1361 ms
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
[~/tmp/kw-ts-test/js-policy-template][main *|u=]
⸘

@jhkrug
Copy link
Contributor

jhkrug commented Oct 16, 2025

A bit more. I tried this with kwctl 1.30.0-beta2 and javy 7.0.1

Still have the error from javy:

Error: Could not process plugin: Using unsupported legacy plugin API

I don't think the make command is getting as far as using kwctl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/documentation Improvements or additions to documentation

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

docs: Add tutorial for policy-sdk-js

6 participants