Skip to content

Commit 5379cca

Browse files
committed
TELCODOCS#2148: Usability improvements in cluster-compare plugin
1 parent 78b4db9 commit 5379cca

7 files changed

+94
-4
lines changed

modules/cluster-compare-configure-inline-diff.adoc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ The `cluster-compare` plugin provides two functions for inline validation:
1414
* `regex`: Validates content in a field using a regular expression.
1515
* `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.
1616

17+
When using the `regex` or `capturegroups` function for inline validation, the `cluster-compare` plugin enforces that identically named capture groups match 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 remain consistent throughout the template.
18+
1719
[id="cluster-compare-configure-regex_{context}"]
1820
== Configuring inline validation with the regex function
1921

@@ -49,6 +51,7 @@ kind: ConfigMap
4951
metadata:
5052
namespace: dashboard
5153
data:
54+
username: "(?<username>[a-z0-9]+)"
5255
bigTextBlock: |-
5356
This is a big text block with some static content, like this line.
5457
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.
@@ -57,7 +60,7 @@ data:
5760
[id="cluster-compare-configure-capturegroups_{context}"]
5861
== Configuring inline validation with the capturegroups function
5962

60-
Use the `capturegroups` inline function for more precise validation of fields featuring multi-line strings.
63+
Use the `capturegroups` inline function for more precise validation of fields featuring multi-line strings. This function also ensures that identically named capture groups match the same values across multiple fields.
6164

6265
.Procedure
6366

@@ -74,11 +77,15 @@ parts:
7477
- path: example.yaml
7578
config:
7679
perField:
77-
- pathToKey: spec.bigTextBlock <1>
78-
inlineDiffFunc: capturegroups <2>
80+
- pathToKey: data.username <1>
81+
inlineDiffFunc: regex <2>
82+
- pathToKey: spec.bigTextBlock <3>
83+
inlineDiffFunc: capturegroups <4>
7984
----
8085
<1> Specifies the field for inline validation.
8186
<2> Enables inline validation using capture groups.
87+
<3> Specifies the multi-line field for capture group validation.
88+
<4> Enables inline validation using capture groups.
8289

8390
. Use a regular expression to validate the field in the associated template:
8491
+
@@ -89,6 +96,7 @@ kind: ConfigMap
8996
metadata:
9097
namespace: dashboard
9198
data:
99+
username: "(?<username>[a-z0-9]+)"
92100
bigTextBlock: |-
93101
This static content outside of a capture group should match exactly.
94102
Here is a username capture group: (?<username>[a-z0-9]+).

modules/cluster-compare-reference-args.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ The following content describes the options for the `cluster-compare` plugin.
2929
| `--generate-override-for`
3030
| Specify the path for templates that requires a patch.
3131

32+
| `--show-template-functions`
33+
| Displays the available template functions.
34+
3235
[NOTE]
3336
====
3437
You must use a file path for the target template that is relative to the `metadata.yaml` file. For example, if the file path for the `metadata.yaml` file is `./compare/metadata.yaml`, a relative file path for the template might be `optional/my-template.yaml`.
@@ -41,7 +44,7 @@ You must use a file path for the target template that is relative to the `metada
4144
| Specify a path to process the `kustomization` directory. This flag cannot be used together with `-f` or `-R`.
4245

4346
| `-o`, `--output`
44-
| Specify the output format. Options include `json`, `yaml`, or `generate-patches`.
47+
| Specify the output format. Options include `json`, `yaml`, `junit`, or `generate-patches`.
4548

4649
| `--override-reason`
4750
| Specify a reason for generating the override.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Module included in the following assemblies:
2+
3+
// *scalability_and_performance/cluster-compare/creating-a-reference-configuration.adoc
4+
5+
:_mod-docs-content-type: REFERENCE
6+
7+
[id="cluster-compare-templating-reference_{context}"]
8+
= Reference template functions
9+
10+
The `cluster-compare` plugin supports all `sprig` library functions, except for the `env` and `expandenv` functions.
11+
See _Additional resources_ for the full list of `sprig` library functions.
12+
13+
The following content describes the additional template functions for the `cluster-compare` plugin.
14+
15+
.Additional cluster-compare template functions
16+
[options="header"]
17+
[cols="2a,3a"]
18+
|====
19+
| Function | Description
20+
21+
|`fromJson`
22+
|Parses the incoming string as a structured JSON object.
23+
24+
|`fromJsonArray`
25+
|Parses the incoming string as a structured JSON array.
26+
27+
|`fromYaml`
28+
|Parses the incoming string as a structured YAML object.
29+
30+
|`fromYamlArray`
31+
|Parses the incoming string as a structured YAML array.
32+
33+
|`toJson`
34+
|Renders incoming data as JSON while preserving object types.
35+
36+
|`toToml`
37+
|Renders the incoming string as structured TOML data.
38+
39+
|`toYaml`
40+
|Renders incoming data as YAML while preserving object types.
41+
42+
|`doNotMatch`
43+
|Prevents a template from matching a cluster resource, even if it would normally match. You can use this function inside a template to conditionally exclude certain resources from correlation. The specified reason is logged when running with the `--verbose` flag. Templates skipped solely due to `doNotMatch` are not considered comparison failures.
44+
45+
|====

modules/using-cluster-compare-live-cluster.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,12 @@ No patched CRs <10>
8484
<8> The CRs that did not match to a corresponding template in the reference configuration.
8585
<9> The metadata hash identifies the reference configuration.
8686
<10> The list of patched CRs.
87+
88+
[NOTE]
89+
====
90+
You can also get the output in `junit` format by adding `-o junit` to the command. For example:
91+
[source,terminal]
92+
----
93+
$ oc cluster-compare -r <path_to_reference_config>/metadata.yaml -o junit
94+
----
95+
====

modules/using-cluster-compare-must-gather.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,12 @@ No patched CRs <10>
8282
<8> The CRs that did not match to a corresponding template in the reference configuration.
8383
<9> The metadata hash identifies the reference configuration.
8484
<10> The list of patched CRs.
85+
86+
[NOTE]
87+
====
88+
You can also get the output in `junit` format by adding `-o junit` to the command. For example:
89+
[source,terminal]
90+
----
91+
$ oc cluster-compare -r <path_to_reference_config>/metadata.yaml -f "must-gather*/*/cluster-scoped-resources","must-gather*/*/namespaces" -R -o junit
92+
----
93+
====

modules/using-cluster-compare-telco-ref.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,12 @@ No patched CRs <10>
158158
<8> The CRs that did not match to a corresponding template in the reference configuration.
159159
<9> The metadata hash identifies the reference configuration.
160160
<10> The list of patched CRs.
161+
162+
[NOTE]
163+
====
164+
You can also get the output in `junit` format by adding `-o junit` to the command. For example:
165+
[source,terminal]
166+
----
167+
$ oc cluster-compare -r out/telco-core-rds/configuration/reference-crs-kube-compare/metadata.yaml -o junit
168+
----
169+
====

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ include::modules/cluster-compare-template-groupings.adoc[leveloffset=+1]
1414

1515
include::modules/cluster-compare-templating.adoc[leveloffset=+1]
1616

17+
include::modules/cluster-compare-templating-reference.adoc[leveloffset=+2]
18+
19+
[role="_additional-resources"]
20+
.Additional resources
21+
22+
* link:https://masterminds.github.io/sprig/[Sprig Function Documentation]
23+
1724
include::modules/cluster-compare-exclude-metadata.adoc[leveloffset=+1]
1825

1926
include::modules/cluster-compare-configure-inline-diff.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)