fluxcd / flux2

Open and extensible continuous delivery solution for Kubernetes. Powered by GitOps Toolkit.
https://fluxcd.io
Apache License 2.0
6.14k stars 572 forks source link

Register JSON schema with SchemaStore #4751

Open krlittle opened 2 months ago

krlittle commented 2 months ago

Describe the bug

Flux does not have code completion or basic validation support in IDEs and editors such as VS Code, JetBrains IDEA, etc.

Steps to reproduce

Make an invalid change anywhere in Flux in VS Code or JetBrains IDEA and the IDE will not provide basic validation.

Expected behavior

By registering the existing JSON schemas in the generated crd-schemas with https://github.com/SchemaStore/schemastore it should automatically be picked up by many of the supporting IDEs and editors such as VS Code, JetBrains IDEA, etc. This would be extremely useful when using Flux as it offers code completion and basic validation for editors.

Screenshots and recordings

No response

OS / Distro

N/A

Flux version

N/A

Flux check

N/A

Git provider

No response

Container Registry provider

No response

Additional context

No response

Code of Conduct

stefanprodan commented 2 months ago

Flux has full support in JetBrains IDEA, all you need is to add the CRDs to the Kubernetes plugin, see:

Screenshot 2024-04-29 at 16 05 24

As for VSCode, we publish the OpenAPI spec for all our CRDs here: https://github.com/fluxcd-community/flux2-schemas

krlittle commented 2 months ago

Thank you so much for the additional information @stefanprodan and taking the time to comment. That is very helpful.

Would you be open to adding Flux's schemas to SchemaStore? As you can provide a pointer in their repository (here: src/api/json/catalog.json) to where the schemas exist, it should only be a one-time commit to SchemaStore.

stefanprodan commented 2 months ago

I'm not sure how this would work, there is no fileMatch that would makes sense for Flux, any YAML file can contain one or more or none Flux custom resources.

krlittle commented 2 months ago

Following through a similar example with the OpenRewrite project that might alleviate the concern for no fileMatch, OpenRewrite added a file with resource descriptions in their repository which uses if/then checks for their spec definitions: JSON schema for OpenRewrite resources

Then they pointed to this schema generically in SchemaStore like so: Add schema for OpenRewrite resource descriptors

    {
      "name": "OpenRewrite Resource",
      "description": "JSON schema for OpenRewrite resource descriptors",
      "fileMatch": ["**/META-INF/rewrite/*.yml"],
      "url": "https://raw.githubusercontent.com/openrewrite/rewrite/main/rewrite-core/openrewrite.json"
    },