Skip to content

Commit

Permalink
Cherrypick #1058[Handle health check not found error gracefully] into…
Browse files Browse the repository at this point in the history
… release-1.9
  • Loading branch information
skmatti committed Mar 26, 2020
1 parent 5a33c28 commit 733da3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 13 additions & 8 deletions pkg/healthchecks/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,26 @@ func (h *HealthChecks) Delete(name string, scope meta.KeyType) error {
if err != nil {
return err
}
klog.V(2).Infof("Deleting regional health check %v", name)
// L7-ILB is the only use of regional right now
err = composite.DeleteHealthCheck(cloud, key, features.L7ILBVersions().HealthCheck)
// Ignore error if the deletion candidate is being used by another resource.
// In most of the cases, this is the associated backend resource itself.
if utils.IsHTTPErrorCode(err, http.StatusNotFound) || utils.IsInUsedByError(err) {
klog.V(4).Infof("DeleteRegionalHealthCheck(%s, _): %v, ignorable error", name, err)
return nil
if err = composite.DeleteHealthCheck(cloud, key, features.L7ILBVersions().HealthCheck); err != nil {
// Ignore error if the deletion candidate is being used by another resource.
// In most of the cases, this is the associated backend resource itself.
if utils.IsHTTPErrorCode(err, http.StatusNotFound) || utils.IsInUsedByError(err) {
klog.V(4).Infof("DeleteRegionalHealthCheck(%s, _): %v, ignorable error", name, err)
return nil
}
return err
}
return nil
}

klog.V(2).Infof("Deleting health check %v", name)
// Not using composite here since the tests still rely on the fake health check interface
if err := h.cloud.DeleteHealthCheck(name); err != nil {
// Ignore error if the deletion candidate is being used by another resource.
if utils.IsInUsedByError(err) {
// Ignore error if the deletion candidate does not exist or is being used
// by another resource.
if utils.IsHTTPErrorCode(err, http.StatusNotFound) || utils.IsInUsedByError(err) {
klog.V(4).Infof("DeleteHealthCheck(%s, _): %v, ignorable error", name, err)
return nil
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/healthchecks/healthchecks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,6 @@ func TestHealthCheckDelete(t *testing.T) {
if !utils.IsHTTPErrorCode(err, http.StatusNotFound) {
t.Errorf("expected not-found error, actual: %v", err)
}

// Delete only HTTP 1234
err = healthChecks.Delete(testNamer.IGBackend(1234), meta.Global)
if err == nil {
t.Errorf("expected not-found error when deleting health check, err: %v", err)
}
}

func TestHTTP2HealthCheckDelete(t *testing.T) {
Expand Down

0 comments on commit 733da3e

Please sign in to comment.