Updating Visual Studio Code’s Kubernetes API Awareness
CloudAfter attempting (and failing) to get Sublime Text to have some of the same “intelligence” that Visual Studio Code has with certain languages, I finally stopped trying to make Sublime Text work for me and just went back to using Code full-time. As I mentioned in this earlier post, now that I’ve finally solved how Code handles wrapping text in brackets and braces and the like I’m much happier. (It’s the small things in life.) Now I’ve moved on to tackling how to update Code’s Kubernetes API awareness.
Code’s awareness of the Kubernetes API comes via the YAML extension by Red Hat, and uses the yaml-language-server
project found in this GitHub repository. (This is the same language server I was trying to get working with Sublime Text via LSP.) Note that I tested this procedure with version 0.7.2 of the extension; files may be in different locations or have different contents in other versions.
The information in this post is based heavily on this article by Josh Rosso, who some of you may know from his guest appearances on TGIK. I’ve adapted the information in Josh’s post to apply to the macOS version of Visual Studio Code.
Here’s how to update the extension to use a schema for Kubernetes 1.17 (the extension uses a schema for Kubernetes 1.14 by default):
- With Code running, the extension installed and enabled, and a YAML file open, verify the location of the extension by running
ps auxwww | grep yaml-language-server
. The path should be something like$HOME/.vscode/extensions/redhat.vscode-yaml-0.7.2/node_modules/yaml-language-server/out/server/src/
(where$HOME
represents your home directory). - Close and exit Code. Although it shouldn’t matter if it’s running, I prefer not to take any chances.
- Use an editor (other than Code!) to edit the
schemaUrls.js
file found in thelanguageservice/utils
directory under the directory identified in step 1. The full path toschemaUrls.js
should be something like$HOME/.vscode/extensions/redhat.vscode-yaml-0.7.2/node_modules/yaml-language-server/out/server/src/languageservice/utils
. - Find the line that starts with
exports.KUBERNETES_SCHEMA_URL
, and change the Kubernetes version later in that line from1.14.0
to1.17.0
. - Save and exit the file, and then restart Code.
That’s it—Code should now use an API schema for Kubernetes 1.17.0. Note that this still won’t help Code be aware of CustomResourceDefinitions like those used by Cluster API, and so the YAML language server will still flag those lines as “errors.” I haven’t found a workaround for that yet, but I’ll keep looking.
Hit me up on Twitter if you have any questions. I hope this helps!
…
Read MoreUpdating Visual Studio Code’s Kubernetes API Awareness