Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing prometheus-operator CRD causes compile to fail #578

Closed
vincentvdk opened this issue Oct 16, 2022 · 8 comments · Fixed by cdklabs/json2jsii#1261 or cdklabs/json2jsii#1259
Closed
Assignees
Labels
bug Something isn't working effort/medium 1 week tops priority/p1 Should be on near term plans

Comments

@vincentvdk
Copy link

When importing https://github.com/prometheus-operator/prometheus-operator/releases/download/v0.60.1/bundle.yaml the compile fails with following error

image

From imported CRD:

export enum AlertmanagerConfigSpecInhibitRulesSourceMatchMatchType {
  /** __stripped_by_cdk8s__ */
  STRIPPED_BY_CDK8S = '__stripped_by_cdk8s__',
  /** __stripped_by_cdk8s__ */
  STRIPPED_BY_CDK8S = '__stripped_by_cdk8s__',
  /** __stripped_by_cdk8s__ */
  STRIPPED_BY_CDK8S = '__stripped_by_cdk8s__',
  /** __stripped_by_cdk8s__ */
  STRIPPED_BY_CDK8S = '__stripped_by_cdk8s__',
}

/**
 * Match operation available with AlertManager >= v0.22.0 and takes precedence over Regex (deprecated) if non-empty.
 *
 * @schema AlertmanagerConfigSpecInhibitRulesTargetMatchMatchType
 */
export enum AlertmanagerConfigSpecInhibitRulesTargetMatchMatchType {
  /** __stripped_by_cdk8s__ */
  STRIPPED_BY_CDK8S = '__stripped_by_cdk8s__',
  /** __stripped_by_cdk8s__ */
  STRIPPED_BY_CDK8S = '__stripped_by_cdk8s__',
  /** __stripped_by_cdk8s__ */
  STRIPPED_BY_CDK8S = '__stripped_by_cdk8s__',
  /** __stripped_by_cdk8s__ */
  STRIPPED_BY_CDK8S = '__stripped_by_cdk8s__',
}
@iliapolo iliapolo added the needs-triage Priority and effort undetermined yet label Feb 6, 2023
@itaispiegel
Copy link

We're also facing this bug. Is anyone on this? :)

@crazed
Copy link
Contributor

crazed commented May 23, 2023

Also running into this with prometheus PodMonitor
https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.58.0/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml

The various enums accept different cases for the same string values, the resulting errors are:

\| 1086   REPLACE = 'replace',
--
\|        ~~~~~~~
\| com.coreos.monitoring.ts:1088:3 - error TS2300: Duplicate identifier 'REPLACE'.
\| 1088   REPLACE = 'Replace',
\|        ~~~~~~~
\| com.coreos.monitoring.ts:1090:3 - error TS2300: Duplicate identifier 'KEEP'.
\| 1090   KEEP = 'keep',
\|        ~~~~
\| com.coreos.monitoring.ts:1092:3 - error TS2300: Duplicate identifier 'KEEP'.
\| 1092   KEEP = 'Keep',
\|        ~~~~
\| com.coreos.monitoring.ts:1094:3 - error TS2300: Duplicate identifier 'DROP'.
\| 1094   DROP = 'drop',
\|        ~~~~
\| com.coreos.monitoring.ts:1096:3 - error TS2300: Duplicate identifier 'DROP'.
\| 1096   DROP = 'Drop',

I'm not super familiar with the internals here but it appears the strings are converted to the same variable name regardless of casing.

For those also affected: manually removing the various cases of the same string from the CRDs will allow cdk8s to generate appropriate enough code.

@iliapolo iliapolo added effort/medium 1 week tops priority/p1 Should be on near term plans bug Something isn't working and removed needs-triage Priority and effort undetermined yet labels Aug 8, 2023
@iliapolo
Copy link
Member

iliapolo commented Aug 8, 2023

Related to #229

@MalteMagnussen
Copy link

Also getting errors on Prometheus CRDs

Error message - click me
mhm@mhm:~/Documents/personal/go-cdk8s$ cdk8s import https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
Importing resources, this may take a few moments...
monitoring.coreos.com
  monitoring.coreos.com/servicemonitor
