Skip to content

Commit

Permalink
Merge pull request #114 from eromanova/docs
Browse files Browse the repository at this point in the history
Document Template system
  • Loading branch information
Kshatrix authored Jul 30, 2024
2 parents 8341851 + d403237 commit a4514ce
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export KUBECONFIG=<path-to-management-kubeconfig>
kubectl get template -n hmc-system -o go-template='{{ range .items }}{{ if eq .status.type "deployment" }}{{ .metadata.name }}{{ printf "\n" }}{{ end }}{{ end }}'
```

For details about the `Template system` in HMC, see [Templates system](docs/templates/main.md#templates-system).

2. Create the file with the `Deployment` configuration:

> Substitute the parameters enclosed in angle brackets with the corresponding values.\
Expand Down
128 changes: 128 additions & 0 deletions docs/templates/main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Templates system

By default, Hybrid Container Cloud delivers a set of default `Template` objects. You can also build your own templates
and use them for deployment.

## Custom deployment Templates

> At the moment all `Templates` should reside in the `hmc-system` namespace. But they can be referenced
> by `Deployments` from any namespace.
Here are the instructions on how to bring your own Template to HMC:

1. Create a [HelmRepository](https://fluxcd.io/flux/components/source/helmrepositories/) object containing the URL to the
external Helm repository.
2. Create a [HelmChart](https://fluxcd.io/flux/components/source/helmcharts/) object referencing the `HelmRepository` as a
`sourceRef`, specifying the name and version of your Helm chart.
3. Create a `Template` object in `hmc-system` namespace referencing this helm chart in `spec.helm.chartRef`.
`chartRef` is a field of the
[CrossNamespaceSourceReference](https://fluxcd.io/flux/components/helm/api/v2/#helm.toolkit.fluxcd.io/v2.CrossNamespaceSourceReference) kind.

Here is an example of a custom `Template` with the `HelmChart` reference:

```yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: custom-templates-repo
namespace: hmc-system
spec:
insecure: true
interval: 10m0s
provider: generic
type: oci
url: oci://ghcr.io/external-templates-repo/charts
```
```yaml
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmChart
metadata:
name: custom-template-chart
namespace: hmc-system
spec:
interval: 5m0s
chart: custom-template-chart-name
reconcileStrategy: ChartVersion
sourceRef:
kind: HelmRepository
name: custom-templates-repo
version: 0.2.0
```
```yaml
apiVersion: hmc.mirantis.com/v1alpha1
kind: Template
metadata:
name: os-k0smotron
namespace: hmc-system
spec:
type: deployment
providers:
infrastructure:
- openstack
bootstrap:
- k0s
controlPlane:
- k0smotron
helm:
chartRef:
kind: HelmChart
name: custom-template-chart
namespace: default
```
The `Template` should follow the rules mentioned below:
1. `spec.type` should be `deployment` (as an alternative, the referenced helm chart may contain the
`hmc.mirantis.com/type: deployment` annotation in `Chart.yaml`).
2. `spec.providers` should contain the list of required Cluster API providers: `infrastructure`, `bootstrap` and
`controlPlane`. As an alternative, the referenced helm chart may contain the specific annotations in the
`Chart.yaml` (value is a list of providers divided by comma). These fields are only used for validation. For example:

`Template` spec:

```yaml
spec:
providers:
infrastructure:
- aws
bootstrap:
- k0s
controlPlane:
- k0smotron
```

`Chart.yaml`:

```bash
annotations:
hmc.mirantis.com/infrastructure-providers: aws
hmc.mirantis.com/controlplane-providers: k0smotron
hmc.mirantis.com/bootstrap-providers: k0s
```

## Remove Templates shipped with HMC

If you need to limit the cluster templates that exist in your HMC installation, follow the instructions below:

1. Get the list of `deployment` Templates shipped with HMC:

```bash
kubectl get templates -n hmc-system -l helm.toolkit.fluxcd.io/name=hmc-templates | grep deployment
```

Example output:
```bash
aws-hosted-cp deployment true
aws-standalone-cp deployment true
```

2. Remove the templates from the list:

```bash
kubectl delete template -n hmc-system <template-name>
```
<!---
TODO: document `--create-template=false` controller flag once the templates are limited to deployment templates only.
-->

0 comments on commit a4514ce

Please sign in to comment.