Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/draganm/manifestor
https://github.com/draganm/manifestor
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/draganm/manifestor
- Owner: draganm
- License: mit
- Created: 2021-05-18T22:33:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-31T10:12:11.000Z (about 1 year ago)
- Last Synced: 2024-06-20T00:33:36.914Z (7 months ago)
- Language: Go
- Size: 43.9 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Manifestor
Small utility to interpolate environment variables into Kubernetes manifests.
Unlike many other templating mechanisms, this utility will never output an invalid YAML.Under the hood, it parses the input yaml files, finds string values, interpolates environment values into them using bash-like interpolation syntax and then re-assembles the resulting YAML(s) that are printed on stdout.
Also, there is an option of executing pre and post interpolation processors in ECMAScript 5.1(+).
## Use
```bash
$ VAR=VALUE manifestor [--processors=] [ ...] | kubectl apply -f -
```## Interpolation format
We are using [envsubst](https://github.com/drone/envsubst) to interpolate environment variables into the string values.
TL;DR;
running
```bash
HOSTNAME="localhost" manifestor ingress.yaml
```where `ingress.yaml` template looks like this:
```yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
name: api
namespace: api
spec:
rules:
- host: ${HOSTNAME}
http:
paths:
- backend:
serviceName: api
servicePort: 3030
path: /api
```will result in the following output:
```yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
name: api
namespace: api
spec:
rules:
- host: localhost
http:
paths:
- backend:
serviceName: api
servicePort: 3030
path: /api
```## Pre and post interpolation processors
String interpolation of environment variables is quite limited.
It won't cater for the cases where a number, boolean value or a whole sub-object needs to be changed, inserted or deleted.
In order to cover those cases, we support executing so-called _processors_.A _processor_ is a JavaScript function that takes an object representing one entity from the manifest and can change it in place.
## Interpolating JS objects directly in yaml
If a more complex object has to be interpolated, any string value starting with `$$JS:` will get evaluated and the result of the evaluation will replace the original string.
e.g.
```yaml
abc: '$$JS: env.GREEN_EGGS_ONLY ? "green eggs" : ["green eggs", "ham"]'
```will evaluate to:
```yaml
abc: green eggs
```
if environment variable `GREEN_EGGS_ONLY` is not set or it has an empty value.In any other case, the result of the evaluation will be:
```yaml
abc:
- green eggs
- ham
```### Naming convention
TODO
### Available functions
TODO
### Available objects
### `env`
`env` contains environment variables passed to the process as key/value object