Skip to content

feat: auto-detect Kubernetes crd schema #1050

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

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

Conversation

qvalentin
Copy link

@qvalentin qvalentin commented Apr 19, 2025

What does this PR do?

This PR adds an option to automatically detect the Kubernetes schema by parsing the contents of the document. In case a Kubernetes GroupVersionKind (GVK) is detected, the matching schema is retrieved from the CRD catalog.

What issues does this PR fix or reference?

#605

Is it tested? How?

Tests for parsing the Kubernetes Group Version Kind have been added

Updated version of #962 including the following changes:

  • only run the auto-detect for files that are registered with the kubernetes schema
  • check if the Kubernetes GroupVersionKind is already defined in the main kubernetes schema, if so, don't look it up in the CRD catalog
  • add config option for crd catalog uri
  • more tests

TODO:

  • final testing
  • add new options to readme

msvechla and others added 5 commits April 22, 2024 20:04
automatically detect the Kubernetes schema based on the document's
GroupVersionKind (GVK) and retrieve the matching schema from the
CRD catalog.
@qvalentin qvalentin changed the title Crd feat: auto-detect Kubernetes crd schema Apr 19, 2025
@tricktron
Copy link

@qvalentin Thanks for the nice work. I actually started working on this as well: https://github.com/tricktron/yaml-language-server/tree/f-kubernetes-improvements

However, I just hardcoded the core kubernetes groups but yours looks better in my opinion. I then actually got sidetracked by adding some more features to my https://github.com/tricktron/crd2jsonschema tool so that I could easily test end-to-end with the newest openshift and tekton crds.

Maybe you can also take over some tests from my my branch, e.g. main...tricktron:yaml-language-server:f-kubernetes-improvements#diff-5d1a1b48130b3cb749d3ae36d72e52f8882d6fa5dc9eaedc5d6e606e411b176cR1194-R1219

And lastly, we should then probably add some documentation as well. This might be a breaking change for the helm language server where you hardcode the kubernetes schemas to templates/**. E.g. this is not needed anymore with this pr and I think it even results in some errors if I remember correctly from my e2e tests. Anyway, I won´t have much time to look at this until next Wednesday but still wanted to give you a fast feedback.

@qvalentin
Copy link
Author

@tricktron I took a look at the schemaValidation.test.ts but since in my logic the customSchemaProvider has higher priority then the CRD logic the tests don't work with my branch.

But I might copy the config options format.

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.

4 participants