kpt icon indicating copy to clipboard operation
kpt copied to clipboard

add wasm runtimes (embedded and nodejs) in kpt

Open mengqiy opened this issue 3 years ago • 0 comments

This PR introduces 2 commands: kpt alpha wasm push and kpt alpha wasm pull:

  • kpt alpha wasm push [path-to-local-wasm-file] [desired-OCI-image-name]
  • kpt alpha wasm pull [OCI-image-name] [desired-local-path-to-store-the-wasm-file]

This PR added 2 wasm runtimes (one embedded wasmtime and node.js) in kpt:

  • It is not a WASI runtime, since golang doesn't have a great support to compile go program to WASI and most of our KRM functions are written in go.
  • It requires the wasm to register a js function called processResourceList in the globals.

To use it in Kptfile:

apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
  name: app
pipeline:
  mutators:
    - wasm: gcr.io/mengqiy-playground/set-namespace:v1.2.4 # Note: wasm is the keyword
      configMap:
        namespace: staging

Then run kpt fn render --allow-wasm

TODO: add performance info

This PR requires go 1.18+. I have cherry picked the 2 commits from https://github.com/GoogleContainerTools/kpt/pull/3447.

mengqiy avatar Aug 09 '22 16:08 mengqiy

Some small nits, but this is pretty close I think.

I think sending the go 1.19 and ioutil -> os changes separately would help make this much more reviewable.

justinsb avatar Aug 10 '22 15:08 justinsb

I think sending the go 1.19 and ioutil -> os changes separately would help make this much more reviewable.

These changes are really from https://github.com/GoogleContainerTools/kpt/pull/3447. I cherry picked the commits to make CI happy.

This PR requires CGO, but it seems we cross compilation doesn't work nicely with CGO. To workaround it, We may need to build it in container for darwin and windows. @justinsb Any suggestions or prior arts in other k8s projects?

mengqiy avatar Aug 10 '22 18:08 mengqiy

I just realized that a few comments have not been addressed. I missed them until I resolved other comments. I will resolve them tomorrow. Meanwhile the PR is mostly ready for another round of review.

I have move part of porch/pkg/oci package to pkg/oci. If you think I should split it out to its own PR. Please let me know. It should not be hard to do it.

mengqiy avatar Aug 17 '22 07:08 mengqiy

Two small things, but lgtm!

justinsb avatar Aug 17 '22 21:08 justinsb