Skip to content

Commit 882da3c

Browse files
authored
Merge pull request #18 from Smirl/handle-422
Gracefully handle 422 response codes when FloatingIP is in pending state
2 parents 655722e + 060ae2c commit 882da3c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

controllers/digitalocean/floatingipbinding_controller.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,15 @@ func (r *FloatingIPBindingReconciler) AssignFloatingIP(
253253
// Assign IP if not already assigned
254254
_, _, err = r.DigitaloceanClient.FloatingIPActions.Assign(ctx, binding.Spec.FloatingIP, droplet.ID)
255255
if err != nil {
256-
log.Error(err, "Failed update floatingIP")
257-
return err
256+
// Check that the error isn't a 422. This occurs if we are already updating the IP
257+
doError, ok := err.(*godo.ErrorResponse)
258+
if ok && doError.Response.StatusCode == 422 {
259+
log.Info("FloatingIP is in pending state. Skipping.")
260+
return nil
261+
} else {
262+
log.Error(err, "Failed update floatingIP")
263+
return err
264+
}
258265
}
259266
log.Info("Assigned droplet to FloatingIP")
260267
}

0 commit comments

Comments
 (0)