Fix flackness of docker-env in parrallel

pull/10118/head
Yanshu Zhao 2021-01-09 18:46:40 +00:00
parent 6d763a1cc7
commit 4b8b2bc6db
3 changed files with 45 additions and 2 deletions

View File

@ -495,6 +495,15 @@ func deleteProfileDirectory(profile string) {
exit.Error(reason.GuestProfileDeletion, "Unable to remove machine directory", err)
}
}
certDir := filepath.Join(localpath.MiniPath(), profile)
if _, err := os.Stat(certDir); err == nil {
out.Step(style.DeletingHost, `Removing {{.directory}} ...`, out.V{"directory": certDir})
err := os.RemoveAll(certDir)
if err != nil {
exit.Error(reason.GuestProfileDeletion, "Unable to remove machine directory", err)
}
}
}
func deleteMachineDirectories(cc *config.ClusterConfig) {

View File

@ -306,7 +306,7 @@ var dockerEnvCmd = &cobra.Command{
ssh: sshHost,
hostIP: hostIP,
port: port,
certsDir: localpath.MakeMiniPath("certs"),
certsDir: localpath.MakeMiniPath(cname),
noProxy: noProxy,
username: d.GetSSHUsername(),
hostname: hostname,

View File

@ -40,6 +40,7 @@ import (
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/localpath"
)
// generic interface for minikube provisioner
@ -102,7 +103,11 @@ func configureAuth(p miniProvisioner) error {
return errors.Wrap(err, "error getting ssh hostname during provisioning")
}
if err := copyHostCerts(authOptions); err != nil {
//if err := copyHostCerts(authOptions); err != nil {
// return err
//}
if err := copyCertsForDockEnv(authOptions, machineName); err != nil {
return err
}
@ -161,6 +166,35 @@ func copyHostCerts(authOptions auth.Options) error {
return nil
}
func copyCertsForDockEnv(authOptions auth.Options, machineName string) error {
klog.Infof("copyCertsForDockEnv")
storePath := localpath.MakeMiniPath(machineName)
err := os.MkdirAll(storePath, 0700)
if err != nil {
klog.Errorf("mkdir failed: %v", err)
}
hostCerts := map[string]string{
authOptions.CaCertPath: path.Join(storePath, "ca.pem"),
authOptions.ClientCertPath: path.Join(storePath, "cert.pem"),
authOptions.ClientKeyPath: path.Join(storePath, "key.pem"),
}
execRunner := command.NewExecRunner(false)
for src, dst := range hostCerts {
f, err := assets.NewFileAsset(src, path.Dir(dst), filepath.Base(dst), "0777")
if err != nil {
return errors.Wrapf(err, "open cert file: %s", src)
}
if err := execRunner.Copy(f); err != nil {
return errors.Wrapf(err, "transferring file: %+v", f)
}
}
return nil
}
func copyRemoteCerts(authOptions auth.Options, driver drivers.Driver) error {
klog.Infof("copyRemoteCerts")