Scott's Weblog The weblog of an IT pro focusing on cloud computing, Kubernetes, Linux, containers, and networking

Updating Visual Studio Code's Kubernetes API Awareness

After 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):

  1. 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).
  2. Close and exit Code. Although it shouldn’t matter if it’s running, I prefer not to take any chances.
  3. Use an editor (other than Code!) to edit the schemaUrls.js file found in the languageservice/utils directory under the directory identified in step 1. The full path to schemaUrls.js should be something like $HOME/.vscode/extensions/redhat.vscode-yaml-0.7.2/node_modules/yaml-language-server/out/server/src/languageservice/utils.
  4. Find the line that starts with exports.KUBERNETES_SCHEMA_URL, and change the Kubernetes version later in that line from 1.14.0 to 1.17.0.
  5. 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!

Metadata and Navigation

Be social and share this post!