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:
+19
-2
@@ -27,6 +27,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dchest/uniuri"
|
"github.com/dchest/uniuri"
|
||||||
|
multierror "github.com/hashicorp/go-multierror"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
apiv1 "k8s.io/api/core/v1"
|
apiv1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/api/extensions/v1beta1"
|
"k8s.io/api/extensions/v1beta1"
|
||||||
@@ -574,9 +575,25 @@ func (gp *GenericPool) waitForReadyPod() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if time.Since(startTime) > gp.podReadyTimeout {
|
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(
|
return errors.Errorf(
|
||||||
"Timeout: waited too long for pod of deployment %v in namespace %v to be ready",
|
"Timeout: waited too long for pod of deployment %v in namespace %v to be ready, error: %v",
|
||||||
gp.deployment.ObjectMeta.Name, gp.namespace)
|
gp.deployment.ObjectMeta.Name, gp.namespace, multierr)
|
||||||
}
|
}
|
||||||
time.Sleep(1000 * time.Millisecond)
|
time.Sleep(1000 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -803,7 +803,7 @@ func fnTest(c *cli.Context) error {
|
|||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
util.CheckErr(err, "read log response from pod")
|
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()
|
defer resp.Body.Close()
|
||||||
err = printPodLogs(c)
|
err = printPodLogs(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user