Skip to content

Collection of VS Code compatible snippets focusing on Kubernetes@Home usage

License

Notifications You must be signed in to change notification settings

budimanjojo/k8s-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes Snippets

📖  Overview

This repository contains VSCode compatible snippets for Kubernetes manifests. The goal is to make writing k8s manifests easier without having to configure yaml-language-server. I work with k8s manifests a lot and telling yaml-language-server to load the correct schema based on filename is painful.

This solves a lot of problem for me:

  • I can preload a schema using inlined schema.
  • I can load schema for each kind instead of using one big schema for all native manifests (YLS default behavior).
  • I don't need to rewrite or copypasta same codes again and again.
  • I can create a dummy manifest painlessly.
  • It can improve code consistency.

🔧  Usage

I based this repo from friendly-snippets. So, this should work with what you can use friendly-snippets with, e.g:

This should also work with VSCode, according to their Snippet Guide.

📥  Installation

You can install this into vim or neovim using your plugin manager, e.g:

-- Packer
use "budimanjojo/k8s-snippets"

-- Plug
Plug 'budimanjojo/k8s-snippets'

-- If you're using coc.nvim, you can use:
CocInstall https://github.com/budimanjojo/k8s-snippets@master

❓  FAQ

Where is the schema url coming from?

For native kubernetes manifests (e.g kubernetes.io/v1), the schema is from here which is the default for kubernetes in yaml-language-server too. For Fluxcd manifests, the schema is from here. For some CRDs, I use this GH workflow (thanks to Devin) to publish schemas of CRDs deployed in my cluster which you can browse at https://schemas.budimanjojo.com/<kind>_<apiVersion>.json. If you want to add more snippets here, make sure you have the schema for it too.

Why are u not using x spaces for indentation?

I use the 2 spaces for all yaml indentations, including dictionaries. Unfortunately, I don't think there's anything I can do to please everybody.

Why don't you merge this with friendly-snippets?

Because not everybody like having inlined schema glued in the snippet, and friendly-snippets's goal is different. Think of it like friendly-snippet is a general public collection while this is for people like me that write a lot of k8s manifests and are using yaml-language-server.

Why is the snippets provided for xxx apiVersion doesn't include xxx kind?

I have a lot of CRDs that I never have to write manifest for (i.e resource that should be managed by the operator or helm). For those manifests, I don't feel the need to write a snippet for. If you have stuffs that you really need, feel free to create a Pull Request here.

☕  Acknowledgements

Thanks to:

About

Collection of VS Code compatible snippets focusing on Kubernetes@Home usage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published