mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
111 lines
4.1 KiB
Plaintext
111 lines
4.1 KiB
Plaintext
// Module included in the following assembly:
|
|
//
|
|
// * scalability_and_performance/cluster-compare/creating-a-reference-configuration.adoc
|
|
|
|
:_mod-docs-content-type: PROCEDURE
|
|
|
|
[id="cluster-compare-configure-inline-diff_{context}"]
|
|
= Configuring inline validation for template fields
|
|
|
|
You can enable inline regular expressions to validate template fields, especially in scenarios where Golang templating syntax is difficult to maintain or overly complex. Using inline regular expressions simplifies templates, improves readability, and allows for more advanced validation logic.
|
|
|
|
The `cluster-compare` plugin provides two functions for inline validation:
|
|
|
|
* `regex`: Validates content in a field using a regular expression.
|
|
* `capturegroups`: Enhances multi-line text comparisons by processing non-capture group text as exact matches, applying regular expression matching only within named capture groups, and ensuring consistency for repeated capture groups.
|
|
|
|
When you use either the `regex` or `capturegroups` function for inline validation, the `cluster-compare` plugin enforces that identically named capture groups have the same values across multiple fields within a template. This means that if a named capture group, such as `(?<username>[a-z0-9]+)`, appears in multiple fields, the values for that group must be consistent throughout the template.
|
|
|
|
[id="cluster-compare-configure-regex_{context}"]
|
|
== Configuring inline validation with the regex function
|
|
|
|
Use the `regex` inline function to validate fields using regular expressions.
|
|
|
|
.Procedure
|
|
|
|
. Create a `metadata.yaml` file to match your use case. Use the following structure as an example:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
apiVersion: v2
|
|
parts:
|
|
- name: Part1
|
|
components:
|
|
- name: Example
|
|
allOf:
|
|
- path: example.yaml
|
|
config:
|
|
perField:
|
|
- pathToKey: spec.bigTextBlock <1>
|
|
inlineDiffFunc: regex <2>
|
|
----
|
|
<1> Specifies the field for inline validation.
|
|
<2> Enables inline validation using regular expressions.
|
|
|
|
. Use a regular expression to validate the field in the associated template:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
namespace: dashboard
|
|
data:
|
|
username: "(?<username>[a-z0-9]+)"
|
|
bigTextBlock: |-
|
|
This is a big text block with some static content, like this line.
|
|
It also has a place where (?<username>[a-z0-9]+) would put in their own name. (?<username>[a-z0-9]+) would put in their own name.
|
|
----
|
|
|
|
[id="cluster-compare-configure-capturegroups_{context}"]
|
|
== Configuring inline validation with the capturegroups function
|
|
|
|
Use the `capturegroups` inline function for more precise validation of fields featuring multi-line strings. This function also ensures that identically named capture groups have the same values across multiple fields.
|
|
|
|
.Procedure
|
|
|
|
. Create a `metadata.yaml` file to match your use case. Use the following structure as an example:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
apiVersion: v2
|
|
parts:
|
|
- name: Part1
|
|
components:
|
|
- name: Example
|
|
allOf:
|
|
- path: example.yaml
|
|
config:
|
|
perField:
|
|
- pathToKey: data.username <1>
|
|
inlineDiffFunc: regex <2>
|
|
- pathToKey: spec.bigTextBlock <3>
|
|
inlineDiffFunc: capturegroups <4>
|
|
----
|
|
<1> Specifies the field for inline validation.
|
|
<2> Enables inline validation using capture groups.
|
|
<3> Specifies the multi-line field for capture-group validation.
|
|
<4> Enables inline validation using capture groups.
|
|
|
|
. Use a regular expression to validate the field in the associated template:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
namespace: dashboard
|
|
data:
|
|
username: "(?<username>[a-z0-9]+)" <1>
|
|
bigTextBlock: |-
|
|
This static content outside of a capture group should match exactly.
|
|
Here is a username capture group: (?<username>[a-z0-9]+).
|
|
It should match this capture group: (?<username>[a-z0-9]+).
|
|
----
|
|
<1> If the username value in the `data.username` field and the value captured in `bigTextBlock` do not match, the `cluster-compare` plugin warns you about the inconsistent matching.
|
|
+
|
|
.Example output with warning about the inconsistent matching:
|
|
[source,terminal]
|
|
----
|
|
WARNING: Capturegroup (?<username>…) matched multiple values: « mismatchuser | exampleuser »
|
|
---- |