vscode-kubernetes-tools / vscode-kubernetes-tools

Kubernetes extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools
Apache License 2.0
684 stars 246 forks source link

schema validation conflicts with other vscode extension on templates yaml #1178

Open yury-kozlov opened 1 year ago

yury-kozlov commented 1 year ago

In our monorepo we have a custom folder named "templates" where we store yaml files not related to kubernetes and to which we apply custom schema validation using "redhat.vscode-yaml" extension. The problem is that when Kubernetes extension is enabled it takes over schema validation of any yaml file located in this folder due to pattern collision "**/templates/*.yaml".

Is there any way to tell kubernetes-tools extension to step back and ignore "templates/*.yaml" pattern so that vscode will use our schema for those files?

lstocchi commented 1 year ago

Hi @yury-kozlov , sorry for the late response. Unfortunately there is no such a command atm. I think the only way would be to add the # vscode-kubernetes-tools: exclude comment at the beginning of any yaml file. Can you please try on some files and let us know if this solve your problem? If so, we could extend the feature to exclude a whole subfolder in future.

You can find a more detailed description at https://github.com/vscode-kubernetes-tools/vscode-kubernetes-tools#yaml-processing-directives

yury-kozlov commented 1 year ago

@lstocchi thank you for your reply.

For some reason this didn't work, I added the comment but k8s extension still intervenes in YAML (you can see its popup below). image Removing spaces, reloading extension/vscode didn't help (only if I disable the ext, I start seeing my schema validation).

Besides this, I'm not sure this is the best option to put ignore comment on every file. If there was an option to skip the whole folder (for example by putting some .ignore file inside it), that would be great.

lstocchi commented 1 year ago

@yury-kozlov i see. I didn't get the problem in the first message, sorry. This is related to helm which is something i don't use at all.

Not sure what we can actually do. The extension registers the helm language with a defined set of filenamePatterns so we should find a way to update them programmatically. @Tatsinnit any idea?

Tatsinnit commented 1 year ago

Thanks @yury-kozlov and @lstocchi . Cool, I can play around with this tomorrow and will loop back once I found any workaround or solution for this. Thanks heaps

Tatsinnit commented 1 year ago

Hiya @yury-kozlov, I've tried few things and tried debugging but upon adding # vscode-kubernetes-tools: exclude on top of the file I was not able to get the popup because the shouldSkip logic within Kubernetes extension skips here are few screenshots below. ☕️🙏

Please let me know if you have exact use-case steps I can follow and try and replicate your scenario.

Please Note: below is the screenshot where I have taken parts of code path which gets triggered, I will see if I can record gif for clarity.

cc: @lstocchi

Will await if you can share more guidance around creating the exact steps please and I can play around with it, really appreciate your pings and thanks heaps.

Helpful screenshots:

Screenshot 2023-06-08 at 11 47 23 PM

shouldSkip call

Screenshot 2023-06-08 at 11 44 43 PM

shouldProvideSchemFor call - eventually detects and return false.

Screenshot 2023-06-08 at 11 44 08 PM

The sample settings I used for YAML extension.

Screenshot 2023-06-09 at 12 00 31 AM
yury-kozlov commented 1 year ago

@Tatsinnit thank you for a thorough check! One question: what is the path of yaml file you are testing (with exclude comment)? On my machine the issue happened when the file is stored inside "templates" folder.

lstocchi commented 1 year ago

@Tatsinnit i guess that the problem is if the file is under a templates folder. You can see that the plugin intervenes in the yaml because the file icon changes. I suppose we should find a way to avoid registering the helmCompletionProvider when required.

Tatsinnit commented 1 year ago

❤️☕️💡 Thank you both! Aha @lstocchi and @yury-kozlov I think I got it now, the moment file is under the template folder the icon instantly changes, (With extension enable)

So, it is surely not the shouldProvideSchemaFor aka consideration-filter issue it is the helmCompletionProvider issue which is part of the extension and gets added way top in the stack. As mentioned the screenshot might add more clarity and as to explain why templates file are behaving that way.

Screenshot 2023-06-12 at 6 03 05 PM Screenshot 2023-06-12 at 6 53 37 PM

Proposed Solution: (something I could try)

Screenshot 2023-06-12 at 7 41 45 PM

Thank you so much! WDYT?

lstocchi commented 1 year ago

Proposed Solution: (something I could try)

  • I like your idea about finding a way to skip the helmCompletionProvider enablement - shall we do it via some new user setting ~> aka something like vs-kubernetes.skip-helm-completion: - if set to true we can test the skipping of filter bit (Which when I tested locally does work and identify the file as right file.
Screenshot 2023-06-12 at 7 41 45 PM

Thank you so much! WDYT?

Yes I was thinking about having a setting to change the default behavior but i'm not sure it's actually possible.

Tatsinnit commented 1 year ago

Yes I was thinking about having a setting to change the default behavior but i'm not sure it's actually possible.

💡 Sounds good, I tried something, so the setting which needs to be wet for user is : vs-kubernetes.skip-helm-provider-completion - to true for skipping the helmcompletionprovider code not to trigger.

kind ping to, @yury-kozlov , @lstocchi , @peterbom for a quick test for this extension.vsix linked below, all you need to do is to rename this file and remove the end .zip so that it can be used for local upload from the vsix - (Please do restart the vscode just to make sure anything cached is cleansed once six and the environment var is set.)

For test - vscode-kubernetes-tools-1.3.13-testskiphelmcompletion1.vsix.zip

Screenshot 2023-06-15 at 3 15 38 PM

Thanks guys, I am unsure of exact steps so I am sure this now skips the helm completion code call but what is the behaviour impact will be. ☕️

peterbom commented 1 year ago

Hey all - I'd really like to confirm the specific behaviour we're looking to avoid. There are a few features I can see that indicate a difference between the file types:

To me, it doesn't look as if the above are all part of one single feature that can be turned on/off. When I have the Kubernetes extension installed, I see the file-type indicator and the auto-completion, but not the schema validation.

@lstocchi, @Tatsinnit: do either of you get the schema validation tooltips, and does the fact that I don't give you any hint as to how we might be able to turn them off?

peterbom commented 1 year ago

@yury-kozlov - could you sanity-check my comment above? Is it definitely the tooltip in your screenshot that indicates that schema validation is happening?

Please let us know if @Tatsinnit's .vsix helps at all.

Because I can't reproduce this myself, I'm wondering if this might be down to a combination of extensions being active (the K8s one plus something else, maybe Helm related?). I'm imagining something like the K8s extension identifies the file as being a helm template (because of a file path pattern), but something else does the schema validation.

yury-kozlov commented 1 year ago

Unfortunately custom built vsix didn't help, after installing vscode-kubernetes-tools-1.3.13-testskiphelmcompletion1.vsix in vscode on my windows machine (and restarting all instances of vscode), I still oberve the same behavior. I even went further and disabled all extensions except for those two: kubernetes-tools and red hat yaml, restarted vs code but still the same. btw, I don't have helm extension.

yury-kozlov commented 1 year ago

Is it definitely the tooltip in your screenshot that indicates that schema validation is happening?

After installing the custom vsix I see that intellisense (autocomplete of k8s extension) is still working, the tooltip is shown, and the icon is blueish square while my own schema validation is suppressed:

After I disable kubernetes extension and reload I see again my schema validation/tooltips as expected: image

horihel commented 1 year ago

just found this issue and wanted to mention: the extension setting language to "helm-template" for anything inside a "templates" folder also breaks SOPS (@signageos/vscode-sops) for us. The ability to disable this behaviour per-workspace would help us greatly.