{"id":16880555,"url":"https://github.com/squaremo/kpt-generator-demo","last_synced_at":"2026-04-11T23:31:46.465Z","repository":{"id":66130730,"uuid":"257009396","full_name":"squaremo/kpt-generator-demo","owner":"squaremo","description":"Demonstration of using a container image to generate Kubernetes configuration, with kpt","archived":false,"fork":false,"pushed_at":"2020-04-19T15:08:43.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-25T05:25:02.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/squaremo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-19T13:42:15.000Z","updated_at":"2020-04-19T15:08:46.000Z","dependencies_parsed_at":"2023-02-24T14:15:43.063Z","dependency_job_id":null,"html_url":"https://github.com/squaremo/kpt-generator-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squaremo%2Fkpt-generator-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squaremo%2Fkpt-generator-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squaremo%2Fkpt-generator-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squaremo%2Fkpt-generator-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/squaremo","download_url":"https://codeload.github.com/squaremo/kpt-generator-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244541980,"owners_count":20469246,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T15:59:13.440Z","updated_at":"2026-04-11T23:31:41.445Z","avatar_url":"https://github.com/squaremo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Demonstration of a reusable kpt package with jk\n\nThis shows:\n\n 1. constructing an image that will run a jk script\n 2. using that image with `kpt fn`\n 3. making it into a package with `kpt pkg` and `kpt cfg`\n\nStarting with the last:\n\n## Using the package from elsewhere\n\nYou can `kpt pkg get` this repository to import it into a\nconfiguration:\n\n    kpt pkg get https://github.com/squaremo/kpt-generator-demo.git ./hello\n\nThe script `image/generate.js` takes two parameter values from the\nfunctionConfig: `namespace` and `image`. I have added a \"setter\" to\nthe Kptfile for both of those, which you can use like this:\n\n    kpt cfg set ./hello image helloworld:v3\n\nthen to re-run the generation step,\n\n    kpt fn run ./hello --fn-path=./hello/fn\n\n... and, if you were genuinely using this as a configuration, you\nwould do `git add ./hello; git commit`.\n\n\u003e **NB** You need to have built the `generate` image, since I can't be\n\u003e bothered pushing it anywhere; once you've got the package as above,\n\u003e `docker build ./hello/image -t generate` should do it.\n\n## How it works\n\nThese sections explain how it's made, and assume the repo itself as\nthe working directory.\n\n## Constructing an image\n\nThe directory `image/` contains a [`jk`](https://github.com/jkcfg/jk)\nscript, and a Dockerfile which builds it into a container image.\n\nThe configuration refers to an image called `generate`; to build the\nimage locally (it's not pushed anywhere):\n\n    docker build ./image -t generate\n\nThe script itself is simple: it takes the\n[`functionConfig`][kpt-fn-spec] from the input, and uses its values to\nconstruct a deployment and a service. It ignores the rest of the\ninput.\n\n### Using the image with `kpt fn`\n\nTo run the image with `kpt fn`, you need some kind of input (since\n`kpt fn run` will just exit if there's no file or stdin input). The\nfiles in `instance/` are the result of running the script with the\nconfig in `fn/configmap_generate.yaml`; i.e.,\n\n    kpt fn run --fn-path=./fn ./instance\n\nRun like this, the files output should be the same as those already\nthere. You could also run\n\n    kpt fn run --image=generate ./instance\n\nto get the same result.\n\n[kpt-fn-spec]: https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/functions-spec.md\n\n### Parameterising the generated output\n\nSince the files in instance/ are generated by the image, I don't want\nto target them with setters, but rather the input to the generation;\ni.e., the functionConfig in `fn/`.\n\nTo add a setter for `namespace`, say, in theory you would do this:\n\n    kpt cfg create-setter . namespace --field data.namespace default\n\n.. which is supposed to target just the fields with that partial path,\n`data.namespace` (i.e., that in `fn/configmap_generate.yaml`); but, it\nappears to target anything with the value given, regardless of the\npath, and ends up being applied to the files in instance/ -- not what\nI want.\n\nI worked around this by giving it a different value in the files I\ndidn't want it to target, then running the `kpt cfg` command, then\nregenerating the files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquaremo%2Fkpt-generator-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquaremo%2Fkpt-generator-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquaremo%2Fkpt-generator-demo/lists"}