Skip to content

Commit f919002

Browse files
author
Venkata Subramani Renduchintala
committed
feat(sre): add Kubernetes YAML linting and schema validation
Enable yamlls with Kubernetes schema (schemaStore) for inline diagnostics on manifest files in common SRE paths (manifests/, k8s/, deploy/, etc.). Wire up nvim-lint with yamllint for YAML syntax checking on save/enter. Disable cmp completion for YAML buffers — diagnostics only, no autocomplete. Add deployment.yaml fixture and extend CI treesitter tests to cover yaml.
1 parent 7b6f1d9 commit f919002

6 files changed

Lines changed: 75 additions & 3 deletions

File tree

lua/autocmds.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ vim.api.nvim_create_autocmd("FileType", {
4545
end,
4646
})
4747

48+
-- Disable cmp autocompletion for YAML — we want linting/diagnostics only
49+
vim.api.nvim_create_autocmd("FileType", {
50+
pattern = "yaml",
51+
callback = function()
52+
require("cmp").setup.buffer({ enabled = false })
53+
end,
54+
})
55+
4856
-- Disable automatic line breaks
4957
vim.api.nvim_create_autocmd("FileType", {
5058
pattern = "*",

lua/lsp/init.lua

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,32 @@ if lspconfig then
114114
capabilities = capabilities,
115115
})
116116

117-
-- YAMLs
117+
-- YAMLs — diagnostics only, no completion
118118
lspconfig("yamlls", {
119+
autostart = true,
119120
capabilities = capabilities,
120-
autostart = false,
121+
settings = {
122+
yaml = {
123+
validate = true,
124+
hover = true,
125+
completion = false,
126+
schemaStore = {
127+
enable = true,
128+
url = "https://www.schemastore.org/api/json/catalog.json",
129+
},
130+
schemas = {
131+
-- Kubernetes manifests in common SRE directory layouts
132+
kubernetes = {
133+
"manifests/**/*.yaml",
134+
"k8s/**/*.yaml",
135+
"kubernetes/**/*.yaml",
136+
"deploy/**/*.yaml",
137+
"templates/**/*.yaml",
138+
"chart/templates/**/*.yaml",
139+
},
140+
},
141+
},
142+
},
121143
})
122144

123145
-- CMake Language Server

lua/plugins/configs/mason.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ return {
8484
},
8585
ignore_install = {},
8686
})
87+
88+
-- Wire up nvim-lint: which linters run per filetype and when
89+
local lint = require("lint")
90+
lint.linters_by_ft = {
91+
yaml = { "yamllint" },
92+
}
93+
vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter" }, {
94+
pattern = { "*.yaml", "*.yml" },
95+
callback = function()
96+
lint.try_lint()
97+
end,
98+
})
8799
end,
88100
},
89101
{

test/fixtures/deployment.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: hello-app
5+
namespace: default
6+
labels:
7+
app: hello-app
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app: hello-app
13+
template:
14+
metadata:
15+
labels:
16+
app: hello-app
17+
spec:
18+
containers:
19+
- name: hello-app
20+
image: nginx:1.25
21+
ports:
22+
- containerPort: 80
23+
resources:
24+
requests:
25+
cpu: "100m"
26+
memory: "128Mi"
27+
limits:
28+
cpu: "250m"
29+
memory: "256Mi"

test/install_parsers.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Headless treesitter parser installer for CI.
22
-- Uses TSInstall! + vim.wait() polling parser .so files on disk.
33
-- Exit code 1 on timeout so the CI step fails visibly.
4-
local langs = { 'go', 'terraform', 'hcl' }
4+
local langs = { 'go', 'terraform', 'hcl', 'yaml' }
55
local parser_dir = vim.fn.stdpath('data') .. '/lazy/nvim-treesitter/parser/'
66

77
local function installed(lang)

test/validate_treesitter.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ end
3939
local cfg = '/home/dev/.config/nvim'
4040
test_parser('go', cfg .. '/test/fixtures/hello.go')
4141
test_parser('terraform', cfg .. '/test/fixtures/main.tf')
42+
test_parser('yaml', cfg .. '/test/fixtures/deployment.yaml')
4243

4344
if #errors > 0 then
4445
for _, err in ipairs(errors) do

0 commit comments

Comments
 (0)