6.4.5. 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.
6.4.5.1. Configuring inline validation with the regex function 링크 복사링크가 클립보드에 복사되었습니다!
Use the regex inline function to validate fields using regular expressions.
Procedure
Create a
metadata.yamlfile to match your use case. Use the following structure as an example:apiVersion: v2 parts: - name: Part1 components: - name: Example allOf: - path: example.yaml config: perField: - pathToKey: spec.bigTextBlock1 inlineDiffFunc: regex2 Use a regular expression to validate the field in the associated template:
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.