mirror of https://github.com/kubernetes/kops.git
Allow channels to cope with non-local URLs
We copy to a temp file before calling kubectl apply
This commit is contained in:
parent
9a507c0397
commit
f51719f938
|
@ -6,12 +6,37 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"io/ioutil"
|
||||||
|
"k8s.io/kops/util/pkg/vfs"
|
||||||
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Apply calls kubectl apply to apply the manifest.
|
// Apply calls kubectl apply to apply the manifest.
|
||||||
// We will likely in future change this to create things directly (or more likely embed this logic into kubectl itself)
|
// We will likely in future change this to create things directly (or more likely embed this logic into kubectl itself)
|
||||||
func Apply(manifest string) error {
|
func Apply(manifest string) error {
|
||||||
_, err := execKubectl("apply", "-f", manifest)
|
// We copy the manifest to a temp file because it is likely e.g. an s3 URL, which kubectl can't read
|
||||||
|
data, err := vfs.Context.ReadFile(manifest)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error reading manifest: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpDir, err := ioutil.TempDir("", "channel")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := os.RemoveAll(tmpDir); err != nil {
|
||||||
|
glog.Warningf("error deleting temp dir %q: %v", tmpDir, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
localManifestFile := path.Join(tmpDir, "manifest.yaml")
|
||||||
|
if err := ioutil.WriteFile(localManifestFile, data, 0600); err != nil {
|
||||||
|
return fmt.Errorf("error writing temp file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = execKubectl("apply", "-f", localManifestFile)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue