Templating
Some fields of the CRDs allow to use Go templates which are rendered by the operator. You can find some explanations on how to use them in here.
Cluster Template
The tenant field .spec.clusterTemplate
defines a template which is used to set default values for clusters of this tenant.
The template will only be applied to fields of the cluster which aren’t already set (empty or nil ).
It’s for example not possible to set the displayName of a cluster if it already defines one.
|
All string fields within this allow to use Go templates which are rendered by the operator.
The template has access to both the cluster as well as the tenant instance.
The cluster data can be accessed directly, while the tenant data is accessible through the {{ .Tenant }}
field.
Since both cluster and tenant are Go types, only exported fields (uppercase) can be accessed. The Go types are generally equivalent to the CRD YAML and differ only in that the fields are capitalized.
Since the |
To access a map in Go templates (like |
Some examples of how to access different values:
apiVersion: syn.tools/v1alpha1
kind: Tenant
metadata:
name: t-aezoo6
spec:
displayName: Big Corp.
gitRepoTemplate:
apiSecretRef:
name: vshn-gitlab
path: syn-dev/customers
repoName: t-aezoo6
clusterTemplate:
facts:
name: '{{ index .Annotations "syn.tools/name" }}'(1)
creation: '{{ .CreationTimestamp }}'
gitRepoTemplate:
apiSecretRef:
name: secret-{{ .Spec.TenantRef.Name }}
path: cluster-catalogs/{{ index .Spec.Facts "cloud" }}
repoName: catalog-{{ .Name }}
displayName: '{{ .Tenant.Spec.DisplayName }} - {{ .Spec.DisplayName }}'(2)
1 | Sets the fact name to the value in the annotation syn.tools/name of the cluster being templated. |
2 | Sets the git repository display name to a concatenation of the tenant’s display name and the clusters display name. |