Python Based KRM Functions #5966
kferrone
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Many years ago, I built grip of scripts for KRM. One in particular is the entrypoint needed for writing krm function in python. I had to rebuild from memory again when I got a new job which mostly got it to where it is now, then back to the back burner. Sorta revived again with my homelab. More years and new job again go by with homelab in dissaray. I finally revive my homelab along with my krm stuff. The other day, I said let's make it open source no matter what state it's in.
All the KRM functions out there are in Go. Why not Python? Why not NodeJS? Maybe Ruby? or Java? So I made a bunch in bash because it was fast and some others in Python cuz it was fresh.
So here is a repo:
https://github.com/kubed-io/krm-py
You can now easily make a one off KRM function in Python and embed it right up in a kustomization project.
https://github.com/kubed-io/krm-py/tree/main/examples/krm
Would be very easy to fork this repo and make your own functions.
Basically just replace these files with your own and change the entrypoint to your own:
https://github.com/kubed-io/krm-py/tree/main/kubed/kustomize
It even works with container images for krm as well.
https://hub.docker.com/r/kubed/krm-py
Serious cool
Then, for the runtime. I don't like installing a bunch of stuff on my machine . . . Go Docker!
Here is some more KRM fun which gives you kubectl, kustomize, krew, helm, and yq/jq.
Here is another repo of great wonder:
https://github.com/kubed-io/krm
Then make a docker compose:
Then a few aliases:
One part I'm particularly proud of, I made sure the
apiVersion
andkind
within the function is actually used. This way you can make a single python project and make a whole library of functions within one module and image. Then the same image/command maybe used over and over with different kinds in the same group.Simply register a new function here: https://github.com/kubed-io/krm-py/blob/99dc214d5597ecf878ea35c56576449ef3044b65/pyproject.toml#L106
Supposedly, according to past me, you are able to run all of the functions as a command from kubectl without using kustomize at all. Something like
kubectl krm -f somefx.yaml
and it'll run. I'm gonna have to read past me's code and try and figure out how he did it.Hoping someone out there thinks this is all pretty sweet. I do plan on being way more active on this. Maybe someone out there is interested enough to kick a few PRs my way. Well, enjoy ya'll.
Beta Was this translation helpful? Give feedback.
All reactions