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
This commit is contained in:
Vishal
2019-01-23 22:26:13 +08:00
committed by Ta-Ching Chen
parent 5ff875b1ac
commit 101e188f41
2 changed files with 20 additions and 3 deletions
+19 -2
View File
@@ -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)
}
+1 -1
View File
@@ -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 {