From 06204c6b1ab49d5244454ac4fedf937e3cd37d16 Mon Sep 17 00:00:00 2001 From: Nick Sardo Date: Wed, 14 Jun 2017 17:09:00 -0700 Subject: [PATCH] Gracefully fail on legacy HC delete --- controllers/gce/backends/backends.go | 4 ++-- controllers/gce/utils/utils.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/controllers/gce/backends/backends.go b/controllers/gce/backends/backends.go index 51278aa71..a14749749 100644 --- a/controllers/gce/backends/backends.go +++ b/controllers/gce/backends/backends.go @@ -173,7 +173,7 @@ func (b *Backends) ensureHealthCheck(sp ServicePort) (string, error) { hc := b.healthChecker.New(sp.Port, sp.Protocol) existingLegacyHC, err := b.healthChecker.GetLegacy(sp.Port) - if err != nil && !utils.IsHTTPErrorCode(err, http.StatusNotFound) { + if err != nil && !utils.IsNotFoundError(err) { return "", err } @@ -256,7 +256,7 @@ func (b *Backends) Add(p ServicePort) error { // If previous health check was legacy type, we need to delete it. if existingHCLink != hcLink && strings.Contains(existingHCLink, "/httpHealthChecks/") { if err = b.healthChecker.DeleteLegacy(p.Port); err != nil { - return err + glog.Warning("Failed to delete legacy HttpHealthCheck %v; Will not try again, err: %v", pName, err) } } diff --git a/controllers/gce/utils/utils.go b/controllers/gce/utils/utils.go index 3b628ef6c..ec35f7412 100644 --- a/controllers/gce/utils/utils.go +++ b/controllers/gce/utils/utils.go @@ -332,6 +332,20 @@ func IgnoreHTTPNotFound(err error) error { return err } +// IsInUsedByError returns true if the resource is being used by another GCP resource +func IsInUsedByError(err error) bool { + apiErr, ok := err.(*googleapi.Error) + if !ok || apiErr.Code != http.StatusBadRequest { + return false + } + return strings.Contains(apiErr.Message, "being used by") +} + +// IsNotFoundError returns true if the resource does not exist +func IsNotFoundError(err error) bool { + return IsHTTPErrorCode(err, http.StatusNotFound) +} + // CompareLinks returns true if the 2 self links are equal. func CompareLinks(l1, l2 string) bool { // TODO: These can be partial links