kubernetes-models-ts icon indicating copy to clipboard operation
kubernetes-models-ts copied to clipboard

Failure parsing regex from alertmanager CRDs

Open RealityAnomaly opened this issue 1 year ago • 2 comments

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:

  1. Generate a CRD model from https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/crds/crd-alertmanagerconfigs.yaml
  2. Error will be reported

Expected behavior CRD generated successfully

Additional context N/A

RealityAnomaly avatar May 15 '23 22:05 RealityAnomaly

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.

christoph-jerolimov avatar Oct 24 '23 06:10 christoph-jerolimov

One way to support this syntax is to use re2, which might impact performance (regex execution speed or module loading speed).

tommy351 avatar Oct 24 '23 10:10 tommy351