kptdev / kpt

Automate Kubernetes Configuration Editing
https://kpt.dev
Apache License 2.0
1.69k stars 227 forks source link

Starlark function generator #2392

Open karlkfi opened 3 years ago

karlkfi commented 3 years ago

I like the way Starlark functions are really easy to write and very short (< 10 lines of code).

I want to be able to publish functions (to the kpt-function-catalog) written in Starlark with minimal effort.

I also need to be able to provide input variables to Starlark functions, so they can be used as validators & mutators.

Since almost all the code and Dockerfile would be boilerplate, it seems like a generator functions could be created, like:

kpt fn generate <name> --lang=starlark

This would generate the Dockerfile and a placeholder file for the starlark code, along with a script or makefile for building and publishing the image.

mengqiy commented 3 years ago

@karlkfi Why do you need a Dockerfile here? It sounds like you want to have the starlark function with a baked-in starlark script and then publish it to the catalog?

The idea of starlark function is that we provide the image and user provide the functionConfig. Publishing the functionConfig of starlark function is equivalent to publishing a function, since that's the only thing that changes. We can potentially have a separate index for starlark functionConfig.

@droot @karlkfi WDYT?

karlkfi commented 3 years ago

Why do you need a Dockerfile here? It sounds like you want to have the starlark function with a baked-in starlark script and then publish it to the catalog?

Yes

Publishing the functionConfig of starlark function is equivalent to publishing a function

No.

Publishing a function as a yaml file in a git repo is NOT equivalent to publishing it as a docker image. With a docker image you can include the usage of the function in any kptfile pipeline. With a yaml file you force the user to kpt pkg get a package with your yaml file.

If you can make kptfile reference a yaml file in a git repo without needing to publish it as an image, then maybe they would be more equivalent. That would certainly be easier. Otherwise they need to be published as container images, right?

droot commented 3 years ago

I agree, having a light weight skylark sdk that scaffolds the Dockerfile and function script and some make helpers to dev and publish the starlark script as function makes sense. It will be sort of a parallel to our typescript and Go SDKs for writing functions.

karlkfi commented 3 years ago

Another option would be to be able to reference a function by URL, instead of just container image. Then I could "publish" a starlark function just by hosting it in a github repo.

The downside is that it would be effectively as secure as sudo curl|bash (not that a container published by someone else is much better).