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

feat: supprt cdktf ^0.20.x #445

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BrentSouza
Copy link

@BrentSouza BrentSouza commented Jun 22, 2024

Fixes #485

Hello. Just figured I would give this a shot! Please let me know if there is any additional work that should be completed. Tests seem to pass when run locally:

 PASS  test/resolve.test.ts (14.014 s)
  √ can resolve direct output value (59 ms)
  √ can resolve indirect output value (9 ms)
  √ can resolve numbers (5 ms)
  √ can resolve booleans (5 ms)
  √ can resolve token maps (5 ms)
  √ cannot resolve literal maps (11 ms)
  √ can resolve token arrays (5 ms)
  √ cannot resolve literal arrays (5 ms)
  √ can resolve expressions (18 ms)
  √ can resolve nested output value (4 ms)
  √ can resolve resource (6 ms)
...
Test Suites: 1 passed, 1 total
Tests:       11 passed, 11 total
Snapshots:   9 updated, 9 total

@BrentSouza BrentSouza changed the title Update deps to support newer cdktf versions chore(deps): Update deps to support newer cdktf versions Jun 22, 2024
Copy link
Member

@iliapolo iliapolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this change but I would like to understand exactly why things don't work without it. Can you share your project setup and the error you are seeing?

Naively, there's nothing preventing peers from using 0.20.7 even now.

"ts-node": "^10.9.2",
"typescript": "^5.5.2"
},
"peerDependencies": {
"cdk8s": "^2.68.11",
"cdktf": "^0.19.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be required because the ^ means any minor version above 19 can be used by peers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iliapolo I don't believe that is how it works. When a package version has a zero as the major version the caret will not increment the minor version, only the patch.

See this for an example:

https://semver.npmjs.com

Use cdktf and specify ^0.19.0 as the version. You'll see 0.20 package versions are not listed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrentSouza is correct. The notion of patch versions only getting bumped on dependencies below 1.0.0 is npm update docs: https://docs.npmjs.com/cli/v10/commands/npm-update#caret-dependencies-below-100

@@ -43,37 +43,37 @@
},
"devDependencies": {
"@cdk8s/projen-common": "0.0.530",
"@cdktf/provider-aws": "^17.0.11",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is this required by [email protected]?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The version constraint on the provider package is incompatible with 0.20.7 of the main cdktf package.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDKTF version 0.20.0 support was added to @cdktf/provider-aws starting @ v19.0.0 which released January 10, 2024. Commit Release

The package.json for the release included typescript ~5.2.0.

"cdktf-cli": "^0.20.7",
"constructs": "^10.3.0",
"eslint": "^8",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"fs-extra": "^11.2.0",
"jest": "^27",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jest needs to be updated to fix the warning that it has not been tested for typescript 5. Also the conversation in the fix notes indicates that even though some later versions said it worked, it didn't.

kulshekhar/ts-jest#4048

"jest-junit": "^15",
"jsii": "^5",
"jsii-diff": "^1.100.0",
"jsii-docgen": "^9.2.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come?

"jsii-pacmak": "^1.100.0",
"jsii-rosetta": "^5",
"projen": "^0.82.8",
"standard-version": "^9",
"ts-jest": "^27",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the above version changes came about because I get the following error running npm install:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/typescript
npm error   typescript@"^5.5.2" from the root project
npm error
npm error Could not resolve dependency:
npm error peer typescript@">=3.8 <5.0" from [email protected]
npm error node_modules/ts-jest
npm error   ts-jest@"^27" from the root project

@BrentSouza
Copy link
Author

Hi @iliapolo, I should note I'm also using both cdktf and cdk8s in python, which is where the version constraint produces an error for my project.

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
cdk8s-cdktf-resolver 0.0.89 requires cdktf<0.20.0,>=0.19.1, but you have cdktf 0.20.7 which is incompatible.

Granted, the package still installs. I just would like to clear out the errors.

@BrentSouza
Copy link
Author

BrentSouza commented Jun 26, 2024

For javascript/typescript, here is a basic project setup that will fail:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "@cdk8s/cdktf-resolver": "^0.0.89",
    "cdk8s": "^2.68.82",
    "cdktf": "^0.20.7"
  }
}

