Skip to content

Commit

Permalink
Merge pull request #2611 from jmcclell/kustomization-remote
Browse files Browse the repository at this point in the history
Fix issue with remote Kustomizations in dev mode. (#2581)
  • Loading branch information
tejal29 authored Aug 8, 2019
2 parents 1603de1 + 8c02203 commit 67c4afe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
5 changes: 3 additions & 2 deletions pkg/skaffold/deploy/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ func dependenciesForKustomization(dir string) ([]string, error) {

path, err := findKustomizationConfig(dir)
if err != nil {
return nil, err
// No kustomiization config found so assume it's remote and stop traversing
return deps, nil
}

buf, err := ioutil.ReadFile(path)
Expand Down Expand Up @@ -217,7 +218,7 @@ func dependenciesForKustomization(dir string) ([]string, error) {
return deps, nil
}

// A kustomization config must be at the root of the direectory. Kustomize will
// A Kustomization config must be at the root of the directory. Kustomize will
// error if more than one of these files exists so order doesn't matter.
func findKustomizationConfig(dir string) (string, error) {
candidates := []string{"kustomization.yaml", "kustomization.yml", "Kustomization"}
Expand Down
42 changes: 22 additions & 20 deletions pkg/skaffold/deploy/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ func TestKustomizeCleanup(t *testing.T) {

func TestDependenciesForKustomization(t *testing.T) {
tests := []struct {
description string
yaml string
expected []string
shouldErr bool
createFiles map[string]string
configName string
description string
yaml string
expected []string
shouldErr bool
skipConfigCreation bool
createFiles map[string]string
configName string
}{
{
description: "resources",
Expand Down Expand Up @@ -272,23 +273,21 @@ func TestDependenciesForKustomization(t *testing.T) {
{
description: "mixture of config names",
yaml: `resources: [app.yaml, base1, base2]`,
expected: []string{"Kustomization", "app.yaml", "base1/kustomization.yml", "base1/app.yaml", "base2/Kustomization", "base2/app.yaml"},
expected: []string{"Kustomization", "app.yaml", "base1/kustomization.yml", "base1/app.yaml", "base2/kustomization.yaml", "base2/app.yaml"},
createFiles: map[string]string{
"app.yaml": "",
"base1/kustomization.yml": `resources: [app.yaml]`,
"base1/app.yaml": "",
"base2/Kustomization": `resources: [app.yaml]`,
"base2/app.yaml": "",
"app.yaml": "",
"base1/kustomization.yml": `resources: [app.yaml]`,
"base1/app.yaml": "",
"base2/kustomization.yaml": `resources: [app.yaml]`,
"base2/app.yaml": "",
},
configName: "Kustomization",
},
{
description: "no kustomization config",
yaml: `resources: [foo]`,
shouldErr: true,
createFiles: map[string]string{
"foo/invalid-config-name": "",
},
description: "remote or missing root kustomization config",
expected: []string{},
configName: "missing-or-remote-root-config",
skipConfigCreation: true,
},
}
for _, test := range tests {
Expand All @@ -297,8 +296,11 @@ func TestDependenciesForKustomization(t *testing.T) {
test.configName = "kustomization.yaml"
}

tmpDir := t.NewTempDir().
Write(test.configName, test.yaml)
tmpDir := t.NewTempDir()

if !test.skipConfigCreation {
tmpDir.Write(test.configName, test.yaml)
}

for path, contents := range test.createFiles {
tmpDir.Write(path, contents)
Expand Down

0 comments on commit 67c4afe

Please sign in to comment.