{"id":20282405,"url":"https://github.com/den-is/ktempl","last_synced_at":"2025-04-11T08:01:48.387Z","repository":{"id":87679898,"uuid":"264417411","full_name":"den-is/ktempl","owner":"den-is","description":"ktempl - renders configuration templates using node data from a Kubernetes cluster","archived":false,"fork":false,"pushed_at":"2023-03-27T14:47:39.000Z","size":95,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T05:36:40.200Z","etag":null,"topics":["configuration-management","devops","devops-tools","go","kubernetes","templates"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/den-is.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-16T10:59:56.000Z","updated_at":"2023-05-02T14:15:28.000Z","dependencies_parsed_at":"2023-04-25T08:47:52.199Z","dependency_job_id":null,"html_url":"https://github.com/den-is/ktempl","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/den-is%2Fktempl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/den-is%2Fktempl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/den-is%2Fktempl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/den-is%2Fktempl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/den-is","download_url":"https://codeload.github.com/den-is/ktempl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248360159,"owners_count":21090659,"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":["configuration-management","devops","devops-tools","go","kubernetes","templates"],"created_at":"2024-11-14T14:09:14.382Z","updated_at":"2025-04-11T08:01:48.345Z","avatar_url":"https://github.com/den-is.png","language":"Go","readme":"# ktempl - render Go templates with Nodes data from a Kubernetes\n\n:warning: **Early stage of development! Use with caution! No warranties provided.** :construction:\n\nktempl renders template files formatted using Go [template][gotemplate] with data returned from a Kubernetes cluster.\n\nPrimary data for ktempl is a **list of nodes** returned by a query to a Kubernetes.\nBy default, ktempl fetches all nodes from the Kubernetes cluster.\nYou can limit/filter nodes list using `-l` and available kubernetes key=value labels.\nAlso you get list of nodes that host specific pods only by providing `-p` and `-l` to select specific pods.\n\nSecondary data is a `key=value` data provided by user using `--set` arguments.\n\nOptionally, after successful render, ktemp might execute command provided by user.\n\nInitial motivation was to write piece of software which can be used as a glue between not flexible services, without built-in service discovery capabilities, and Kubernetes.\nOne such example is the Varnish HTTP accelerator, where you need to pass backend servers configuration, and reload Varnish daemon if configuration changes.\n\nInspired by many configuration management frameworks which operate templates to generate configs, e.g., [Helm][helm], [consul-template][consultemplate], [Ansible][ansibletemplate], [Puppet][puppettemplate], etc.\n\n## Prerequisites\n\nYou should have a `kubeconfig` file with proper authentication and context details supplied.\n\nUser listed in the `kubeconfig` should be allowed to list nodes and pods.\n\nAs a minimum user should be allowed to list either nodes or pods.\n\nDefault kubeconfig location `~/.kube/config`\n\nMore details on how to obtain that file can be found [here][kubeconfigdoc].\n\n## Install\n\nDownload from the [releases][releasespage] page. Example setup on linux machine:\n\n```sh\ncurl -OL https://github.com/den-is/ktempl/releases/download/0.0.1/ktempl_0.0.1_`uname -s`_x86_64.tar.gz \u0026\u0026\\\ntar xzvf ktempl_0.0.1_`uname -s`_x86_64.tar.gz \u0026\u0026\\\ncp ktempl_0.0.1_`uname -s`_x86_64/ktempl /usr/local/bin\n```\n\nCompile it yourself. Minimum recommended Go version is 1.17+.\n\n```sh\ngo get -u github.com/den-is/ktempl\n```\n\n## Template language and scope variables\n\nTemplates are formated using [Go template language][gotemplate] and support [Sprig template library][sprig].\n\nTwo main variables are passed to template for rendering:\n\n- `.Nodes` - list of nodes returned by Kubernetes\n- `.Values` - dictionary of key=values passed to ktempl using `--set` in the terminal or `values:` in the config file.\n\nEach node in `.Nodes` has next fields\n\n- `.mynode.Name`\n- `.mynode.InternalIP`\n- `.mynode.Annotations`\n- `.mynode.Labels`\n\nExample template file\n\n```jinja\n# Welcome to {{ .Values.title  | lower | repeat 5 }} \u003c\u003c\u003c\u003c\n{{- range $i, $n := .Nodes }}\nNode {{$n.Name }} has {{ $n.InternalIP }} IP and port {{ $.Values.port }}\n{{- end }}\n```\n\n## Example usage\n\nMore examples [here](/examples/)\n\n```sh\n# query nodes with a specific label\nktempl -l disk=ssd -t myexamle.tpl\n\n# query pods with a specific label\nktempl -p -l app=myapp1 -t myexamle.tpl\n\n# extended example\nktempl -l app=stagingapps -t example.tpl -o output.conf --set port=32456 --exec=\"touch success_exec.txt\"\n```\n\n## Config file\n\nOptionally you can supply ktempl with a config file.\nThe default is `config.yaml` in the same directory as binary.\nOr `/etc/ktempl/config.yaml`.\nOr whatever you supply with `-c` command-line option.\n\n## List of available configuration options\n\n| Config file settings  |         CLI flags         | Description                                                              |\n| ----------------------| --------------------------| ------------------------------------------------------------------------ |\n| `kubeconfig`          | `-k, --kubeconfig`        | Path to kubeconfig                                                       |\n| `pods`                | `-p, --pods`              | Query pods and get nodes they are running on                             |\n| `namespace`           | `-n, --namespace`         | Kubernetes namespace where to look Pods for. Used with `-p`              |\n| `selector`            | `-l, --selector`          | Kubernetes [label selectors][labelselectors] string                      |\n| `template`            | `-t, --template`          | Path to template                                                         |\n| `output`              | `-o, --output`            | Path where to put rendered results. default stdout                       |\n| `permissions`         | `N/A`                     | Output file permissions. default 0644. should be in 4 digit format!      |\n| `set`                 | `--set`                   | Additional key=values passed to template rendering engine                |\n| `exec`                | `-e, --exec`              | Command to execute after successful template render                      |\n| `log.file`            | `--log-file`              | Path to log file. Allowed values `disabled`, `stdout`, `stderr`, `path_to_log_file_dst`. Default `disabled`. |\n| `log.level`           | `--log-level`             | Minimum log message level to log. Default `info`. Available levels by hierarchy: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `panic` |\n| `N/A`                 | `-c, --config`            | Path to ktempl config file                                               |\n| `daemon`              | `-d, --daemon`            | Run ktempl in service mode, rather than singleshot                       |\n| `interval`            | `-i, --interval`          | Interval between polls. default 15s. Valid time units are \"s\", \"m\", \"h\". |\n| `retries`             | `N/A`                     | _NOT YET IMPLEMENTED_ Number of retries to fetch data from Kubernetes    |\n| `timeout`             | `N/A`                     | _NOT YET IMPLEMENTED_ ktempl operations timeout                          |\n\n### Contact\n\nDenis Iskandarov denis@cloudboom.io\n\n[gotemplate]: https://golang.org/pkg/text/template/\n[sprig]: http://masterminds.github.io/sprig/\n[consultemplate]: https://github.com/hashicorp/consul-template\n[helm]: https://helm.sh/\n[ansibletemplate]: https://docs.ansible.com/ansible/latest/modules/template_module.html\n[puppettemplate]: https://puppet.com/docs/puppet/latest/lang_template.html\n[kubeconfigdoc]: https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/\n[labelselectors]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/\n[releasespage]: https://github.com/den-is/ktempl/releases\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fden-is%2Fktempl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fden-is%2Fktempl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fden-is%2Fktempl/lists"}