Skip to content

Commit

Permalink
refactor: render or skip stack based on stackConfigs is provided or n…
Browse files Browse the repository at this point in the history
…ot (#83)
  • Loading branch information
howieyuen committed Jul 5, 2022
1 parent f0cc4c4 commit b8ba9fc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions pkg/scaffold/internal_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ func Test_readIntoFS(t *testing.T) {
"internal/deployment-single-stack/README.md",
"internal/deployment-single-stack/base",
"internal/deployment-single-stack/base/base.k",
"internal/deployment-single-stack/dev",
"internal/deployment-single-stack/dev/ci-test",
"internal/deployment-single-stack/dev/ci-test/settings.yaml",
"internal/deployment-single-stack/dev/kcl.yaml",
"internal/deployment-single-stack/dev/main.k",
"internal/deployment-single-stack/dev/stack.yaml",
"internal/deployment-single-stack/kusion.yaml",
"internal/deployment-single-stack/project.yaml",
"internal/deployment-single-stack/stack",
"internal/deployment-single-stack/stack/ci-test",
"internal/deployment-single-stack/stack/ci-test/settings.yaml",
"internal/deployment-single-stack/stack/kcl.yaml",
"internal/deployment-single-stack/stack/main.k",
"internal/deployment-single-stack/stack/stack.yaml",
}
assert.Equal(t, want, got)
}
26 changes: 13 additions & 13 deletions pkg/scaffold/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,19 +459,19 @@ func RenderFSTemplate(srcFS afero.Fs, srcDir string, destFS afero.Fs, destDir st
for k, v := range tc.ProjectConfig {
configs[k] = v
}
// Walk each stack
for stackName, stackConfigs := range tc.StacksConfig {
// Use stack name as sub dir
dest = filepath.Join(destDir, stackName)
// Merge and override project config
for k, v := range stackConfigs {
configs[k] = v
}
// Walk stack dir with merged configs
err = walkFiles(srcFS, src, destFS, dest, configs)
if err != nil {
return err
}
// Skip if stackConfigs are not provided
stackConfigs, exits := tc.StacksConfig[fileInfo.Name()]
if !exits {
continue
}
// Merge and override project config
for k, v := range stackConfigs {
configs[k] = v
}
// Walk stack dir with merged configs
err = walkFiles(srcFS, src, destFS, dest, configs)
if err != nil {
return err
}
} else {
// Stack dir nested in 3rd level or even deeper, eg: meta_app/deployed_unit/stack_dir
Expand Down

0 comments on commit b8ba9fc

Please sign in to comment.