@devdata/kubetpl
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

kubetpl

Templating helper for Kubernetes manifest files.

Usage

By CLI

npx @devdata/kubetpl \
    --sources 'kubernetes/**/*.{yml,yaml}'
    --config kubetpl.json \
    --runtime development \
    --vars.replicas 4 \
    > compiled-manifest.yml

kubetpl.json:

{
    "vars": {
        "replicas": {
            "default": "1",
            "production": "3"
        },
        "namespace": {
            "$default": "main"
        }
    }
}

By Code

import { Compiler } from 'kubetpl'

const config = {
    vars: {
        replicas: {
            default: '1',
            production: '3'
        },
        namespace: {
            $default: 'main'
        }
    }
}

const compiler = new Compiler({
    config,
    sources: 'kubernetes/**/*.{yml,yaml}',
    runtime: 'development',
    // Inject/override existing vars (optional)
    vars: {
        namespace: 'development'
    }
})

const manifest = compiler.compile()
// ... or
compiler.compileToFile('compiled-manifest.yml')

How it works

  1. Load up the sources from glob pattern/paths.
  2. Combine them into one using yaml Document starter (---)
  3. Replace all placeholders with values from the config and optionally extra vars. The runtime option determines which set of variables to use.
  4. Output the result.

The compiler will abort if theres a placeholder without any corresponding variable defined.

Placeholders

Put placeholders like this in your source files: {{vars.example}}.

Built in placeholders:

  • {{meta.runtime}} - Contains the runtime parameter passed into the compiler.

Ideas

  • Turn into GitHub Action for ease of use.

Readme

Keywords

none

Package Sidebar

Install

npm i @devdata/kubetpl

Weekly Downloads

23

Version

0.1.7

License

none

Unpacked Size

18.2 kB

Total Files

14

Last publish

Collaborators

  • zappen999