Gracefully fail on legacy HC delete
This commit is contained in:
parent
f65b35f766
commit
06204c6b1a
2 changed files with 16 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue