Skip to main content

ResourceTemplate

In order to make customizations easier, Koreo provides ResourceTemplate. ResourceTemplate allows static resources to be defined which ResourceFunctions may then overlay with dynamic values to produce a fully materialized resource. ResourceFunctions can dynamically compute the ResourceTemplate name, making it easy to support a range of use cases and configurations for a managed resource. By allowing the statically defined resource to be dynamically loaded, it reduces the need to create complex or verbose Functions.

For instance, ResourceTemplates may be provided for different environments, for specific resource types, or dynamically supplied configuration values. ResourceTemplates are also useful for simple static templates to provide common configuration, such as regions. This allows the ResourceFunction to be responsible for defining the interface and applying the values while ResourceTemplates supply the bulk of static configuration.

This model makes it easy to turn existing resources into ResourceTemplates, then use a Function only to apply dynamic values.

Static Resource Specification

The template is a static Target Resource Specification. Both apiVersion and kind must be provided, but everything else is optional. This static template will be (optionally) overlaid within the ResourceFunction. The metadata.name and metadata.namespace properties are always overlaid by the ResourceFunction, so you need not specify them.

ResourceTemplate Example

The example below demonstrates a ResourceFunction which dynamically loads a ResourceTemplate based on a provided input along with a corresponding FunctionTest.

apiVersion: koreo.dev/v1beta1
kind: ResourceTemplate
metadata:
# The template will be looked up by its name.
name: docs-template-one.v1
namespace: koreo-demo
spec:
# Template contains the static resource that will be used as the base.
# apiVersion and kind are required. The template is the actual body, or some
# portion thereof, which you'd like to set static values for.
template:
apiVersion: koreo.dev/v1beta1
kind: TestDummy
metadata:
labels:
docs.koreo.dev/example: template-label
spec:
value: one
nested:
- 1
- 2

Specification

NameTypeDescriptionRequired
apiVersionstringkoreo.dev/v1beta1true
kindstringResourceTemplatetrue
metadataobjectRefer to the Kubernetes API documentation for the fields of the metadata field.true
specobject
false
statusobject
false

spec

NameTypeDescriptionRequired
templateRawExtension
true
contextobject
false