Templates
Space templates are, as the name implies, templates that you can create which can then be applied when creating a space. These templates can be used to configure any space settings that you would configure on an individual space object.
Space templates are used for creating a standard developer environment for a given team or organization or to template out pre-built environments to be used in continuous integration and testing.
As regular project users can only deploy new spaces via template, templates provide a mechanism to isolate namespaces from each other.
Templates can include settings such as:
- Isolation relevant objects, such as resource quotas, limit ranges and network policies.
- Kubernetes objects (including CRDs!). This could include development tooling, pre-populated databases with test data, or any other useful resources.
- Custom defined Apps
Create Space Template
Space templates can be created directly in the Loft UI.
- In the Loft UI, select the Templates field on the left-most menu bar.
- From the Templates sub-menu, select the button.
- Click button.
- In the drawer that appears from the right, give your space template a name by replacing the 'my-template' placeholder name, or by updating the manifest YAML 'metadata.name' field.
- [Optional] Update the template with any additional desired configuration options.
- The Definition tab contains settings relating to the space deployment itself, primarily related to sleeping, see the Sleep Mode section for more details.
- Objects is where you can define Kubernetes manifests that should be created in the virtual cluster.
- Apps allows you to select any pre-defined 'applications' (ex: Cert Manager) that should be installed into the virtual cluster.
- Parameters provides a mechanism for exposing values that users should be able to modify when deploying a virtual cluster from this template.
- Permissions are additional access rules that can be defined for the virtual cluster instance.
- Finally, Template Permissions are the permissions that are applied to the template itself -- that is, who has permission to view/edit this template.
- Click on the button at the very bottom.
Using Templates (UI & CLI)
Once you have created a space template you can then refer to that template when creating a new space. All template configurations will be automatically applied to the newly created space. Spaces referring to templates can be created in the UI or via the Loft CLI.
- UI
- CLI
- Select the Projects field on the left menu bar.
- From the project drop-down menu, select the project you'd like to create the space in.
- Click the Spaces option on the project pane.
- Click the button on the right side of the page.
- In the pop-up box, select your template from the template drop down menu.
- [Optional] select the cluster in which to create the virtual cluster.
- Click the to continue.
- In the drawer that appears from the right, give your space a name by replacing the my-space placeholder name, or by updating the manifest YAML metadata.name field.
- Click the button.
When creating a space from the Loft CLI, you will need to provide the name of the project in which to deploy the space, and the name of template to use:
loft create space [vcluster-name] --project [project-name] --template [template-name]
Versioning
Space templates can be versioned. Versioning a space template allows you to make changes over time to a template while retaining the current version/iteration. Spaces that are deployed with templates that have updated versions will show up with a warning indicating that a newer template version is available.
Parameters
Parameters are a very powerful component of space templates. These parameters allow for giving users that may consume your space template a bit of flexibility with configuration options for certain applications, while still maintaining control over the possible values the users can select.
When deploying a space referring to a template with parameters configured, Loft will
prompt the user for their selection for the given parameters. For example, with a parameters
configuration as shown below, the user will get a dialog box where they can select 'one' or
'two' as the value for the mylabelvalue
variable.
- variable: mylabelvalue
label: SpaceLabelValue
description: Please select the value for the Space "my-label" key
options:
- one
- two
section: Labels
The final value of this variable can then be used throughout the template. For example, this value can be used within space label and annotaitons section. In the example below, this value is being set as a label on the created space object.
my-label: "{{ .Values.mylabelvalue }}"
Check out the Apps section of the docs, especially the Parameters section for more details on Parameters generally, and in relation to Apps!