From 0ec839186d618d232de6747aa70d6720924839c9 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 11 Jun 2020 10:57:15 -0700 Subject: [PATCH 1/4] Change glog.Errorf to glog.Infof so that we don't get an ugly log to stdout --- pkg/drivers/kic/oci/oci.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index 1a1b189cab..0a756b4c4a 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -76,7 +76,7 @@ func DeleteContainer(ociBin string, name string) error { _, err := ContainerStatus(ociBin, name) if err != nil { - glog.Errorf("%s daemon seems to be stuck. Please try restarting your %s. Will try to delete anyways: %v", ociBin, ociBin, err) + glog.Infof("%s daemon seems to be stuck. Will try to delete anyways: %v", ociBin, err) } // try to delete anyways if err := ShutDown(ociBin, name); err != nil { From 330224f36a0ef7464bebce8497a7d7174b471fb0 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 11 Jun 2020 12:50:11 -0700 Subject: [PATCH 2/4] Warn user to restart daemon if context deadline is exceeded --- pkg/drivers/kic/oci/cli_runner.go | 4 ++-- pkg/drivers/kic/oci/oci.go | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/drivers/kic/oci/cli_runner.go b/pkg/drivers/kic/oci/cli_runner.go index 7c348cd8e0..abd6c45b5f 100644 --- a/pkg/drivers/kic/oci/cli_runner.go +++ b/pkg/drivers/kic/oci/cli_runner.go @@ -88,7 +88,7 @@ func runCmd(cmd *exec.Cmd, warnSlow ...bool) (*RunResult, error) { } killTime := 19 * time.Second // this will be applied only if warnSlow is true - warnTime := 2 * time.Second + warnTime := 10 * time.Second ctx, cancel := context.WithTimeout(context.Background(), killTime) defer cancel() @@ -138,7 +138,7 @@ func runCmd(cmd *exec.Cmd, warnSlow ...bool) (*RunResult, error) { } if ctx.Err() == context.DeadlineExceeded { - return rr, fmt.Errorf("%q timed out after %s", rr.Command(), killTime) + return rr, context.DeadlineExceeded } } diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index 0a756b4c4a..f7625d15d2 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -17,6 +17,7 @@ limitations under the License. package oci import ( + "context" "os" "time" @@ -27,6 +28,7 @@ import ( "github.com/golang/glog" "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/util/retry" "fmt" @@ -73,10 +75,11 @@ func DeleteContainersByLabel(ociBin string, label string) []error { // DeleteContainer deletes a container by ID or Name func DeleteContainer(ociBin string, name string) error { - _, err := ContainerStatus(ociBin, name) - if err != nil { - glog.Infof("%s daemon seems to be stuck. Will try to delete anyways: %v", ociBin, err) + if err == context.DeadlineExceeded { + out.WarningT("{{.ocibin}} daemon is taking an unsually long time to respond, consider restarting {{.ocibin}}", out.V{"ociBin": ociBin}) + } else if err != nil { + glog.Warningf("error getting container status, will try to delete anyways: %v", err) } // try to delete anyways if err := ShutDown(ociBin, name); err != nil { From b750ab49649414064b73423a85632512bcb698d5 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 11 Jun 2020 13:00:44 -0700 Subject: [PATCH 3/4] fix lint --- pkg/drivers/kic/oci/cli_runner.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/drivers/kic/oci/cli_runner.go b/pkg/drivers/kic/oci/cli_runner.go index abd6c45b5f..4653cbc6f0 100644 --- a/pkg/drivers/kic/oci/cli_runner.go +++ b/pkg/drivers/kic/oci/cli_runner.go @@ -89,14 +89,15 @@ func runCmd(cmd *exec.Cmd, warnSlow ...bool) (*RunResult, error) { killTime := 19 * time.Second // this will be applied only if warnSlow is true warnTime := 10 * time.Second - ctx, cancel := context.WithTimeout(context.Background(), killTime) - defer cancel() if cmd.Args[1] == "volume" || cmd.Args[1] == "ps" { // volume and ps requires more time than inspect killTime = 30 * time.Second warnTime = 3 * time.Second } + ctx, cancel := context.WithTimeout(context.Background(), killTime) + defer cancel() + if warn { // convert exec.Command to with context cmdWithCtx := exec.CommandContext(ctx, cmd.Args[0], cmd.Args[1:]...) cmdWithCtx.Stdout = cmd.Stdout //copying the original command From 6ef48499b490af9b5cb10b11c7a1c2aabad8cb8c Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Fri, 12 Jun 2020 11:00:46 -0700 Subject: [PATCH 4/4] Code review comments --- pkg/drivers/kic/oci/cli_runner.go | 2 +- pkg/drivers/kic/oci/oci.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/drivers/kic/oci/cli_runner.go b/pkg/drivers/kic/oci/cli_runner.go index 4653cbc6f0..cfcde88f39 100644 --- a/pkg/drivers/kic/oci/cli_runner.go +++ b/pkg/drivers/kic/oci/cli_runner.go @@ -88,7 +88,7 @@ func runCmd(cmd *exec.Cmd, warnSlow ...bool) (*RunResult, error) { } killTime := 19 * time.Second // this will be applied only if warnSlow is true - warnTime := 10 * time.Second + warnTime := 2 * time.Second if cmd.Args[1] == "volume" || cmd.Args[1] == "ps" { // volume and ps requires more time than inspect killTime = 30 * time.Second diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index f7625d15d2..ff4bed93a9 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -77,7 +77,7 @@ func DeleteContainersByLabel(ociBin string, label string) []error { func DeleteContainer(ociBin string, name string) error { _, err := ContainerStatus(ociBin, name) if err == context.DeadlineExceeded { - out.WarningT("{{.ocibin}} daemon is taking an unsually long time to respond, consider restarting {{.ocibin}}", out.V{"ociBin": ociBin}) + out.WarningT("{{.ocibin}} is taking an unsually long time to respond, consider restarting {{.ocibin}}", out.V{"ociBin": ociBin}) } else if err != nil { glog.Warningf("error getting container status, will try to delete anyways: %v", err) }