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 metav1.TypeMeta (.metadata in YAML) is an embedded struct, you must access it’s fields directly (and not via .Metadata as in YAML). For example the name is accessed with {{ .Name }}.

To access a map in Go templates (like .Annotations) you have to use the index function. For example an annotation is accessed with {{ index .Annotations "syn.tools/name" }}.

Some examples of how to access different values:

apiVersion: syn.tools/v1alpha1
kind: Tenant
  name: t-aezoo6
  displayName: Big Corp.
      name: vshn-gitlab
    path: syn-dev/customers
    repoName: t-aezoo6
      name: '{{ index .Annotations "syn.tools/name" }}'(1)
      creation: '{{ .CreationTimestamp }}'
        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.