Improve error message when docker-env is used with an incompatible runtime
parent
8d1f4552c0
commit
dadf4bd35d
|
@ -122,13 +122,18 @@ func isDockerActive(d drivers.Driver) (bool, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
output, err := client.Output("sudo systemctl is-active docker")
|
cmd := "sudo systemctl is-active docker"
|
||||||
if err != nil {
|
|
||||||
return false, err
|
output, err := client.Output(cmd)
|
||||||
}
|
|
||||||
// systemd returns error code on inactive
|
|
||||||
s := strings.TrimSpace(output)
|
s := strings.TrimSpace(output)
|
||||||
return err == nil && s == "active", nil
|
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("%s failed: %v\noutput: %q", cmd, err, s)
|
||||||
|
}
|
||||||
|
if s != "active" {
|
||||||
|
return false, fmt.Errorf("%s returned %q", cmd, s)
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// dockerEnvCmd represents the docker-env command
|
// dockerEnvCmd represents the docker-env command
|
||||||
|
@ -165,9 +170,15 @@ var dockerEnvCmd = &cobra.Command{
|
||||||
if hostSt != state.Running.String() {
|
if hostSt != state.Running.String() {
|
||||||
exit.WithCodeT(exit.Unavailable, `'{{.profile}}' is not running`, out.V{"profile": profile})
|
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)
|
ok, err := isDockerActive(host.Driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit.WithError("Error getting service status", err)
|
exit.WithError("Docker runtime check failed", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue