Skip to content

Commit 729642e

Browse files
authored
Merge pull request #7112 from tstromberg/apiserver-always
Improve error when docker-env is used with non-docker runtime
2 parents c5ceccd + dadf4bd commit 729642e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

cmd/minikube/cmd/docker-env.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,18 @@ func isDockerActive(d drivers.Driver) (bool, error) {
122122
if err != nil {
123123
return false, err
124124
}
125-
output, err := client.Output("sudo systemctl is-active docker")
125+
cmd := "sudo systemctl is-active docker"
126+
127+
output, err := client.Output(cmd)
128+
s := strings.TrimSpace(output)
129+
126130
if err != nil {
127-
return false, err
131+
return false, fmt.Errorf("%s failed: %v\noutput: %q", cmd, err, s)
128132
}
129-
// systemd returns error code on inactive
130-
s := strings.TrimSpace(output)
131-
return err == nil && s == "active", nil
133+
if s != "active" {
134+
return false, fmt.Errorf("%s returned %q", cmd, s)
135+
}
136+
return true, nil
132137
}
133138

134139
// dockerEnvCmd represents the docker-env command
@@ -165,9 +170,15 @@ var dockerEnvCmd = &cobra.Command{
165170
if hostSt != state.Running.String() {
166171
exit.WithCodeT(exit.Unavailable, `'{{.profile}}' is not running`, out.V{"profile": profile})
167172
}
173+
174+
if cc.KubernetesConfig.ContainerRuntime != "docker" {
175+
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.`,
176+
out.V{"runtime": cc.KubernetesConfig.ContainerRuntime})
177+
}
178+
168179
ok, err := isDockerActive(host.Driver)
169180
if err != nil {
170-
exit.WithError("Error getting service status", err)
181+
exit.WithError("Docker runtime check failed", err)
171182
}
172183

173184
if !ok {

0 commit comments

Comments
 (0)