Skip to content

Commit ef18465

Browse files
author
Venkata Subramani Renduchintala
committed
feat(sre): add Helm, Bash and Dockerfile LSP, linting and formatting
- helm_ls: enable with internal yamlls integration for templates - shellcheck via nvim-lint for sh/bash filetypes - hadolint via nvim-lint for dockerfile filetype - shfmt replaces beautysh as sh formatter in conform - treesitter: add bash and gotmpl parsers - CI: extend parser install and validation to cover bash, gotmpl, dockerfile - fixtures: script.sh, Dockerfile, helm_deployment.yaml
1 parent 3813874 commit ef18465

9 files changed

Lines changed: 123 additions & 10 deletions

File tree

lua/lsp/init.lua

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,33 @@ if lspconfig then
189189
})
190190

191191
-- Helm Language Server
192-
--[[ lspconfig("helm_ls", {
193-
autostart = false,
192+
lspconfig("helm_ls", {
193+
autostart = true,
194194
capabilities = capabilities,
195-
}) --]]
195+
settings = {
196+
['helm-ls'] = {
197+
logLevel = "info",
198+
valuesFiles = {
199+
mainValuesFile = "values.yaml",
200+
lintOverlayValuesFile = "values.lint.yaml",
201+
additionalValuesFilesGlobPattern = "values*.yaml",
202+
},
203+
yamlls = {
204+
enabled = true,
205+
diagnosticsLimit = 50,
206+
showDiagnosticsDirectly = false,
207+
path = "yaml-language-server",
208+
config = {
209+
schemas = {
210+
kubernetes = "templates/**",
211+
},
212+
completion = true,
213+
hover = true,
214+
},
215+
},
216+
},
217+
},
218+
})
196219

197220
-- Json Language Server
198221
lspconfig("jsonls", {

lua/plugins/configs/conform.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ return {
2424

2525
formatters_by_ft = {
2626
lua = { "stylua" },
27-
sh = { "beautysh" },
27+
sh = { "shfmt" },
2828
json = { "jq" },
2929
html = { "prettierd", "prettier", "tidy", stop_after_first = true },
3030
css = { "prettierd", "prettier", "tidy", stop_after_first = true },

lua/plugins/configs/mason.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ return {
2222
ensure_installed = vim.env.CI and {} or {
2323
"gopls",
2424
"terraform-ls",
25+
"helm_ls",
2526
"ansiblels",
2627
"awk_ls",
2728
"bashls",
@@ -59,6 +60,9 @@ return {
5960
quiet_mode = false,
6061
ensure_installed = vim.env.CI and {} or {
6162
"tflint",
63+
"shellcheck",
64+
"shfmt",
65+
"hadolint",
6266
"actionlint",
6367
"ansible-lint",
6468
"api-linter",
@@ -88,10 +92,13 @@ return {
8892
-- Wire up nvim-lint: which linters run per filetype and when
8993
local lint = require("lint")
9094
lint.linters_by_ft = {
91-
yaml = { "yamllint" },
95+
yaml = { "yamllint" },
96+
sh = { "shellcheck" },
97+
bash = { "shellcheck" },
98+
dockerfile = { "hadolint" },
9299
}
93100
vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter" }, {
94-
pattern = { "*.yaml", "*.yml" },
101+
pattern = { "*.yaml", "*.yml", "*.sh", "Dockerfile", "dockerfile" },
95102
callback = function()
96103
lint.try_lint()
97104
end,

lua/plugins/configs/treesitter.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ return {
4141
"go",
4242
"terraform",
4343
"hcl",
44+
"bash",
45+
"gotmpl",
4446
},
4547
refactor = {
4648
highlight_definitions = {

test/fixtures/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM debian:12-slim AS base
2+
3+
ARG APP_VERSION=1.0.0
4+
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends \
7+
ca-certificates \
8+
curl \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
WORKDIR /app
12+
13+
FROM base AS builder
14+
15+
COPY . .
16+
17+
RUN chmod +x ./entrypoint.sh
18+
19+
FROM base AS runtime
20+
21+
COPY --from=builder /app/entrypoint.sh /usr/local/bin/entrypoint.sh
22+
23+
ENV APP_VERSION=${APP_VERSION}
24+
25+
EXPOSE 8080
26+
27+
USER nobody
28+
29+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

test/fixtures/helm_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: {{ include "mychart.fullname" . }}
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
{{- include "mychart.labels" . | nindent 4 }}
8+
spec:
9+
replicas: {{ .Values.replicaCount }}
10+
selector:
11+
matchLabels:
12+
{{- include "mychart.selectorLabels" . | nindent 6 }}
13+
template:
14+
metadata:
15+
labels:
16+
{{- include "mychart.selectorLabels" . | nindent 8 }}
17+
spec:
18+
containers:
19+
- name: {{ .Chart.Name }}
20+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
21+
imagePullPolicy: {{ .Values.image.pullPolicy }}
22+
ports:
23+
- name: http
24+
containerPort: {{ .Values.service.port }}
25+
protocol: TCP
26+
{{- if .Values.resources }}
27+
resources:
28+
{{- toYaml .Values.resources | nindent 12 }}
29+
{{- end }}

test/fixtures/script.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
NAMESPACE="${1:-default}"
5+
6+
echo "Checking pods in namespace: ${NAMESPACE}"
7+
8+
pods=$(kubectl get pods -n "${NAMESPACE}" --no-headers 2>/dev/null | wc -l)
9+
10+
if [[ "${pods}" -eq 0 ]]; then
11+
echo "No pods found in ${NAMESPACE}"
12+
exit 1
13+
fi
14+
15+
echo "Found ${pods} pod(s)"
16+
17+
for pod in $(kubectl get pods -n "${NAMESPACE}" -o jsonpath='{.items[*].metadata.name}'); do
18+
status=$(kubectl get pod "${pod}" -n "${NAMESPACE}" -o jsonpath='{.status.phase}')
19+
echo " ${pod}: ${status}"
20+
done

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', 'yaml' }
4+
local langs = { 'go', 'terraform', 'hcl', 'yaml', 'bash', 'gotmpl', 'dockerfile' }
55
local parser_dir = vim.fn.stdpath('data') .. '/lazy/nvim-treesitter/parser/'
66

77
local function installed(lang)

test/validate_treesitter.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ local function test_parser(lang, filepath)
3737
end
3838

3939
local cfg = '/home/dev/.config/nvim'
40-
test_parser('go', cfg .. '/test/fixtures/hello.go')
41-
test_parser('terraform', cfg .. '/test/fixtures/main.tf')
42-
test_parser('yaml', cfg .. '/test/fixtures/deployment.yaml')
40+
test_parser('go', cfg .. '/test/fixtures/hello.go')
41+
test_parser('terraform', cfg .. '/test/fixtures/main.tf')
42+
test_parser('yaml', cfg .. '/test/fixtures/deployment.yaml')
43+
test_parser('bash', cfg .. '/test/fixtures/script.sh')
44+
test_parser('gotmpl', cfg .. '/test/fixtures/helm_deployment.yaml')
45+
test_parser('dockerfile', cfg .. '/test/fixtures/Dockerfile')
4346

4447
if #errors > 0 then
4548
for _, err in ipairs(errors) do

0 commit comments

Comments
 (0)