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
+20 -11
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 urlErr, ok := err.(*url.Error); ok {
if netErr, ok := urlErr.Err.(*net.OpError); ok { if err == nil && resp2.StatusCode < 300 {
if netErr.Op == "dial" { // && netErr.Err == syscall.ECONNREFUSED return pod, nil
log.Printf("Error connecting to pod (%v)", netErr) }
if i < maxRetries-1 {
time.Sleep(500 * time.Duration(2*i) * time.Millisecond) // Only retry for the specific case of a connection error.
continue if urlErr, ok := err.(*url.Error); ok {
} if netErr, ok := urlErr.Err.(*net.OpError); ok {
if netErr.Op == "dial" {
if i < maxRetries-1 {
time.Sleep(500 * time.Duration(2*i) * time.Millisecond)
log.Printf("Error connecting to pod (%v), retrying", netErr)
continue
} }
} }
} }
return nil, err
} }
resp2.Body.Close()
if err == nil {
err = fission.MakeErrorFromHTTP(resp2)
}
log.Printf("Failed to specialize pod: %v", err)
return nil, err
} }
return pod, nil return pod, nil