Running npm install for this produces:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/cdktf
npm error   cdktf@"^0.20.7" from the root project
npm error
npm error Could not resolve dependency:
npm error peer cdktf@"^0.19.1" from @cdk8s/[email protected]
npm error node_modules/@cdk8s/cdktf-resolver
npm error   @cdk8s/cdktf-resolver@"^0.0.89" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.

Copy link

@joekiller joekiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this looks clean and would be appreciated :)

The general theme here is that terraform-cdk is in the v0.20.0 range right now and because of the way npm handles carrot dependencies below 1.0.0 the cdktf and related dependencies need updating.

Side note, the project here itself is always in patch numbers but it can use minor due to NPM's handling of below 1.0.0 carrots too. I think what is expected i.e. that each minor bump isn't compatible with the next in the "zero-dots" (0.X.Y) is expected which would open up the "opportunity" to patch previous versions if needed.

"ts-node": "^10.9.2",
"typescript": "^5.5.2"
},
"peerDependencies": {
"cdk8s": "^2.68.11",
"cdktf": "^0.19.1",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrentSouza is correct. The notion of patch versions only getting bumped on dependencies below 1.0.0 is npm update docs: https://docs.npmjs.com/cli/v10/commands/npm-update#caret-dependencies-below-100

@@ -43,37 +43,37 @@
},
"devDependencies": {
"@cdk8s/projen-common": "0.0.530",
"@cdktf/provider-aws": "^17.0.11",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDKTF version 0.20.0 support was added to @cdktf/provider-aws starting @ v19.0.0 which released January 10, 2024. Commit Release

The package.json for the release included typescript ~5.2.0.

"@types/fs-extra": "^11.0.4",
"@types/jest": "^27",
"@types/jest": "^29",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jest added support for typescript 5.x starting with version 29.1.0 (ts-jest 20.1.0 CHANGELOG.md 2023-03-26)

"cdktf-cli": "^0.20.7",
"constructs": "^10.3.0",
"eslint": "^8",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"fs-extra": "^11.2.0",
"jest": "^27",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jest needs to be updated to fix the warning that it has not been tested for typescript 5. Also the conversation in the fix notes indicates that even though some later versions said it worked, it didn't.

kulshekhar/ts-jest#4048

@joekiller
Copy link

@BrentSouza a maintenance release (v0.0.91) got pushed out. you might want a merge in main (or rebase) and yarn install to update the lock.

cdk8s-team maintainers

The development dependencies between "cdktf": "^0.19.1" and has already drifted with "@cdktf/provider-aws": "^17.0.11", wanting 0.18. It may be good to consider utilizing npm such that accidental drift isn't happening with these "pre-stable" releases.

Having everyone understand that caret dependencies below 1.0.0 don't float I hope the cdk8s-team will take these PRs more readily as part of their workflow and consider adopting a package manager that fails when peer dependencies fail to sync.

https://semver.org/spec/v2.0.0.html#how-should-i-deal-with-revisions-in-the-0yz-initial-development-phase

Additional comments

The project utilizes yarn and if you tried to npm install the current tree it'll fail too. This difference in results is due to after npm 7 was released the behavior was changed regarding peer dependencies. Before npm would warn about the peer dependencies being incompatible (and this is what yarn does today). npm 7+, released early 2021, will now fail if the peer dependencies are incompatible (probably a good thing!). See npm 7 is now generally available! - peer-dependencies.

In the meantime if you are using a modern npm, you could set the project to use legacy-peer-deps, via npm config set legacy-peer-deps true --location project but this is not idea in the long run.

yarn seems to ignore people reporting "Unmet Peer Dependencies should fail build" regarding this issue and suggests that projects could use a log filter which pretty much ignores the fact that peer dependencies are part of the ecosystem now.

I think this node blog, from 2013(!), Peer Dependencies summarizes the best approach:

One piece of advice: peer dependency requirements, unlike those for regular dependencies, should be lenient. You should not lock your peer dependencies down to specific patch versions. It would be really annoying if one Chai plugin peer-depended on Chai 1.4.1, while another depended on Chai 1.5.0, simply because the authors were lazy and didn't spend the time figuring out the actual minimum version of Chai they are compatible with.

Sadly this project is in the unstable phase so the advice is good but doesn't have as much flexibility as one might desire at this time.

I hope this gets merged.

@BrentSouza
Copy link
Author

@joekiller Yup I keep rebasing every few days since the automated patches keep introducing conflicts. I’ll push an update this morning.

@BrentSouza
Copy link
Author

@iliapolo Any additional questions or concerns with the changes outlined in this PR?

Copy link

@joekiller joekiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@BrentSouza
Copy link
Author

I was away for a bit but I've rebased once again on the latest from main. @iliapolo please let me know if you need any further information or would like to see additional changes.

@BrentSouza
Copy link
Author

Keeping the fire burning on this one 🔥

Just rebased once again. @iliapolo Hopefully things are well with you. Please let me know if there's anything else I can do for this PR

@joekiller
Copy link

joekiller commented Jul 24, 2024

I too hope Eli is doing well. In the meantime, could anyone else of the @cdk8s-team provide a review here?

@iliapolo
Copy link
Member

@BrentSouza @joekiller Appreciate the work on this and the calrifications. LGTM 👍

@iliapolo
Copy link
Member

@BrentSouza apologies but looks like we need to regenerate some snapshot files. Run yarn build and we should be good.

Now that the PR is approved it should just merge once the snapshots are fixed.

Thanks!

@iliapolo iliapolo changed the title chore(deps): Update deps to support newer cdktf versions feat(deps): supprt cdktf ^0.20.x Jul 28, 2024
@iliapolo iliapolo changed the title feat(deps): supprt cdktf ^0.20.x feat: supprt cdktf ^0.20.x Jul 28, 2024
@BrentSouza
Copy link
Author

@iliapolo Running yarn build is showing that it will remove all of the README.md content from API.md. Is there something I should be doing to prevent that?

@BrentSouza
Copy link
Author

Looks like if I modify the task to use the -r option, the README is included. I can either:

  1. Modify the docgen task in .projen/tasks.json to include the -r option, thus avoiding any diff for API.md
  2. Allow the readme content to be removed from API.md

I'll wait to hear back on what the desired output is.

@BrentSouza
Copy link
Author

Looking at it a bit more, this is because we're updating jsii-docgen to 10.x.x

Seems like removal of the README content is an intended change for JSII projects since tasks.json is generated as part of the build. I'll rebase to get the latest conflicts resolved and run yarn build then push

@BrentSouza
Copy link
Author

@iliapolo Unfortunately I have to bug you once more as the build step requires approval to run.

@BrentSouza
Copy link
Author

I had to step away from this one for a bit, but I'm happy to rebase and resolve conflicts once more if we can coordinate on the pipeline approval @iliapolo? It's a chore to keep rebasing given the automated updates to the project.

@iliapolo
Copy link
Member

@BrentSouza yeah I understand. Please rebase and ping me on slack so I can merge before the next rebasing cycle :)

@iliapolo iliapolo added the response-requested Awaiting response from author label Sep 10, 2024
Copy link

This PR has not received a response in a while and will be closed soon. If you want to keep it open, please leave a comment below @mentioning a maintainer.

@joekiller
Copy link

@BrentSouza I hope you can rebase and connect with @iliapolo on slack. The link is on the website but here it is for convenience: https://cdk.dev/

@github-actions github-actions bot removed closing-soon response-requested Awaiting response from author labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cdk8s-cdktf-resolver: Support cdktf ^0.20
4 participants