cdk8s-team / cdk8s-cli

Apache License 2.0
37 stars 23 forks source link

Import k8s from custom URL #1938

Open mattdavis90 opened 6 months ago

mattdavis90 commented 6 months ago

Description of the feature or enhancement:

Add a command line option to cdk8s import k8s to point to a custom URL instead of the default (hardcoded) one. Something along the lines of cdk8s import k8s:http://127.0.0.1/_definitions.json.

Use Case:

I've created a project that generates a dynamic _definitions.json from your running Kubernetes installation and wanted to use this with the cdk8s import k8s command to have cdk8s generate imports that include all of my CRDs automatically without me specifying each one individually.

Currently the URL for k8s is hardcoded. By changing the file node_modules/cdk8s-cli/lib/import/k8s.js I can point to my URL and CDK8s successfully generates import files from my live deployment.

Suggested implementation

Similar to github and helm imports take a URL, allow something like cdk8s import k8s:<url> or add a CLI option such as --custom-url.

I'm happy to have a go at implementing this feature but wanted to find out if others are interested before opening a PR and also what the preferred means of specifying the URL would be.

Thanks


This is a :rocket: Feature Request

iliapolo commented 3 months ago

@mattdavis90 are you saying the _definitions.json that gets generated from your includes both core k8s resources AND CRDs? If its just CRDs than you can curl it locally, and then run cdk8s import /path/to/file.

If they include both, thats tricky because our code currently dispatches fairly different code paths for core resources vs CRDs.

mattdavis90 commented 3 months ago

Hi, the code exposes both k8s resources and CRDs within the same _definitions.json with the, admittedly little, testing that I did it seemed to work as expected by simply changing the import URL.

iliapolo commented 3 months ago

Changing the import URL makes it treat the file as only containing CDRs, probably ignoring core resources....

It's not a bad idea though to have cdk8s be able to treat each properly, no matter where it comes from.