diff --git a/cmd/config/internal/commands/tree.go b/cmd/config/internal/commands/tree.go index 7bc23e008..2b14da271 100644 --- a/cmd/config/internal/commands/tree.go +++ b/cmd/config/internal/commands/tree.go @@ -74,13 +74,17 @@ type TreeRunner struct { structure string } +func (r *TreeRunner) getMatchFilesGlob() []string { + matchFilesGlob := append([]string{ext.KRMFileName()}, kio.DefaultMatch...) + return append(matchFilesGlob, "Kustomization") +} + func (r *TreeRunner) runE(c *cobra.Command, args []string) error { var input kio.Reader var root = "." - matchFilesGlob := append([]string{ext.KRMFileName()}, kio.DefaultMatch...) if len(args) == 1 { root = filepath.Clean(args[0]) - input = kio.LocalPackageReader{PackagePath: args[0], MatchFilesGlob: matchFilesGlob} + input = kio.LocalPackageReader{PackagePath: args[0], MatchFilesGlob: r.getMatchFilesGlob()} } else { input = &kio.ByteReader{Reader: c.InOrStdin()} } diff --git a/cmd/config/internal/commands/tree_test.go b/cmd/config/internal/commands/tree_test.go index 92bcac173..dc0d21508 100644 --- a/cmd/config/internal/commands/tree_test.go +++ b/cmd/config/internal/commands/tree_test.go @@ -90,6 +90,53 @@ spec: } } +func TestTreeCommand_Kustomization(t *testing.T) { + d, err := ioutil.TempDir("", "kustomize-tree-test") + defer os.RemoveAll(d) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`kind: Deployment +metadata: + labels: + app: nginx + name: bar + annotations: + app: nginx +spec: + replicas: 3 +`), 0600) + if !assert.NoError(t, err) { + return + } + + err = ioutil.WriteFile(filepath.Join(d, "Kustomization"), []byte(`apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- f2.yaml +`), 0600) + if !assert.NoError(t, err) { + return + } + + // fmt the files + b := &bytes.Buffer{} + r := commands.GetTreeRunner("") + r.Command.SetArgs([]string{d}) + r.Command.SetOut(b) + if !assert.NoError(t, r.Command.Execute()) { + return + } + + if !assert.Equal(t, fmt.Sprintf(`%s +├── [Kustomization] Kustomization +└── [f2.yaml] Deployment bar +`, d), b.String()) { + return + } +} + func TestTreeCommand_subpkgs(t *testing.T) { d, err := ioutil.TempDir("", "kustomize-tree-test") defer os.RemoveAll(d)