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§
- Secret
- A Kubernetes secret.
- Template
- A Kubernetes manifest template and the values for each of its parameters.
Enums§
- Parameter
Value - The user-supplied value of a template parameter, either plain text or Base64-encoded.
Functions§
- parameter_
values_ from_ file - Loads
ParameterValuesfrom a file. - parameter_
values_ from_ str - Loads
ParameterValuesfrom the raw contents of a parameter file. - parameter_
values_ from_ yaml - Loads
ParameterValuesfrom a YAML document in the format of a parameter file.
Type Aliases§
- Parameter
Values - A map of parameter names to user-supplied values of the parameters.
- Secrets
- A set of Kubernetes secrets.