Skip to content

Commit

Permalink
support kustomize components
Browse files Browse the repository at this point in the history
  • Loading branch information
djeebus committed Jan 9, 2025
1 parent 38a515c commit bb6802e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/appdir/walk_kustomize_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func walkKustomizeFiles(result *AppDirectory, fs fs.FS, appName, dirpath string)

kustomize struct {
Bases []string `yaml:"bases"`
Components []string `yaml:"components"`
Resources []string `yaml:"resources"`
PatchesJson6902 []patchJson6902 `yaml:"patchesJson6902"`
PatchesStrategicMerge []string `yaml:"patchesStrategicMerge"`
Expand All @@ -66,7 +67,7 @@ func walkKustomizeFiles(result *AppDirectory, fs fs.FS, appName, dirpath string)

for _, resource := range kustomize.Resources {
if isGoGetterIsh(resource) {
// no reason to walk remote files, since they can't be changed
// no reason to walk remote files, since they can't be changed in this PR
continue
}

Expand Down Expand Up @@ -110,6 +111,17 @@ func walkKustomizeFiles(result *AppDirectory, fs fs.FS, appName, dirpath string)
}
}

for _, componentPath := range kustomize.Components {
if isGoGetterIsh(componentPath) {
continue
}
relPath := filepath.Join(dirpath, componentPath)
result.addDir(appName, relPath)
if err = walkKustomizeFiles(result, fs, appName, relPath); err != nil {
log.Warn().Err(err).Msgf("failed to read kustomize.yaml from components in %s", relPath)
}
}

for _, patchFile := range kustomize.PatchesStrategicMerge {
relPath := filepath.Join(dirpath, patchFile)
result.addFile(appName, relPath)
Expand Down
12 changes: 12 additions & 0 deletions pkg/appdir/walk_kustomize_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ resources:
- file1.yaml
- ../overlays/base
- /common/overlays/prod
components:
- ../components/one/
- ../components/two/
`)},
"test/overlays/base/kustomization.yaml": {
Data: toBytes(`
Expand All @@ -73,6 +77,8 @@ resources:
"common/overlays/prod/kustomization.yaml": {Data: toBytes("hello: world")},
"test/overlays/base/some-file1.yaml": {Data: toBytes("hello: world")},
"test/overlays/base/some-file2.yaml": {Data: toBytes("hello: world")},
"test/components/one/kustomization.yaml": {Data: toBytes("hello: world")},
"test/components/two/kustomization.yaml": {Data: toBytes("hello: world")},
}
)

Expand Down Expand Up @@ -135,6 +141,12 @@ resources:
kustomizeApp1Name,
kustomizeApp2Name,
},
"test/components/one": {
kustomizeApp2Name,
},
"test/components/two": {
kustomizeApp2Name,
},
}, appdir.appDirs)

assert.Equal(t, map[string][]string{
Expand Down

0 comments on commit bb6802e

Please sign in to comment.