未验证 提交 b0204cd3 编写于 作者: T Thomas Strömberg 提交者: GitHub

Merge pull request #5224 from tstromberg/filepath

Windows: Use path.Join for VM paths, fall-back to anon image downloads
......@@ -23,7 +23,6 @@ import (
"io"
"os"
"path"
"path/filepath"
"github.com/golang/glog"
"github.com/pkg/errors"
......@@ -80,7 +79,7 @@ func NewMemoryAssetTarget(d []byte, targetPath, permissions string) *MemoryAsset
// NewFileAsset creates a new FileAsset
func NewFileAsset(src, targetDir, targetName, permissions string) (*FileAsset, error) {
glog.Infof("NewFileAsset: %s -> %s", src, filepath.Join(targetDir, targetName))
glog.Infof("NewFileAsset: %s -> %s", src, path.Join(targetDir, targetName))
f, err := os.Open(src)
if err != nil {
return nil, errors.Wrapf(err, "Error opening file asset: %s", src)
......
......@@ -19,10 +19,13 @@ package kubeadm
import (
"bytes"
"crypto/tls"
"fmt"
"net"
"net/http"
"path/filepath"
// WARNING: Do not use path/filepath in this package unless you want bizarre Windows paths
"path"
"runtime"
"strings"
"time"
......@@ -95,7 +98,7 @@ var PodsByLayer = []pod{
}
// yamlConfigPath is the path to the kubeadm configuration
var yamlConfigPath = filepath.Join(constants.GuestEphemeralDir, "kubeadm.yaml")
var yamlConfigPath = path.Join(constants.GuestEphemeralDir, "kubeadm.yaml")
// SkipAdditionalPreflights are additional preflights we skip depending on the runtime in use.
var SkipAdditionalPreflights = map[string][]string{}
......@@ -200,7 +203,7 @@ func createFlagsFromExtraArgs(extraOptions config.ExtraOptionSlice) string {
// etcdDataDir is where etcd data is stored.
func etcdDataDir() string {
return filepath.Join(constants.GuestPersistentDir, "etcd")
return path.Join(constants.GuestPersistentDir, "etcd")
}
// createCompatSymlinks creates compatibility symlinks to transition running services to new directory structures
......@@ -538,7 +541,7 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte,
}{
ExtraOptions: convertToFlags(extraOpts),
ContainerRuntime: k8s.ContainerRuntime,
KubeletPath: filepath.Join(binRoot(k8s.KubernetesVersion), "kubelet"),
KubeletPath: path.Join(binRoot(k8s.KubernetesVersion), "kubelet"),
}
if err := kubeletSystemdTemplate.Execute(&b, opts); err != nil {
return nil, err
......@@ -700,7 +703,7 @@ func generateConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte, er
// NewKubeletService returns a generated systemd unit file for the kubelet
func NewKubeletService(cfg config.KubernetesConfig) ([]byte, error) {
var b bytes.Buffer
opts := struct{ KubeletPath string }{KubeletPath: filepath.Join(binRoot(cfg.KubernetesVersion), "kubelet")}
opts := struct{ KubeletPath string }{KubeletPath: path.Join(binRoot(cfg.KubernetesVersion), "kubelet")}
if err := kubeletServiceTemplate.Execute(&b, opts); err != nil {
return nil, errors.Wrap(err, "template execute")
}
......@@ -725,7 +728,7 @@ func configFiles(cfg config.KubernetesConfig, kubeadm []byte, kubelet []byte, ku
// binDir returns the persistent path binaries are stored in
func binRoot(version string) string {
return filepath.Join(constants.GuestPersistentDir, "binaries", version)
return path.Join(constants.GuestPersistentDir, "binaries", version)
}
// invokeKubeadm returns the invocation command for Kubeadm
......@@ -744,7 +747,7 @@ func transferBinaries(cfg config.KubernetesConfig, c command.Runner) error {
return errors.Wrapf(err, "downloading %s", name)
}
dst := filepath.Join(binRoot(cfg.KubernetesVersion), name)
dst := path.Join(binRoot(cfg.KubernetesVersion), name)
if err := machine.CopyBinary(c, src, dst); err != nil {
return errors.Wrapf(err, "copybinary %s -> %s", src, dst)
}
......
......@@ -19,7 +19,7 @@ package command
import (
"fmt"
"io"
"path/filepath"
"path"
"k8s.io/minikube/pkg/minikube/assets"
)
......@@ -54,5 +54,5 @@ type Runner interface {
}
func getDeleteFileCommand(f assets.CopyableFile) string {
return fmt.Sprintf("sudo rm %s", filepath.Join(f.GetTargetDir(), f.GetTargetName()))
return fmt.Sprintf("sudo rm %s", path.Join(f.GetTargetDir(), f.GetTargetName()))
}
......@@ -21,6 +21,7 @@ import (
"io"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
......@@ -76,7 +77,7 @@ func (*ExecRunner) Copy(f assets.CopyableFile) error {
if err := os.MkdirAll(f.GetTargetDir(), os.ModePerm); err != nil {
return errors.Wrapf(err, "error making dirs for %s", f.GetTargetDir())
}
targetPath := filepath.Join(f.GetTargetDir(), f.GetTargetName())
targetPath := path.Join(f.GetTargetDir(), f.GetTargetName())
if _, err := os.Stat(targetPath); err == nil {
if err := os.Remove(targetPath); err != nil {
return errors.Wrapf(err, "error removing file %s", targetPath)
......
......@@ -21,7 +21,6 @@ import (
"fmt"
"io"
"path"
"path/filepath"
"sync"
"github.com/golang/glog"
......@@ -167,7 +166,7 @@ func (s *SSHRunner) Copy(f assets.CopyableFile) error {
// StdinPipe is closed. But let's use errgroup to make it explicit.
var g errgroup.Group
var copied int64
dst := filepath.Join(path.Join(f.GetTargetDir(), f.GetTargetName()))
dst := path.Join(path.Join(f.GetTargetDir(), f.GetTargetName()))
glog.Infof("Transferring %d bytes to %s", f.GetLength(), dst)
g.Go(func() error {
......
......@@ -20,7 +20,6 @@ import (
"crypto"
"os"
"path"
"path/filepath"
"runtime"
"github.com/golang/glog"
......@@ -93,7 +92,7 @@ func CacheBinary(binary, version, osName, archName string) (string, error) {
// CopyBinary copies a locally cached binary to the guest VM
func CopyBinary(cr command.Runner, src string, dest string) error {
f, err := assets.NewFileAsset(src, filepath.Dir(dest), filepath.Base(dest), "0755")
f, err := assets.NewFileAsset(src, path.Dir(dest), path.Base(dest), "0755")
if err != nil {
return errors.Wrap(err, "new file asset")
}
......
......@@ -25,6 +25,7 @@ import (
"runtime"
"strings"
"sync"
"time"
"github.com/golang/glog"
"github.com/google/go-containerregistry/pkg/authn"
......@@ -44,7 +45,7 @@ import (
)
// loadRoot is where images should be loaded from within the guest VM
var loadRoot = filepath.Join(constants.GuestPersistentDir, "images")
var loadRoot = path.Join(constants.GuestPersistentDir, "images")
var getWindowsVolumeName = getWindowsVolumeNameCmd
......@@ -75,8 +76,10 @@ func CacheImages(images []string, cacheDir string) error {
dst := filepath.Join(cacheDir, image)
dst = sanitizeCacheDir(dst)
if err := CacheImage(image, dst); err != nil {
glog.Errorf("CacheImage %s -> %s failed: %v", image, dst, err)
return errors.Wrapf(err, "caching image %s", dst)
}
glog.Infof("CacheImage %s -> %s succeeded", image, dst)
return nil
})
}
......@@ -143,7 +146,9 @@ func CacheAndLoadImages(images []string) error {
func sanitizeCacheDir(image string) string {
if runtime.GOOS == "windows" && hasWindowsDriveLetter(image) {
// not sanitize Windows drive letter.
return image[:2] + strings.Replace(image[2:], ":", "_", -1)
s := image[:2] + strings.Replace(image[2:], ":", "_", -1)
glog.Infof("windows sanitize: %s -> %s", image, s)
return s
}
return strings.Replace(image, ":", "_", -1)
}
......@@ -286,8 +291,14 @@ func getDstPath(dst string) (string, error) {
// CacheImage caches an image
func CacheImage(image, dst string) error {
glog.Infof("Attempting to cache image: %s at %s\n", image, dst)
start := time.Now()
glog.Infof("CacheImage: %s -> %s", image, dst)
defer func() {
glog.Infof("CacheImage: %s -> %s completed in %s", image, dst, time.Since(start))
}()
if _, err := os.Stat(dst); err == nil {
glog.Infof("%s exists", dst)
return nil
}
......@@ -331,14 +342,26 @@ func CacheImage(image, dst string) error {
if err != nil {
return err
}
glog.Infof("%s exists", dst)
return nil
}
func retrieveImage(ref name.Reference) (v1.Image, error) {
glog.Infof("retrieving image: %+v", ref)
img, err := daemon.Image(ref)
if err == nil {
glog.Infof("found %s locally; caching", ref.Name())
return img, err
}
return remote.Image(ref, remote.WithAuthFromKeychain(authn.DefaultKeychain))
glog.Infof("daemon image for %+v: %v", img, err)
img, err = remote.Image(ref, remote.WithAuthFromKeychain(authn.DefaultKeychain))
if err == nil {
return img, err
}
glog.Warningf("failed authn download for %+v (trying anon): %+v", ref, err)
img, err = remote.Image(ref)
if err != nil {
glog.Warningf("failed anon download for %+v: %+v", ref, err)
}
return img, err
}
......@@ -22,6 +22,7 @@ import (
"context"
"fmt"
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"
......@@ -50,7 +51,7 @@ type MinikubeRunner struct {
// Remove removes a file
func (m *MinikubeRunner) Remove(f assets.CopyableFile) error {
_, err := m.SSH(fmt.Sprintf("rm -rf %s", filepath.Join(f.GetTargetDir(), f.GetTargetName())))
_, err := m.SSH(fmt.Sprintf("rm -rf %s", path.Join(f.GetTargetDir(), f.GetTargetName())))
return err
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册