From 264f54c0186f7e27de9fcb3615866f8b4b54d4fe Mon Sep 17 00:00:00 2001 From: Joe Lombrozo Date: Fri, 17 Nov 2023 16:25:36 -0500 Subject: [PATCH] walk some more kustomize paths --- pkg/config/walk_kustomize_files.go | 24 +++++++++++++++++++++--- pkg/config/walk_kustomize_files_test.go | 23 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/pkg/config/walk_kustomize_files.go b/pkg/config/walk_kustomize_files.go index 52bc60ef..c68a6894 100644 --- a/pkg/config/walk_kustomize_files.go +++ b/pkg/config/walk_kustomize_files.go @@ -11,6 +11,10 @@ import ( "k8s.io/apimachinery/pkg/util/yaml" ) +type patchJson6902 struct { + Path string `yaml:"path"` +} + func walkKustomizeFiles(result *AppDirectory, fs fs.FS, appName, dirpath string) error { kustomizeFile := filepath.Join(dirpath, "kustomization.yaml") @@ -18,9 +22,10 @@ func walkKustomizeFiles(result *AppDirectory, fs fs.FS, appName, dirpath string) err error kustomize struct { - Resources []string `yaml:"resources"` - - PatchesStrategicMerge []string `yaml:"patchesStrategicMerge"` + Bases []string `yaml:"bases"` + Resources []string `yaml:"resources"` + PatchesJson6902 []patchJson6902 `yaml:"patchesJson6902"` + PatchesStrategicMerge []string `yaml:"patchesStrategicMerge"` } ) @@ -71,10 +76,23 @@ func walkKustomizeFiles(result *AppDirectory, fs fs.FS, appName, dirpath string) } } + for _, basePath := range kustomize.Bases { + relPath := filepath.Join(dirpath, basePath) + result.AddDir(appName, relPath) + if err = walkKustomizeFiles(result, fs, appName, relPath); err != nil { + log.Warn().Err(err).Msgf("failed to read kustomize.yaml in %s", relPath) + } + } + for _, patchFile := range kustomize.PatchesStrategicMerge { relPath := filepath.Join(dirpath, patchFile) result.AddFile(appName, relPath) } + for _, patch := range kustomize.PatchesJson6902 { + relPath := filepath.Join(dirpath, patch.Path) + result.AddFile(appName, relPath) + } + return nil } diff --git a/pkg/config/walk_kustomize_files_test.go b/pkg/config/walk_kustomize_files_test.go index bcc114b7..0f1352b3 100644 --- a/pkg/config/walk_kustomize_files_test.go +++ b/pkg/config/walk_kustomize_files_test.go @@ -16,6 +16,9 @@ func TestKustomizeWalking(t *testing.T) { return []byte(s) } + kustomizeBaseName = "kustomize-base" + kustomizeBasePath = "test/base" + kustomizeApp1Name = "kustomize-app" kustomizeApp1Path = "test/app" @@ -25,6 +28,9 @@ func TestKustomizeWalking(t *testing.T) { fs = fstest.MapFS{ "test/app/kustomization.yaml": { Data: toBytes(` +bases: +- ../base + resources: - file1.yaml - ./file2.yaml @@ -36,6 +42,12 @@ resources: "test/app2/kustomization.yaml": { Data: toBytes(` +patchesStrategicMerge: +- patch.yaml + +patchesJson6902: +- path: patch2.yaml + resources: - file1.yaml - ../overlays/base @@ -64,6 +76,7 @@ resources: appdir := NewAppDirectory() appdir.AddAppStub(kustomizeApp1Name, kustomizeApp1Path, false, true) appdir.AddAppStub(kustomizeApp2Name, kustomizeApp2Path, false, true) + appdir.AddAppStub(kustomizeBaseName, kustomizeBasePath, false, true) err = walkKustomizeFiles(appdir, fs, kustomizeApp1Name, kustomizeApp1Path) require.NoError(t, err) @@ -81,6 +94,10 @@ resources: "test/app/overlays/dev": { kustomizeApp1Name, }, + "test/base": { + kustomizeBaseName, + kustomizeApp1Name, + }, "test/overlays/base": { kustomizeApp1Name, kustomizeApp2Name, @@ -105,6 +122,12 @@ resources: "test/file3.yaml": { kustomizeApp1Name, }, + "test/app2/patch2.yaml": { + kustomizeApp2Name, + }, + "test/app2/patch.yaml": { + kustomizeApp2Name, + }, "test/overlays/base/some-file1.yaml": { kustomizeApp1Name, kustomizeApp2Name,