feat: use automated ssh-agent in docker-env
parent
3d1b44055a
commit
a814542ad3
|
@ -298,13 +298,6 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
|
|||
|
||||
cname := ClusterFlagValue()
|
||||
|
||||
// start the ssh-agent
|
||||
// this must be done before the cluster config is loaded
|
||||
// otherwise we won't be able to get SSH_AUTH_SOCK and SSH_AGENT_PID from cluster config.
|
||||
if err := sshagent.Start(cname); err != nil {
|
||||
exit.Message(reason.SshAgentStart, err.Error())
|
||||
}
|
||||
|
||||
co := mustload.Running(cname)
|
||||
|
||||
driverName := co.CP.Host.DriverName
|
||||
|
@ -336,11 +329,19 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
|
|||
// user also need to execute ssh-agent bash and minikube ssh-host --append-known before this
|
||||
// so remind them to do so
|
||||
out.WarningT("Please ensure you have executed 'ssh-agent bash' and 'minikube ssh-host --append-known' in this shell before using docker-env on containerd. Ignore this message if you have done it")
|
||||
}
|
||||
|
||||
// set the ssh-agent envs for current process
|
||||
os.Setenv("SSH_AUTH_SOCK", co.Config.SSHAuthSock)
|
||||
os.Setenv("SSH_AGENT_PID", strconv.Itoa(co.Config.SSHAgentPID))
|
||||
// start the ssh-agent
|
||||
if err := sshagent.Start(cname); err != nil {
|
||||
exit.Message(reason.SSHAgentStart, err.Error())
|
||||
}
|
||||
// cluster config must be reloaded
|
||||
// otherwise we won't be able to get SSH_AUTH_SOCK and SSH_AGENT_PID from cluster config.
|
||||
co = mustload.Running(cname)
|
||||
|
||||
// set the ssh-agent envs for current process
|
||||
os.Setenv("SSH_AUTH_SOCK", co.Config.SSHAuthSock)
|
||||
os.Setenv("SSH_AGENT_PID", strconv.Itoa(co.Config.SSHAgentPID))
|
||||
}
|
||||
|
||||
r := co.CP.Runner
|
||||
|
||||
|
|
|
@ -429,7 +429,7 @@ var (
|
|||
// minikube failed to cache images for the current container runtime
|
||||
RuntimeCache = Kind{ID: "RUNTIME_CACHE", ExitCode: ExRuntimeError}
|
||||
// minikube failed to start an ssh-agent when executing docker-env
|
||||
SshAgentStart = Kind{ID: "SSH_AGENT_START", ExitCode: ExRuntimeError}
|
||||
SSHAgentStart = Kind{ID: "SSH_AGENT_START", ExitCode: ExRuntimeError}
|
||||
|
||||
// service check timed out while starting minikube dashboard
|
||||
SvcCheckTimeout = Kind{ID: "SVC_CHECK_TIMEOUT", ExitCode: ExSvcTimeout}
|
||||
|
|
|
@ -406,6 +406,9 @@ minikube failed to enable the current container runtime
|
|||
"RUNTIME_CACHE" (Exit code ExRuntimeError)
|
||||
minikube failed to cache images for the current container runtime
|
||||
|
||||
"SSH_AGENT_START" (Exit code ExRuntimeError)
|
||||
minikube failed to start an ssh-agent when executing docker-env
|
||||
|
||||
"SVC_CHECK_TIMEOUT" (Exit code ExSvcTimeout)
|
||||
service check timed out while starting minikube dashboard
|
||||
|
||||
|
|
|
@ -194,12 +194,12 @@ func TestDockerEnvContainerd(t *testing.T) {
|
|||
output := result.Output()
|
||||
groups := regexp.MustCompile(`DOCKER_HOST="(\S*)"`).FindStringSubmatch(output)
|
||||
if len(groups) < 2 {
|
||||
t.Errorf("failed to acquire SSH_AUTH_SOCK, output is %s", output)
|
||||
t.Errorf("DOCKER_HOST doesn't match expected format, output is %s", output)
|
||||
}
|
||||
dockerHost := groups[1]
|
||||
segments := strings.Split(dockerHost, ":")
|
||||
if len(segments) < 3 {
|
||||
t.Errorf("failed to acquire dockerHost, output is %s", dockerHost)
|
||||
t.Errorf("DOCKER_HOST doesn't match expected format, output is %s", dockerHost)
|
||||
}
|
||||
|
||||
// get SSH_AUTH_SOCK
|
||||
|
@ -211,7 +211,7 @@ func TestDockerEnvContainerd(t *testing.T) {
|
|||
// get SSH_AGENT_PID
|
||||
groups = regexp.MustCompile(`SSH_AGENT_PID=(\S*)`).FindStringSubmatch(output)
|
||||
if len(groups) < 2 {
|
||||
t.Errorf("failed to acquire SSH_AUTH_SOCK, output is %s", output)
|
||||
t.Errorf("failed to acquire SSH_AUTH_PID, output is %s", output)
|
||||
}
|
||||
sshAgentPid := groups[1]
|
||||
|
||||
|
|
Loading…
Reference in New Issue