NOTE: Temp directory retained due to an error: /tmp/temp-eOzr32
Error: jsii compilation failed with non-zero exit code: 1
  | [2023-09-21T18:18:07.871] [ERROR] jsii/compiler - Compilation errors prevented the JSII assembly from being created
  | warning JSII6: A "peerDependency" on "constructs" at "10.2.70" means you should take a "devDependency" on "constructs" at "10.2.70" (found "undefined")
  | warning JSII6: A "peerDependency" on "cdk8s" at "2.64.18" means you should take a "devDependency" on "cdk8s" at "2.64.18" (found "undefined")
  | warning JSII3: There is no "README.md" file. It is required in order to generate valid PyPI (Python) packages.
  | monitoring.coreos.com.ts:1167:3 - error TS2300: Duplicate identifier 'REPLACE'.
  | 1167   REPLACE = "replace",
  |        ~~~~~~~
  | monitoring.coreos.com.ts:1169:3 - error TS2300: Duplicate identifier 'REPLACE'.
  | 1169   REPLACE = "Replace",
  |        ~~~~~~~
  | monitoring.coreos.com.ts:1171:3 - error TS2300: Duplicate identifier 'KEEP'.
  | 1171   KEEP = "keep",
  |        ~~~~
  | monitoring.coreos.com.ts:1173:3 - error TS2300: Duplicate identifier 'KEEP'.
  | 1173   KEEP = "Keep",
  |        ~~~~
  | monitoring.coreos.com.ts:1175:3 - error TS2300: Duplicate identifier 'DROP'.
  | 1175   DROP = "drop",
  |        ~~~~
  | monitoring.coreos.com.ts:1177:3 - error TS2300: Duplicate identifier 'DROP'.
  | 1177   DROP = "Drop",
  |        ~~~~
  | monitoring.coreos.com.ts:1195:3 - error TS2300: Duplicate identifier 'LOWERCASE'.
  | 1195   LOWERCASE = "lowercase",
  |        ~~~~~~~~~
  | monitoring.coreos.com.ts:1197:3 - error TS2300: Duplicate identifier 'LOWERCASE'.
  | 1197   LOWERCASE = "Lowercase",
  |        ~~~~~~~~~
  | monitoring.coreos.com.ts:1199:3 - error TS2300: Duplicate identifier 'UPPERCASE'.
  | 1199   UPPERCASE = "uppercase",
  |        ~~~~~~~~~
  | monitoring.coreos.com.ts:1201:3 - error TS2300: Duplicate identifier 'UPPERCASE'.
  | 1201   UPPERCASE = "Uppercase",
  |        ~~~~~~~~~
  | monitoring.coreos.com.ts:1303:3 - error TS2300: Duplicate identifier 'REPLACE'.
  | 1303   REPLACE = "replace",
  |        ~~~~~~~
  | monitoring.coreos.com.ts:1305:3 - error TS2300: Duplicate identifier 'REPLACE'.
  | 1305   REPLACE = "Replace",
  |        ~~~~~~~
  | monitoring.coreos.com.ts:1307:3 - error TS2300: Duplicate identifier 'KEEP'.
  | 1307   KEEP = "keep",
  |        ~~~~
  | monitoring.coreos.com.ts:1309:3 - error TS2300: Duplicate identifier 'KEEP'.
  | 1309   KEEP = "Keep",
  |        ~~~~
  | monitoring.coreos.com.ts:1311:3 - error TS2300: Duplicate identifier 'DROP'.
  | 1311   DROP = "drop",
  |        ~~~~
  | monitoring.coreos.com.ts:1313:3 - error TS2300: Duplicate identifier 'DROP'.
  | 1313   DROP = "Drop",
  |        ~~~~
  | monitoring.coreos.com.ts:1331:3 - error TS2300: Duplicate identifier 'LOWERCASE'.
  | 1331   LOWERCASE = "lowercase",
  |        ~~~~~~~~~
  | monitoring.coreos.com.ts:1333:3 - error TS2300: Duplicate identifier 'LOWERCASE'.
  | 1333   LOWERCASE = "Lowercase",
  |        ~~~~~~~~~
  | monitoring.coreos.com.ts:1335:3 - error TS2300: Duplicate identifier 'UPPERCASE'.
  | 1335   UPPERCASE = "uppercase",
  |        ~~~~~~~~~
  | monitoring.coreos.com.ts:1337:3 - error TS2300: Duplicate identifier 'UPPERCASE'.
  | 1337   UPPERCASE = "Uppercase",
  |        ~~~~~~~~~
  +----------------------------------------------------------------------------------
  | Command: /home/mhm/.nvm/versions/node/v18.16.0/lib/node_modules/cdk8s-cli/node_modules/jsii-srcmak/node_modules/jsii/bin/jsii --silence-warnings reserved-word
  | Workdir: /tmp/temp-eOzr32
  +----------------------------------------------------------------------------------
    at newError (/home/mhm/.nvm/versions/node/v18.16.0/lib/node_modules/cdk8s-cli/node_modules/jsii-srcmak/lib/util.js:62:20)
    at ChildProcess.<anonymous> (/home/mhm/.nvm/versions/node/v18.16.0/lib/node_modules/cdk8s-cli/node_modules/jsii-srcmak/lib/util.js:79:29)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)

