Skip to content

Commit e2352dc

Browse files
committed
Allow for remote kustomize bases
Kustomize will error if it can't find a base dependency, so it's safe for Skaffold to assume that any base file that does not exist locally is intended to be a remote path that can be ignored since Skaffold can't monitor remote paths for changes.
1 parent bdee774 commit e2352dc

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

pkg/skaffold/deploy/kustomize.go

+18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"io"
2222
"io/ioutil"
23+
"os"
2324
"os/exec"
2425
"path/filepath"
2526

@@ -167,6 +168,12 @@ func dependenciesForKustomization(dir string) ([]string, error) {
167168
}
168169

169170
for _, base := range content.Bases {
171+
// If the file doesn't exist locally, we can assume it's a remote file and
172+
// skip it, since we can't monitor remote files. Kustomize itself will
173+
// handle invalid/missing files.
174+
if !fileExistsLocally(base, dir) {
175+
continue
176+
}
170177
baseDeps, err := dependenciesForKustomization(filepath.Join(dir, base))
171178
if err != nil {
172179
return nil, err
@@ -203,6 +210,17 @@ func joinPaths(root string, paths []string) []string {
203210
return list
204211
}
205212

213+
func fileExistsLocally(filename string, workingDir string) bool {
214+
path := filename
215+
if !filepath.IsAbs(filename) {
216+
path = filepath.Join(workingDir, filename)
217+
}
218+
if _, err := os.Stat(path); err == nil {
219+
return true
220+
}
221+
return false
222+
}
223+
206224
// Dependencies lists all the files that can change what needs to be deployed.
207225
func (k *KustomizeDeployer) Dependencies() ([]string, error) {
208226
return dependenciesForKustomization(k.KustomizePath)

pkg/skaffold/deploy/kustomize_test.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func TestDependenciesForKustomization(t *testing.T) {
161161
yaml string
162162
expected []string
163163
shouldErr bool
164+
createFiles map[string]string
164165
}{
165166
{
166167
description: "resources",
@@ -204,16 +205,28 @@ func TestDependenciesForKustomization(t *testing.T) {
204205
expected: []string{"kustomization.yaml", "secret1.file", "secret2.file", "secret3.file"},
205206
},
206207
{
207-
description: "unknown base",
208-
yaml: `bases: [other]`,
209-
shouldErr: true,
208+
description: "base exists locally",
209+
yaml: `bases: [base]`,
210+
expected: []string{"base/kustomization.yaml", "base/app.yaml", "kustomization.yaml"},
211+
createFiles: map[string]string{
212+
"base/kustomization.yaml": `resources: [app.yaml]`,
213+
},
214+
},
215+
{
216+
description: "missing base locally",
217+
yaml: `bases: [missing-or-remote-base]`,
218+
expected: []string{"kustomization.yaml"},
210219
},
211220
}
212221
for _, test := range tests {
213222
testutil.Run(t, test.description, func(t *testutil.T) {
214223
tmpDir := t.NewTempDir().
215224
Write("kustomization.yaml", test.yaml)
216225

226+
for path, contents := range test.createFiles {
227+
tmpDir.Write(path, contents)
228+
}
229+
217230
k := NewKustomizeDeployer(&runcontext.RunContext{
218231
Cfg: &latest.Pipeline{
219232
Deploy: latest.DeployConfig{

0 commit comments

Comments
 (0)