mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
51 lines
1.8 KiB
Plaintext
51 lines
1.8 KiB
Plaintext
// 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
|
|
|
|
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 <1>
|
|
namespace: {{ .metadata.namespace }} <2>
|
|
labels:
|
|
app: guestbook
|
|
tier: frontend
|
|
spec:
|
|
{{- if and .spec.type (eq (.spec.type) "NodePort" "LoadBalancer") }}
|
|
type: {{.spec.type }} <3>
|
|
{{- else }}
|
|
type: should be NodePort or LoadBalancer
|
|
{{- end }}
|
|
ports:
|
|
- port: 80
|
|
selector:
|
|
app: guestbook
|
|
{{- if .spec.selector.tier }} <4>
|
|
tier: frontend
|
|
{{- end }}
|
|
----
|
|
<1> Configures a required field that must match the specified value.
|
|
<2> Configures a required field that can have any value.
|
|
<3> Configures validation for the `.spec.type` field.
|
|
<4> Configures an optional field.
|