tommy351 / kubernetes-models-ts

Kubernetes models in TypeScript.
https://www.npmjs.com/package/kubernetes-models
MIT License
136 stars 36 forks source link

Failure parsing regex from alertmanager CRDs #129

Closed RealityAnomaly closed 3 months ago

RealityAnomaly commented 1 year ago

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

jerolimov commented 11 months ago

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.

tommy351 commented 11 months ago

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