@iliapolo
Copy link
Member

iliapolo commented Oct 18, 2023

@vinayak-kukreja lets make json2Jsii filter out (i.e choose only one) enum values and properties that result in the same camelCase. I think that the similar casings in these CRDs are a result of backwards compatibility guarantees, so we should be ok with just choosing one of them, as they all should continue to work until the next major version of the CRD, at which point a new clean schema will be published and a new cdk8s import will be required.

@vinayak-kukreja vinayak-kukreja self-assigned this Oct 19, 2023
@rassie
Copy link
Contributor

rassie commented Nov 2, 2023

It seems like the original issue (!=, =, =~ and !~ being part of an enum) has been a bit derailed by a similar but unconnected issue of case-sensitive enums.

image

@iliapolo's proposal only addresses the second issue. For the first issue: would it be considered OK to transcribe such enums as EXCLAMATION_EQUALS or do we need more logic or a whitelist of known mathematical expressions?

github-merge-queue bot pushed a commit to cdklabs/json2jsii that referenced this issue Nov 22, 2023
Enums in schema which has same value but different casing creates same
enum values which conflicts with each other. For instance,
[observed](cdk8s-team/cdk8s-cli#578 (comment))
while importing a custom resource definition in cdk8s.

```
\| 1086   REPLACE = 'replace',
--
\|        ~~~~~~~
\| com.coreos.monitoring.ts:1088:3 - error TS2300: Duplicate identifier 'REPLACE'.
\| 1088   REPLACE = 'Replace',
\|        ~~~~~~~
\| com.coreos.monitoring.ts:1090:3 - error TS2300: Duplicate identifier 'KEEP'.
\| 1090   KEEP = 'keep',
\|        ~~~~
\| com.coreos.monitoring.ts:1092:3 - error TS2300: Duplicate identifier 'KEEP'.
\| 1092   KEEP = 'Keep',
\|        ~~~~
\| com.coreos.monitoring.ts:1094:3 - error TS2300: Duplicate identifier 'DROP'.
\| 1094   DROP = 'drop',
\|        ~~~~
\| com.coreos.monitoring.ts:1096:3 - error TS2300: Duplicate identifier 'DROP'.
\| 1096   DROP = 'Drop',
```

Fixes cdk8s-team/cdk8s-cli#578

---------

Signed-off-by: Vinayak Kukreja <vinakuk@amazon.com>
github-merge-queue bot pushed a commit to cdklabs/json2jsii that referenced this issue Dec 8, 2023
…1261)

Characters like, `!=, ==, =~, !~` etc would result in `VALUE_` enum
values since we are not able to code generate these characters to
something valid. This PR is adding an allowlist with some known
characters to provide valid enum values if such a case occurs.

Fixes cdk8s-team/cdk8s-cli#578

---------

Signed-off-by: Vinayak Kukreja <vinakuk@amazon.com>
@vinayak-kukreja
Copy link
Contributor

Hey everyone, we have posted a fix for this issue, please let us know if you are still facing it.

@vinayak-kukreja
Copy link
Contributor

Hey all, please let us know if you still face this issue. Closing the thread for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working effort/medium 1 week tops priority/p1 Should be on near term plans
Projects
None yet
7 participants