From ae02d79e5129bd03d1f1871fdc99eed85ce919b8 Mon Sep 17 00:00:00 2001 From: Charles Thomas Date: Mon, 27 Jun 2022 15:15:42 -0400 Subject: [PATCH] docs: add `bin/renderlocal` to README w/examples - examples should be copy/paste-able from the root of the repo - included: - single and multiple `--env` arguments - with and without `--out` option --- README.md | 57 +++++++++++++++++++++++++ package-lock.json | 26 ++++++++++- test/example/alternate-greeting-cm.yaml | 8 ++++ test/example/hello-cm.yaml | 8 ++++ test/example/hello-mtp.yaml | 28 ++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 test/example/alternate-greeting-cm.yaml create mode 100644 test/example/hello-cm.yaml create mode 100644 test/example/hello-mtp.yaml diff --git a/README.md b/README.md index 04842a1..4d283cd 100644 --- a/README.md +++ b/README.md @@ -608,3 +608,60 @@ before enabling impersonation, any user on the cluster that is allowed to create razeedeploy resources will be able to impersonate any other user. Once the ImpersonationWebhook controller is installed and all necessary config and authorizations in place, impersonation can be safely enabled in the `razeedeploy-config` configmap. + +## Local Testing with `bin/renderlocal` + +`bin/renderlocal` can be used to see what the resources generated by a +MustacheTemplate would look like. + +`bin/renderlocal` arguments: + +- `--mtp` a path to the template you want to render. +- `--env` a path to a file containing `ConfigMaps`, `Secrets`, or other + resources used to render the template. Any number of `--env` files can be + added; at least one is required. +- `--out` if provided, the path to write the resulting rendered resources + [OPTIONAL] + +### Example + +```shell +bin/renderlocal --mtp test/example/hello-mtp.yaml --env test/example/hello-cm.yaml + +{..."failed to get env: {\"name\":\"greeting\",... # expected warning +kind: ConfigMap +apiVersion: v1 +metadata: + name: result + namespace: default +data: + result: hello, Razee! +``` + +```shell +bin/renderlocal --mtp test/example/hello-mtp.yaml \ +--env test/example/hello-cm.yaml --env test/example/alternate-greeting-cm.yaml + +kind: ConfigMap +apiVersion: v1 +metadata: + name: result + namespace: default +data: + result: howdy, Razee! +``` + +```shell +bin/renderlocal --mtp test/example/hello-mtp.yaml \ +--env test/example/hello-cm.yaml --env test/example/alternate-greeting-cm.yaml \ +--out /tmp/output.yaml \ +&& cat /tmp/output.yaml + +kind: ConfigMap +apiVersion: v1 +metadata: + name: result + namespace: default +data: + result: howdy, Razee! +``` diff --git a/package-lock.json b/package-lock.json index da2df32..0e2a04d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,11 +14,13 @@ "handlebars": "^4.7.7", "js-yaml": "^4.1.0", "mustache": "^4.2.0", + "nopt": "^5.0.0", "object-path": "^0.11.8", "pino": "^7.11.0" }, "bin": { - "mustachetemplate": "bin/mustachetemplate" + "mustachetemplate": "bin/mustachetemplate", + "renderlocal": "bin/renderlocal" }, "devDependencies": { "chai": "^4.3.6", @@ -3741,6 +3743,20 @@ "integrity": "sha512-zR6HoT6LrLCRBwukmrVbHv0EpEQjksO6GmFcZQQuCAy139BEsoVKPYnf3jongYW83fAa1torLGYwxxky/p28sg==", "dev": true }, + "node_modules/nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", @@ -8818,6 +8834,14 @@ "integrity": "sha512-zR6HoT6LrLCRBwukmrVbHv0EpEQjksO6GmFcZQQuCAy139BEsoVKPYnf3jongYW83fAa1torLGYwxxky/p28sg==", "dev": true }, + "nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "requires": { + "abbrev": "1" + } + }, "normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", diff --git a/test/example/alternate-greeting-cm.yaml b/test/example/alternate-greeting-cm.yaml new file mode 100644 index 0000000..c403206 --- /dev/null +++ b/test/example/alternate-greeting-cm.yaml @@ -0,0 +1,8 @@ +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: alternate-greeting-cm + namespace: default +data: + greeting: howdy diff --git a/test/example/hello-cm.yaml b/test/example/hello-cm.yaml new file mode 100644 index 0000000..2e65222 --- /dev/null +++ b/test/example/hello-cm.yaml @@ -0,0 +1,8 @@ +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: hello-cm + namespace: default +data: + name: Razee diff --git a/test/example/hello-mtp.yaml b/test/example/hello-mtp.yaml new file mode 100644 index 0000000..b0300bf --- /dev/null +++ b/test/example/hello-mtp.yaml @@ -0,0 +1,28 @@ +--- +kind: MustacheTemplate +apiVersion: "deploy.razee.io/v1alpha2" +metadata: + name: hello-mtp + namespace: default +spec: + env: + - name: name + valueFrom: + configMapKeyRef: + name: hello-cm + key: name + - name: greeting + valueFrom: + configMapKeyRef: + name: alternate-greeting-cm + key: greeting + optional: true + default: "hello" + templates: + - kind: ConfigMap + apiVersion: v1 + metadata: + name: result + namespace: default + data: + result: "{{greeting}}, {{name}}!"