apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: regextests.stable.example.com
spec:
group: stable.example.com
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
regex:
type: string
x-kubernetes-validations:
# This rule only checks if the regex is valid.
# It results in an error if regex is ivalid, else the expression evaluates to true.
- rule: "''.findAll(self).size() >= 0"
scope: Namespaced
names:
plural: regextests
singular: regextest
kind: RegexTest
apiVersion: stable.example.com/v1
kind: RegexTest
metadata:
name: invalid
spec:
regex: '[0-9'
kubectl apply -f isregex/isregex-cr-invalid.yaml
The RegexTest "invalid" is invalid: spec.regex: Invalid value: "string": Illegal regex: error parsing regexp: missing closing ]: `[0-9` evaluating rule: ''.findAll(self).size() >= 0