Handle pod specialization errors

Handle pod specialization success/failure better.  Make sure we only
retry on connection failure, otherwise fail immediately.
This commit is contained in:
Soam Vasani
2016-11-07 12:21:10 -08:00
parent fffba6fcf0
commit d8fdd84368
+14 -5
View File
@@ -251,21 +251,30 @@ func (gp *GenericPool) specializePod(metadata *fission.Metadata) (*v1.Pod, error
maxRetries := 20 maxRetries := 20
for i := 0; i < maxRetries; i++ { for i := 0; i < maxRetries; i++ {
resp2, err := http.Post(specializeUrl, "text/plain", bytes.NewReader([]byte{})) resp2, err := http.Post(specializeUrl, "text/plain", bytes.NewReader([]byte{}))
if err != nil { defer resp2.Body.Close()
if err == nil && resp2.StatusCode < 300 {
return pod, nil
}
// Only retry for the specific case of a connection error.
if urlErr, ok := err.(*url.Error); ok { if urlErr, ok := err.(*url.Error); ok {
if netErr, ok := urlErr.Err.(*net.OpError); ok { if netErr, ok := urlErr.Err.(*net.OpError); ok {
if netErr.Op == "dial" { // && netErr.Err == syscall.ECONNREFUSED if netErr.Op == "dial" {
log.Printf("Error connecting to pod (%v)", netErr)
if i < maxRetries-1 { if i < maxRetries-1 {
time.Sleep(500 * time.Duration(2*i) * time.Millisecond) time.Sleep(500 * time.Duration(2*i) * time.Millisecond)
log.Printf("Error connecting to pod (%v), retrying", netErr)
continue continue
} }
} }
} }
} }
return nil, err
if err == nil {
err = fission.MakeErrorFromHTTP(resp2)
} }
resp2.Body.Close() log.Printf("Failed to specialize pod: %v", err)
return nil, err
} }
return pod, nil return pod, nil