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

Improve error when docker-env is used with non-docker runtime #7112

Merged
merged 1 commit into from
Mar 20, 2020
Merged
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
23 changes: 17 additions & 6 deletions cmd/minikube/cmd/docker-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,18 @@ func isDockerActive(d drivers.Driver) (bool, error) {
if err != nil {
return false, err
}
output, err := client.Output("sudo systemctl is-active docker")
cmd := "sudo systemctl is-active docker"

output, err := client.Output(cmd)
s := strings.TrimSpace(output)

if err != nil {
return false, err
return false, fmt.Errorf("%s failed: %v\noutput: %q", cmd, err, s)
}
// systemd returns error code on inactive
s := strings.TrimSpace(output)
return err == nil && s == "active", nil
if s != "active" {
return false, fmt.Errorf("%s returned %q", cmd, s)
}
return true, nil
}

// dockerEnvCmd represents the docker-env command
Expand Down Expand Up @@ -165,9 +170,15 @@ var dockerEnvCmd = &cobra.Command{
if hostSt != state.Running.String() {
exit.WithCodeT(exit.Unavailable, `'{{.profile}}' is not running`, out.V{"profile": profile})
}

if cc.KubernetesConfig.ContainerRuntime != "docker" {
exit.WithCodeT(exit.BadUsage, `The docker-env command is only compatible with the "docker" runtime, but this cluster was configured to use the "{{.runtime}}" runtime.`,
out.V{"runtime": cc.KubernetesConfig.ContainerRuntime})
}

ok, err := isDockerActive(host.Driver)
if err != nil {
exit.WithError("Error getting service status", err)
exit.WithError("Docker runtime check failed", err)
}

if !ok {
Expand Down