From 101e188f41d0403aaa744c8634d4a467e9638d18 Mon Sep 17 00:00:00 2001 From: Vishal Date: Wed, 23 Jan 2019 19:56:13 +0530 Subject: [PATCH] Clear message in case of function/pod failure (#1069) * Clear message in case of function/pod failure * Added err handling while getting pods * Using multierror instead of strings --- executor/poolmgr/gp.go | 21 +++++++++++++++++++-- fission/function.go | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/executor/poolmgr/gp.go b/executor/poolmgr/gp.go index 3098c69c..c0070554 100644 --- a/executor/poolmgr/gp.go +++ b/executor/poolmgr/gp.go @@ -27,6 +27,7 @@ import ( "time" "github.com/dchest/uniuri" + multierror "github.com/hashicorp/go-multierror" "github.com/pkg/errors" apiv1 "k8s.io/api/core/v1" "k8s.io/api/extensions/v1beta1" @@ -574,9 +575,25 @@ func (gp *GenericPool) waitForReadyPod() error { } if time.Since(startTime) > gp.podReadyTimeout { + podList, err := gp.kubernetesClient.CoreV1().Pods(gp.namespace).List(metav1.ListOptions{ + LabelSelector: labels.Set( + gp.deployment.Spec.Selector.MatchLabels).AsSelector().String(), + }) + if err != nil { + log.Printf("Error getting pod list after timeout waiting for ready pod: %v", err) + } + + // Since even single pod is not ready, choosing the first pod to inspect is a good approximation. In future this can be done better + pod := podList.Items[0] + var multierr *multierror.Error + for _, cStatus := range pod.Status.ContainerStatuses { + if cStatus.Ready != true { + multierr = multierror.Append(multierr, errors.New(fmt.Sprintf("%v: %v", cStatus.State.Waiting.Reason, cStatus.State.Waiting.Message))) + } + } return errors.Errorf( - "Timeout: waited too long for pod of deployment %v in namespace %v to be ready", - gp.deployment.ObjectMeta.Name, gp.namespace) + "Timeout: waited too long for pod of deployment %v in namespace %v to be ready, error: %v", + gp.deployment.ObjectMeta.Name, gp.namespace, multierr) } time.Sleep(1000 * time.Millisecond) } diff --git a/fission/function.go b/fission/function.go index 7ec3f955..99e9bbca 100644 --- a/fission/function.go +++ b/fission/function.go @@ -803,7 +803,7 @@ func fnTest(c *cli.Context) error { body, err := ioutil.ReadAll(resp.Body) util.CheckErr(err, "read log response from pod") - fmt.Printf("Error calling function %s: %d %s", fnName, resp.StatusCode, string(body)) + fmt.Printf("Error calling function %s: %d; Please try again or fix the error: %s", fnName, resp.StatusCode, string(body)) defer resp.Body.Close() err = printPodLogs(c) if err != nil {