kubernetes-models-ts
kubernetes-models-ts copied to clipboard
Failure parsing regex from alertmanager CRDs
Describe the bug Generation fails when parsing this regex. Looks like it's probably because the parser doesn't support mode modifiers
SyntaxError: Invalid regular expression: /^((?i)sun|mon|tues|wednes|thurs|fri|satur)day(?:((:(sun|mon|tues|wednes|thurs|fri|satur)day)$)|$)/u: Invalid group
at new RegExp (<anonymous>)
at rewriteStringPattern (/Users/alex/.npm/_npx/8852c2fa68ce2282/node_modules/@kubernetes-models/generate/dist/schema.js:88:22)
at /Users/alex/.npm/_npx/8852c2fa68ce2282/node_modules/@kubernetes-models/generate/dist/schema.js:114:52
at Array.reduce (<anonymous>)
at doTransformSchema (/Users/alex/.npm/_npx/8852c2fa68ce2282/node_modules/@kubernetes-models/generate/dist/schema.js:114:25)
at doTransformSchema (/Users/alex/.npm/_npx/8852c2fa68ce2282/node_modules/@kubernetes-models/generate/dist/schema.js:108:25)
at doTransformSchema (/Users/alex/.npm/_npx/8852c2fa68ce2282/node_modules/@kubernetes-models/generate/dist/schema.js:108:25)
at doTransformSchema (/Users/alex/.npm/_npx/8852c2fa68ce2282/node_modules/@kubernetes-models/generate/dist/schema.js:108:25)
at doTransformSchema (/Users/alex/.npm/_npx/8852c2fa68ce2282/node_modules/@kubernetes-models/generate/dist/schema.js:108:25)
at doTransformSchema (/Users/alex/.npm/_npx/8852c2fa68ce2282/node_modules/@kubernetes-models/generate/dist/schema.js:108:25)
To Reproduce Steps to reproduce the behavior:
- Generate a CRD model from https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/crds/crd-alertmanagerconfigs.yaml
- Error will be reported
Expected behavior CRD generated successfully
Additional context N/A
The CRD is now moved here: https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/charts/crds/crds/crd-alertmanagerconfigs.yaml
But it contains still a regex that isn't valid in JavaScript.
Tested in Chrome console:
/^((?i)sun|mon|tues|wednes|thurs|fri|satur)day(?:((:(sun|mon|tues|wednes|thurs|fri|satur)day)$)|$)/
VM294:1 Uncaught SyntaxError: Invalid regular expression: /^((?i)sun|mon|tues|wednes|thurs|fri|satur)day(?:((:(sun|mon|tues|wednes|thurs|fri|satur)day)$)|$)/: Invalid group
That's difficult to handle here. One solution might be to open a PR to change that regex to one that works also in JavaScript.
One way to support this syntax is to use re2, which might impact performance (regex execution speed or module loading speed).