Skip to content

Commit 45ac5b2

Browse files
(devena-mono) Propagate stderr from kustomize build
The goal here is to propagate warnings (which is all that's assumed to written to stderr) so they can e.g. be presented during PRs. For this reason the warnings are written between two delimiters so they can always be unambiguously parsed. Tests weren't added since these would depend on the version of `kustomize` being run and I don't think it's worth the effort trying to add setup around that just for this small behaviour change. Sample output (by adding a `patchesStrategicMerge:` to one of our existing manifests): Found kustomization build dir: services/opslevel-k8s-reconciler/k8s-manifests/base Running `kustomize build services/opslevel-k8s-reconciler/k8s-manifests/base` Built: services/opslevel-k8s-reconciler/k8s-manifests/base ---start Warnings--- Warnings for: services/opslevel-k8s-reconciler/k8s-manifests/base # Warning: 'patchesStrategicMerge' is deprecated. Please use 'patches' instead. Run 'kustomize edit fix' to update your Kustomization automatically. ---End warnings--- Ticket: DENA-247
1 parent 1ebeb5c commit 45ac5b2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

kustomize-build-dirs/main.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,20 @@ func buildManifests(kustomizationRoots []string, rootDir string) (map[string]str
235235
kustomizationRoot := kustomizationRoots[i]
236236
fmt.Printf("Running `kustomize build %s`\n", kustomizationRoot)
237237
group.Go(func() error {
238-
manifest, err := kustomizeBuild(filepath.Join(rootDir, kustomizationRoot))
238+
manifest, stderr, err := kustomizeBuild(filepath.Join(rootDir, kustomizationRoot))
239239
if err != nil {
240240
return err
241241
}
242242
mutex.Lock()
243243
fmt.Printf("Built: %s\n", kustomizationRoot)
244+
if stderr != "" {
245+
fmt.Fprintf(
246+
os.Stderr,
247+
"---start Warnings---\nWarnings for: %s\n%s---End warnings---\n",
248+
kustomizationRoot,
249+
stderr,
250+
)
251+
}
244252
manifestMap[kustomizationRoot] = manifest
245253
defer mutex.Unlock()
246254
return nil
@@ -252,7 +260,7 @@ func buildManifests(kustomizationRoots []string, rootDir string) (map[string]str
252260
return manifestMap, nil
253261
}
254262

255-
func kustomizeBuild(path string) (string, error) {
263+
func kustomizeBuild(path string) (string, string, error) {
256264
var stdout strings.Builder
257265
var stderr strings.Builder
258266
args := []string{"build", path}
@@ -261,15 +269,15 @@ func kustomizeBuild(path string) (string, error) {
261269
cmd.Stderr = &stderr
262270

263271
if err := cmd.Run(); err != nil {
264-
return "", fmt.Errorf(
272+
return "", "", fmt.Errorf(
265273
"Error running 'kustomize %s': %v\nstderr: %s",
266274
strings.Join(args, " "),
267275
err,
268276
stderr.String(),
269277
)
270278
}
271279

272-
return stdout.String(), nil
280+
return stdout.String(), stderr.String(), nil
273281
}
274282

275283
func writeManifest(manifest string, outDir string, manifestPath string) error {

0 commit comments

Comments
 (0)