// Module included in the following assemblies:

// *scalability_and_performance/cluster-compare/creating-a-reference-configuration.adoc

:_mod-docs-content-type: PROCEDURE

[id="cluster-compare-templating_{context}"]
= Configuring expected variation in a template

[role="_abstract"]
You can handle variable content within a template by using Golang templating syntax. Using this syntax, you can configure validation logic that handles optional, required, and conditional content within the template.  

[NOTE]
====
* The `cluster-compare` plugin requires all templates to render as valid YAML. To avoid parsing errors for missing fields, use conditional templating syntax such as `{{- if .spec.<optional_field> }}` when implementing templating syntax. This conditional logic ensures templates process missing fields gracefully and maintains valid YAML formatting.

* You can use the Golang templating syntax with custom and built-in functions for complex use cases. All Golang built-in functions are supported including the functions in the Sprig library.
====

.Procedure

* Create a `metadata.yaml` file to match your use case. Use the following structure as an example:
+
[source,yaml]
----
apiVersion: v2
kind: Service
metadata:
  name: frontend
  namespace: {{ .metadata.namespace }}
  labels:
    app: guestbook
    tier: frontend
spec:
  {{- if and .spec.type (eq (.spec.type) "NodePort" "LoadBalancer") }}
  type: {{.spec.type }}
  {{- else }}
  type: should be NodePort or LoadBalancer
  {{- end }}
  ports:
  - port: 80
  selector:
    app: guestbook
    {{- if .spec.selector.tier }}
    tier: frontend
    {{- end }}
----
+
where:

`name: frontend`:: Configures a required field that must match the specified value.
`namespace: \{{ .metadata.namespace }}`:: Configures a required field that can have any value.
`type: \{{.spec.type }}`:: Configures validation for the `.spec.type` field.
`\{{- if .spec.selector.tier }}`:: Configures an optional field.
