Crate ktmpl[][src]

Expand description

the Templates + Parameterization proposal.

The crate ships with a command line utility and a library for programmatically processing manifest templates. See the README for documentation for the command line utility, and a general overview of the Kubernetes template system.

Here is a simple example of using the library:

extern crate ktmpl;

use ktmpl::{ParameterValue, ParameterValues, Template};

fn main() {
    let template_contents = r#"
---
kind: "Template"
apiVersion: "v1"
metadata:
  name: "example"
objects:
  - kind: "Service"
    apiVersion: "v1"
    metadata:
      name: "$(DATABASE_SERVICE_NAME)"
    spec:
      ports:
        - name: "db"
          protocol: "TCP"
          targetPort: 3000
      selector:
        name: "$(DATABASE_SERVICE_NAME)"
parameters:
  - name: "DATABASE_SERVICE_NAME"
    description: "Database service name"
    required: true
    parameterType: "string"
"#;

    let mut parameter_values = ParameterValues::new();

    parameter_values.insert(
        "DATABASE_SERVICE_NAME".to_string(),
        ParameterValue::Plain("mongo".to_string()),
    );

    let template = Template::new(
        template_contents.to_string(),
        parameter_values,
        None,
    ).unwrap();
    let processed_template = template.process().unwrap();

    assert_eq!(
        processed_template.lines().map(|l| l.trim_right()).collect::<Vec<&str>>().join("\n"),
        r#"---
kind: Service
apiVersion: v1
metadata:
  name: mongo
spec:
  ports:
    - name: db
      protocol: TCP
      targetPort: 3000
  selector:
    name: mongo"#
    );
}

Structs

A Kubernetes secret.

A Kubernetes manifest template and the values for each of its parameters.

Enums

The user-supplied value of a template parameter, either plain text or Base64-encoded.

Functions

Loads ParameterValues from a file.

Loads ParameterValues from the raw contents of a parameter file.

Loads ParameterValues from a YAML document in the format of a parameter file.

Type Definitions

A map of parameter names to user-supplied values of the parameters.

A set of Kubernetes secrets.