Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for urls in deploy.kubectl.manifests #1408

Merged
merged 1 commit into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/skaffold/deploy/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ func (k *KubectlDeployer) readManifests(ctx context.Context) (kubectl.ManifestLi
manifests.Append(buf)
}

for _, manifest := range k.Manifests {
if util.IsURL(manifest) {
buf, err := util.Download(manifest)
if err != nil {
return nil, errors.Wrap(err, "downloading manifest")
}
manifests.Append(buf)
}
}

for _, m := range k.RemoteManifests {
manifest, err := k.readRemoteManifest(ctx, m)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions pkg/skaffold/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ func ExpandPathsGlob(workingDir string, paths []string) ([]string, error) {
if err != nil {
return nil, errors.Wrap(err, "glob")
}
if files == nil {
return nil, fmt.Errorf("file pattern must match at least one file %s", path)
}

for _, f := range files {
err := filepath.Walk(f, func(path string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -139,8 +136,8 @@ func ReadConfiguration(filename string) ([]byte, error) {
return nil, errors.New("filename not specified")
case filename == "-":
return ioutil.ReadAll(os.Stdin)
case strings.HasPrefix(filename, "http://") || strings.HasPrefix(filename, "https://"):
return download(filename)
case IsURL(filename):
return Download(filename)
default:
directory := filepath.Dir(filename)
baseName := filepath.Base(filename)
Expand All @@ -157,7 +154,11 @@ func ReadConfiguration(filename string) ([]byte, error) {
}
}

func download(url string) ([]byte, error) {
func IsURL(s string) bool {
return strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://")
}

func Download(url string) ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
Expand Down
5 changes: 0 additions & 5 deletions pkg/skaffold/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ func TestExpandPathsGlob(t *testing.T) {
in: []string{"dir*"},
out: []string{tmpDir.Path("dir/sub_dir/file"), tmpDir.Path("dir_b/sub_dir_b/file")},
},
{
description: "error unmatched glob",
in: []string{"dir/sub_dir_c/*"},
shouldErr: true,
},
}

for _, tt := range tests {
Expand Down