Skip to content

Commit d133013

Browse files
janiszclaude
andcommitted
Upgrade k8s-manifests-lib to v0.1.2 for source file tracking
Enable source annotations in the Kustomize renderer to track the actual source files where Kubernetes objects are defined. This improves error reporting by showing the real file paths instead of synthetic paths. Before: tests/testdata/mykustomize/deployment-kustomize-test-deployment.yaml After: /path/to/tests/testdata/mykustomize/base/deployment.yaml This makes it easier for users to find and fix lint errors in their Kustomize configurations. Addresses PR review comment: #1045 (comment) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fbb9949 commit d133013

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/go-viper/mapstructure/v2 v2.4.0
1111
github.com/goccy/go-yaml v1.18.0
1212
github.com/google/cel-go v0.26.1
13+
github.com/lburgazzoli/k8s-manifests-lib v0.1.2
1314
github.com/mitchellh/go-homedir v1.1.0
1415
github.com/mitchellh/mapstructure v1.5.0
1516
github.com/openshift/api v0.0.0-20230406152840-ce21e3fe5da2
@@ -86,7 +87,6 @@ require (
8687
github.com/klauspost/compress v1.18.0 // indirect
8788
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
8889
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
89-
github.com/lburgazzoli/k8s-manifests-lib v0.1.1 // indirect
9090
github.com/lib/pq v1.10.9 // indirect
9191
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
9292
github.com/mattn/go-colorable v0.1.13 // indirect
@@ -103,7 +103,6 @@ require (
103103
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
104104
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
105105
github.com/onsi/ginkgo/v2 v2.25.1 // indirect
106-
github.com/onsi/gomega v1.38.2 // indirect
107106
github.com/opencontainers/go-digest v1.0.0 // indirect
108107
github.com/opencontainers/image-spec v1.1.1 // indirect
109108
github.com/pelletier/go-toml/v2 v2.2.4 // indirect

go.sum

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
22
cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
33
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
44
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
5+
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
56
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
67
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk=
78
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
89
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
910
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
1011
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
1112
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
13+
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
14+
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
1215
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
1316
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
1417
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
@@ -134,6 +137,7 @@ github.com/go-openapi/swag/typeutils v0.25.1 h1:rD/9HsEQieewNt6/k+JBwkxuAHktFtH3
134137
github.com/go-openapi/swag/typeutils v0.25.1/go.mod h1:9McMC/oCdS4BKwk2shEB7x17P6HmMmA6dQRtAkSnNb8=
135138
github.com/go-openapi/swag/yamlutils v0.25.1 h1:mry5ez8joJwzvMbaTGLhw8pXUnhDK91oSJLDPF1bmGk=
136139
github.com/go-openapi/swag/yamlutils v0.25.1/go.mod h1:cm9ywbzncy3y6uPm/97ysW8+wZ09qsks+9RS8fLWKqg=
140+
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
137141
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
138142
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
139143
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
@@ -190,6 +194,10 @@ github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI
190194
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
191195
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
192196
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
197+
github.com/itchyny/gojq v0.12.17 h1:8av8eGduDb5+rvEdaOO+zQUjA04MS0m3Ps8HiD+fceg=
198+
github.com/itchyny/gojq v0.12.17/go.mod h1:WBrEMkgAfAGO1LUcGOckBl5O726KPp+OlkKug0I/FEY=
199+
github.com/itchyny/timefmt-go v0.1.7 h1:xyftit9Tbw+Dc/huSSPJaEmX1TVL8lw5vxjJLK4GMMA=
200+
github.com/itchyny/timefmt-go v0.1.7/go.mod h1:5E46Q+zj7vbTgWY8o5YkMeYb4I6GeWLFnetPy5oBrAI=
193201
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
194202
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
195203
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -210,8 +218,10 @@ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq
210218
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
211219
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
212220
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
213-
github.com/lburgazzoli/k8s-manifests-lib v0.1.1 h1:Hxd8FMUgWl87PNAmlwK49UF3n82wPjw7DtjcbodZvxM=
214-
github.com/lburgazzoli/k8s-manifests-lib v0.1.1/go.mod h1:KbU9qYnaBuQ9pzy5eouAouaA/VdvKB1I00y20NEqxj8=
221+
github.com/lburgazzoli/gomega-matchers v0.1.1 h1:it5XiuJGJB2Noq1KayamTgEe7Ls2/Cycezt3g6xyuo4=
222+
github.com/lburgazzoli/gomega-matchers v0.1.1/go.mod h1:sTPi8iTNViVEDJujnMzYicDshmo6G4rl9+gF/O02/V8=
223+
github.com/lburgazzoli/k8s-manifests-lib v0.1.2 h1:MraZxEA1qQK1QqHMJ9ztMqcOpwzKDVlxou3OnES+au0=
224+
github.com/lburgazzoli/k8s-manifests-lib v0.1.2/go.mod h1:KbU9qYnaBuQ9pzy5eouAouaA/VdvKB1I00y20NEqxj8=
215225
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
216226
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
217227
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
@@ -223,6 +233,7 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
223233
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
224234
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
225235
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
236+
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
226237
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
227238
github.com/miekg/dns v1.1.68 h1:jsSRkNozw7G/mnmXULynzMNIsgY2dHC8LO6U6Ij2JEA=
228239
github.com/miekg/dns v1.1.68/go.mod h1:fujopn7TB3Pu3JM69XaawiU0wqjpL9/8xGop5UrTPps=
@@ -276,6 +287,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
276287
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
277288
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
278289
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
290+
github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY=
291+
github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg=
279292
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.86.1 h1:j/GvU9UxlK5nuUKOWYOY0LRqcfHZl1ffTOa46+00Cys=
280293
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.86.1/go.mod h1:nPk0OteXBkbT0CRCa2oZQL1jRLW6RJ2fuIijHypeJdk=
281294
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
@@ -297,6 +310,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
297310
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
298311
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
299312
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
313+
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
314+
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
300315
github.com/rubenv/sql-migrate v1.8.0 h1:dXnYiJk9k3wetp7GfQbKJcPHjVJL6YK19tKj8t2Ns0o=
301316
github.com/rubenv/sql-migrate v1.8.0/go.mod h1:F2bGFBwCU+pnmbtNYDeKvSuvL6lBVtXDXUUv5t+u1qw=
302317
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=

pkg/lintcontext/parse_yaml.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/bmatcuk/doublestar/v4"
1616
"github.com/lburgazzoli/k8s-manifests-lib/pkg/engine"
1717
"github.com/lburgazzoli/k8s-manifests-lib/pkg/renderer/kustomize"
18+
"github.com/lburgazzoli/k8s-manifests-lib/pkg/types"
1819
ocsAppsV1 "github.com/openshift/api/apps/v1"
1920
ocpSecV1 "github.com/openshift/api/security/v1"
2021
k8sMonitoring "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
@@ -315,10 +316,10 @@ func normalizeDirectoryPaths(renderedFiles map[string]string) map[string]string
315316
}
316317

317318
func (l *lintContextImpl) loadObjectsFromKustomize(dir string, ignorePaths []string) error {
318-
// Create a kustomize engine
319+
// Create a kustomize engine with source annotations enabled
319320
e, err := engine.Kustomize(kustomize.Source{
320321
Path: dir,
321-
})
322+
}, kustomize.WithSourceAnnotations(true))
322323
if err != nil {
323324
l.addInvalidObjects(InvalidObject{Metadata: ObjectMetadata{FilePath: dir}, LoadErr: err})
324325
return nil
@@ -342,8 +343,18 @@ func (l *lintContextImpl) loadObjectsFromKustomize(dir string, ignorePaths []str
342343
continue
343344
}
344345

345-
// Create a file path for the object for reporting purposes
346-
filePath := filepath.Join(dir, fmt.Sprintf("%s-%s.yaml", strings.ToLower(obj.GetKind()), obj.GetName()))
346+
// Extract the source file from annotations if available
347+
filePath := ""
348+
if annotations := obj.GetAnnotations(); annotations != nil {
349+
if sourceFile, ok := annotations[types.AnnotationSourceFile]; ok && sourceFile != "" {
350+
// Prefix with the kustomization directory to show full path
351+
filePath = filepath.Join(dir, sourceFile)
352+
}
353+
}
354+
// Fallback: Create a file path for the object for reporting purposes
355+
if filePath == "" {
356+
filePath = filepath.Join(dir, fmt.Sprintf("%s-%s.yaml", strings.ToLower(obj.GetKind()), obj.GetName()))
357+
}
347358

348359
// Load the object using the existing YAML reader
349360
if err := l.loadObjectsFromReader(filePath, bytes.NewReader(yamlData)); err != nil {

0 commit comments

Comments
 (0)