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

docker/podman: add solution message when container exits after start/create #8501

Merged
merged 8 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func runStart(cmd *cobra.Command, args []string) {
starter, err := provisionWithDriver(cmd, ds, existing)
if err != nil {
maybeExitWithAdvice(err)
machine.MaybeAdviceNoExit(err, viper.GetString("driver"))
if specified {
// If the user specified a driver, don't fallback to anything else
exit.WithError("error provisioning host", err)
Expand Down
13 changes: 12 additions & 1 deletion pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ func (d *Driver) Restart() error {
// Start an already created kic container
func (d *Driver) Start() error {
if err := oci.StartContainer(d.NodeConfig.OCIBinary, d.MachineName); err != nil {
oci.PrintPostPortem(d.OCIBinary, d.MachineName)
_, err := oci.DaemonInfo(d.OCIBinary)
if err != nil {
return errors.Wrapf(oci.ErrDaemonInfo, "container name %q", d.MachineName)
medyagh marked this conversation as resolved.
Show resolved Hide resolved
}
return errors.Wrap(err, "start")
}
checkRunning := func() error {
Expand All @@ -320,7 +325,13 @@ func (d *Driver) Start() error {
}

if err := retry.Expo(checkRunning, 500*time.Microsecond, time.Second*30); err != nil {
return err
oci.PrintPostPortem(d.OCIBinary, d.MachineName)
_, err := oci.DaemonInfo(d.OCIBinary)
if err != nil {
return errors.Wrapf(oci.ErrDaemonInfo, "container name %q", d.MachineName)
medyagh marked this conversation as resolved.
Show resolved Hide resolved
}

return errors.Wrapf(oci.ErrExitedAfterCreate, "container name %q", d.MachineName)
}
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/drivers/kic/oci/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ var ErrWindowsContainers = FailFastError(errors.New("docker container type is wi

// ErrCPUCountLimit is thrown when docker daemon doesn't have enough CPUs for the requested container
var ErrCPUCountLimit = FailFastError(errors.New("not enough CPUs is available for container"))

// ErrExitedAfterCreate is thrown when container is created without error but it exists and it's status is not running.
var ErrExitedAfterCreate = errors.New("container status is not running after creation")
medyagh marked this conversation as resolved.
Show resolved Hide resolved

// ErrDaemonInfo is thrown when docker/podman info is failing or not responding
var ErrDaemonInfo = errors.New("daemon info not responding")
42 changes: 41 additions & 1 deletion pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ func CreateContainerNode(p CreateParams) error {

// retry up to up 13 seconds to make sure the created container status is running.
if err := retry.Expo(checkRunning, 13*time.Millisecond, time.Second*13); err != nil {
return errors.Wrapf(err, "check container %q running", p.Name)
PrintPostPortem(p.OCIBinary, p.Name)
_, err := DaemonInfo(p.OCIBinary)
if err != nil {
return errors.Wrapf(ErrDaemonInfo, "container name %q", p.Name)
}
return errors.Wrapf(ErrExitedAfterCreate, "container name %q", p.Name)
}

return nil
Expand Down Expand Up @@ -571,3 +576,38 @@ func ShutDown(ociBin string, name string) error {
glog.Infof("Successfully shutdown container %s", name)
return nil
}

//containerLogs will print out the logs for a container
medyagh marked this conversation as resolved.
Show resolved Hide resolved
func containerLogs(ociBin string, name string) (*RunResult, error) {
if ociBin == Docker {
return runCmd(exec.Command(ociBin, "logs", "--timestamps", "--details", name))
}
// podman doesn't have --details
return runCmd(exec.Command(ociBin, "logs", "--timestamps", name))
}

//PrintPostPortem will print relevant docker/podman infos after a container fails
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to log instead of print (normally associated to stdout). Perhaps LogContainerStatus?

Copy link
Member Author

@medyagh medyagh Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about LogContainerDebug? since we are doing three things there

func PrintPostPortem(ociBin string, name string) {
rr, err := containerLogs(ociBin, name)
if err != nil {
glog.Warningf("Filed to get postmortem logs. %s :%v", rr.Command(), err)
} else {
glog.Warningf("Postmortem container logs: %s", rr.Command())
}
if ociBin == Docker {
di, err := dockerSystemInfo()
if err != nil {
glog.Warningf("Failed to get postmortem docker info: %v", err)
} else {
glog.Warningf("postmortem docker info: %+v", di)
}
} else {
pi, err := podmanSystemInfo()
if err != nil {
glog.Warningf("couldn't get postmortem info, failed to to run podman info: %v", err)
} else {
glog.Warningf("postmortem podman info: %+v", pi)
}
}

}
64 changes: 64 additions & 0 deletions pkg/minikube/machine/advice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package machine

import (
"runtime"

"github.com/pkg/errors"
"k8s.io/minikube/pkg/drivers/kic/oci"
"k8s.io/minikube/pkg/minikube/out"
)

// MaybeAdviceNoExit will provide advice without exiting, so minikube has a chance to try the failover
func MaybeAdviceNoExit(err error, driver string) {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
if errors.Is(err, oci.ErrDaemonInfo) {
out.ErrLn("")
out.ErrT(out.Conflict, "{{.driver_name}} couldn't proceed because {{.driver_name}} service is not healthy.", out.V{"driver_name": driver})
}

if errors.Is(err, oci.ErrExitedAfterCreate) {
out.ErrLn("")
out.ErrT(out.Conflict, "Unfortunately {{.driver_name}} container exited after it was created, with an unclear root cause.", out.V{"driver_name": driver})
medyagh marked this conversation as resolved.
Show resolved Hide resolved
}

if errors.Is(err, oci.ErrExitedAfterCreate) || errors.Is(err, oci.ErrDaemonInfo) {
out.T(out.Tip, "If you are still interested to make {{.driver_name}} driver work. The following suggestions might help you get passed this issue:", out.V{"driver_name": driver})
out.T(out.Empty, `
- Prune unused {{.driver_name}} images, volumes and abandoned containers.`, out.V{"driver_name": driver})
out.T(out.Empty, `
- Restart your {{.driver_name}} service`, out.V{"driver_name": driver})
if runtime.GOOS != "linux" {
out.T(out.Empty, `
- Ensure your {{.driver_name}} daemon has access to enough CPU/memory resources. `, out.V{"driver_name": driver})
if runtime.GOOS == "darwin" && driver == oci.Docker {
out.T(out.Empty, `
- Docs https://docs.docker.com/docker-for-mac/#resources`, out.V{"driver_name": driver})
}
if runtime.GOOS == "windows" && driver == oci.Docker {
out.T(out.Empty, `
- Docs https://docs.docker.com/docker-for-windows/#resources`, out.V{"driver_name": driver})
}
}
out.T(out.Empty, `
- Delete and recreate minikube cluster
minikube delete
minikube start --driver={{.driver_name}}`, out.V{"driver_name": driver})
// TODO #8348: maybe advice user if to set the --force-systemd https://github.com/kubernetes/minikube/issues/8348
}

}
1 change: 1 addition & 0 deletions pkg/minikube/machine/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func recreateIfNeeded(api libmachine.API, cc *config.ClusterConfig, n *config.No
out.T(out.Restarting, `Restarting existing {{.driver_name}} {{.machine_type}} for "{{.cluster}}" ...`, out.V{"driver_name": cc.Driver, "cluster": machineName, "machine_type": machineType})
}
if err := h.Driver.Start(); err != nil {
MaybeAdviceNoExit(err, h.DriverName)
return h, errors.Wrap(err, "driver start")
}
if err := saveHost(api, h, cc, n); err != nil {
Expand Down