{"id":20365851,"url":"https://github.com/cycoresystems/kubetemplate","last_synced_at":"2025-07-11T01:35:20.590Z","repository":{"id":45142937,"uuid":"184115454","full_name":"CyCoreSystems/kubetemplate","owner":"CyCoreSystems","description":"Kubernetes application configuration templating engine","archived":false,"fork":false,"pushed_at":"2022-01-05T16:27:55.000Z","size":54,"stargazers_count":2,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T17:12:50.245Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CyCoreSystems.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-29T17:36:20.000Z","updated_at":"2022-01-05T16:22:57.000Z","dependencies_parsed_at":"2022-07-25T23:33:16.112Z","dependency_job_id":null,"html_url":"https://github.com/CyCoreSystems/kubetemplate","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyCoreSystems%2Fkubetemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyCoreSystems%2Fkubetemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyCoreSystems%2Fkubetemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyCoreSystems%2Fkubetemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CyCoreSystems","download_url":"https://codeload.github.com/CyCoreSystems/kubetemplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248519473,"owners_count":21117757,"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-11-15T00:20:35.222Z","updated_at":"2025-04-12T04:50:52.935Z","avatar_url":"https://github.com/CyCoreSystems.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KubeTemplate\n\nKubeTemplate (package `kubetemplate`) is a library to facilitate the\nconstruction of reactive application configurations when running inside\nKubernetes.\n\nIt provides a common Go-based templating engine to construct application\nconfiguration files using a number of kubernetes resources as sources.\n\n## Usage\n\nA templating engine can be used on any number of templates, but before calling\n`Render()` on a template, you should run that template through a `Learn()`\ncycle.\n\nThus, the usual process is to run each template through a `Learn()` whenever it\nis added or changes, and then call `Render()` any number of times.\nNote that `Learn()` takes out a lock on the entire engine, so you should not\nattempt to run it concurrently.\n\nThe network portion of this tool relies on a netdiscover instance.\nSee [NetDiscover](https://github.com/CyCoreSystems/netdiscover) for more\ninformation.\nAt a minimum, just create one with `discover.NewDiscoverer()`.\n\n## Templates\n\nValues for the templates may come from a number of sources:\n\n  - [ConfigMap](#configmap-and-secret) / [Secret](#configmap-and-secret)\n  - [Environment Variables](#environment-variables)\n  - [Service](#service)\n  - [ServiceIP](#serviceip)\n  - [Endpoints](#endpoints) (of a Service)\n  - [EndpointIPs](#endpoint-ips) (of a Service)\n  - [Network](#network-data)\n\n### ConfigMap and Secret\n\nTo obtain ConfigMap or Secret entries, KubeTemplate will use the Kubernetes API to\nattempt to pull in the ConfigMap/Secret and key requested. \n\n**Format**:  `{{.ConfigMap \"\u003cname\u003e\" \"\u003cnamespace\u003e\" \"\u003ckey\u003e\"}}` \n\n**Format**:  `{{.Secret \"\u003cname\u003e\" \"\u003cnamespace\u003e\" \"\u003ckey\u003e\"}}` \n\nThe provided namespace _may_ be `\"\"` if both the ConfigMap/Secret is in the same\nnamespace as the Pod _and_ the `POD_NAMESPACE` environment variable is properly\nset.\n\nThe ConfigMap/Secret will be monitored by the engine, and if it is updated, the\nconfiguration files will be regenerated, and a reload will be performed.\n\nNote that this will likely require an RBAC entry to allow the `ServiceAccount`\nunder which the engine is running to access the referenced ConfigMap.\n\n**NOTE**: it is generally easier to use the standard kubernetes Pod methods to\ntranslate ConfigMap and Secret values to environment variables.  However, doing\nso does not currently result in changes to those referent ConfigMaps and Secrets\nbeing propagated to running applications.  Therefore, the choice between using\nthese dynamic references and the native kubernetes environment variable bindings\nis left to the user.\n\n\n### Environment Variables\n\n**Format**: `{{.Env \"\u003cname\u003e\"}}`\n\nIt is useful to note that IP addresses of services within the same namespace\nwill automatically be populated as environment variables by kubernetes.  These\nwill be of the form `\u003cSERVICE_NAME\u003e_SERVICE_HOST`.  For instance, the IP of a\nservice named \"kamailio\" will be stored in the environment variable\n`KAMAILIO_SERVICE_HOST`.  This is a normal, default feature of all kubernetes\ncontainers.  See the [documentation](https://kubernetes.io/docs/concepts/services-networking/service/) for more information.\n\n### Service\n\nData from a kubernetes Service may be obtained using the Kubernetes API.\n\n**Format**: `{{.Service \"\u003cname\u003e\" \"\u003cnamespace\u003e]\"}}`\n\nThe provided namespace _may_ be `\"\"` if both the Service is in the same\nnamespace as the Pod _and_ the `POD_NAMESPACE` environment variable is properly\nset.\n\nThe value returned here is the Kubernetes\n[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#service-v1-core).\nKeep in mind that Go uses PascalCase for the fields, so \"clusterIP\" becomes\n\"ClusterIP\".\n\nFor example, to get the ClusterIP of a service named \"kamailio\" in the \"voip\"\nnamespace:\n\n`{{ with .Service \"kamailio\" \"voip\"}}{{.Spec.ClusterIP}}{{end}}`\n\nNote that the IP address of a service within the same namespace can be obtained\nmore simply by environment variable, as described above.\n\n### ServiceIP\n\nSince the most common reason to probe a service is to retrieve its ClusterIP, we\nhave also included a macro which does just that.\n\n**Format**: `{{.ServiceIP \"\u003cname\u003e\" \"\u003cnamespace\u003e]\"}}`\n\nThis works as Service, but instead of returning a structure, it just returns the\nClusterIP of the Service, as a string.\n\n\n### Endpoints\n\nData from the kubernetes Endpoints of a Service may be obtained using the\nKubernetes API.\n\n**Format**: `{{.Service \"\u003cname\u003e\" \"\u003cnamespace\u003e\"}}`\n\nThe provided namespace _may_ be `\"\"` if both the Service is in the same\nnamespace as the Pod _and_ the `POD_NAMESPACE` environment variable is properly\nset.\n\nThe value returned is the Kubernetes [Endpoints](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#endpoints-v1-core).\n\nThe Endpoints will be monitored by the engine, and if it is updated, the\nreload channel will be signaled.\n\nThis is usually used to obtain the dynamic set of proxy servers, but since the\nmost common reason to do this is to obtain the set of IPs for endpoints of a\nservice, we provide a second helper function just for that.\n\n### Endpoint IPs\n\nOne of the most common pieces of dynamic data to retrieve is the set of IPs for\nthe endpoints of a service.  Therefore, to simplify the relatively tedious\niteration of these directly from the Endpoints spec, we provide the EndpointIPs\nmacro, which returns the list of IPs of all Endpoints of the given service\nname.\n\n**Format**: `{{.EndpointIPs \"\u003cname\u003e\" \"\u003cnamespace\u003e\"}}`\n\nThe provided namespace _may_ be `\"\"` if both the Service is in the same\nnamespace as the Pod _and_ the `POD_NAMESPACE` environment variable is properly\nset.\n\nUsing this is then easy.  For example, to create a PJSIP endpoint from the set\nof proxy servers running as the \"kamailio\" service:\n\n`pjsip.d/proxies.conf`:\n\n```ini\n[proxies]\ntype=endpoint\ntransport=k8s-internal-ipv4-external-media\ncontext=from-proxies\ndisallow=all\nallow=ulaw\naors=proxies\nrtp_symmetric=yes\n\n[proxies]\ntype=aor\n{{range .EndpointIPs \"kamailio\"}}\ncontact=sip:{{.}}\n{{end}}\n\n[proxies]\ntype=identify\nendpoint=proxies\n{{range .EndpointIPs \"kamailio\"}}\nmatch={{.}}\n{{end}}\n\n[proxies]\ntype=acl\ndeny=0.0.0.0/0.0.0.0\n{{range .EndpointIPs \"kamailio\"}}\npermit={{.}}\n{{end}}\n```\n\nThe Endpoints IPs will be monitored by the engine, and if they are updated, the\nconfiguration files will be regenerated, and a reload will be performed.\n\n\n### Network data\n\nThe IP addresses for the running Pod are made available, as well.\n\n**Format**: `{{.Network \"\u003ckind\u003e\"}}`\n\nThe available data kinds correspond to the data available from\n[NetDiscover](https://github.com/CyCoreSystems/netdiscover):\n\n  - \"hostname\"\n  - \"privatev4\"\n  - \"publicv4\"\n  - \"publicv6\"\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycoresystems%2Fkubetemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcycoresystems%2Fkubetemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycoresystems%2Fkubetemplate/lists"}