Skip to content

Commit

Permalink
walk some more kustomize paths
Browse files Browse the repository at this point in the history
  • Loading branch information
djeebus committed Nov 17, 2023
1 parent 6b1a86b commit 264f54c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pkg/config/walk_kustomize_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ 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")

var (
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"`
}
)

Expand Down Expand Up @@ -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
}
23 changes: 23 additions & 0 deletions pkg/config/walk_kustomize_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func TestKustomizeWalking(t *testing.T) {
return []byte(s)
}

kustomizeBaseName = "kustomize-base"
kustomizeBasePath = "test/base"

kustomizeApp1Name = "kustomize-app"
kustomizeApp1Path = "test/app"

Expand All @@ -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
Expand All @@ -36,6 +42,12 @@ resources:

"test/app2/kustomization.yaml": {
Data: toBytes(`
patchesStrategicMerge:
- patch.yaml
patchesJson6902:
- path: patch2.yaml
resources:
- file1.yaml
- ../overlays/base
Expand Down Expand Up @@ -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)
Expand All @@ -81,6 +94,10 @@ resources:
"test/app/overlays/dev": {
kustomizeApp1Name,
},
"test/base": {
kustomizeBaseName,
kustomizeApp1Name,
},
"test/overlays/base": {
kustomizeApp1Name,
kustomizeApp2Name,
Expand All @@ -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,
Expand Down

0 comments on commit 264f54c

Please sign in to comment.