Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 ignore Conflict status in order to make instance able to detach interface #962

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/cloud/services/compute/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,15 @@ func (s *Service) deleteAttachInterface(eventObject runtime.Object, instanceID,

mc := metrics.NewMetricPrometheusContext("server_os_interface", "delete")
err = attachinterfaces.Delete(s.computeClient, instanceID, portID).ExtractErr()
if mc.ObserveRequestIgnoreNotFound(err) != nil {
if mc.ObserveRequestIgnoreNotFoundorConflict(err) != nil {
if capoerrors.IsNotFound(err) {
return nil
}
if capoerrors.IsConflict(err) {
// we don't want to block deletion because of Conflict
// due to instance must be paused/active/shutoff in order to detach interface
return nil
}
record.Warnf(eventObject, "FailedDeleteAttachInterface", "Failed to delete attach interface: instance %s, port %s: %v", instance.ID, port.ID, err)
return err
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ func (mc *MetricPrometheusContext) ObserveRequestIgnoreNotFound(err error) error
return mc.ObserveRequest(err)
}

// ObserveRequestIgnoreNotFoundorConflict records the request latency and counts the errors if it's not IsNotFound or IsConflict.
func (mc *MetricPrometheusContext) ObserveRequestIgnoreNotFoundorConflict(err error) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (mc *MetricPrometheusContext) ObserveRequestIgnoreNotFoundorConflict(err error) error {
func (mc *MetricPrometheusContext) ObserveRequestIgnoreNotFoundOrConflict(err error) error {

if capoerrors.IsNotFound(err) {
_ = mc.ObserveRequest(nil)
return err
}
if capoerrors.IsConflict(err) {
_ = mc.ObserveRequest(nil)
return err
}
return mc.ObserveRequest(err)
}

// Observe records the request latency and counts the errors.
func (mc *MetricPrometheusContext) Observe(om *OpenstackPrometheusMetrics, err error) error {
if om == nil {
Expand Down
16 changes: 16 additions & 0 deletions pkg/utils/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,19 @@ func IsInvalidError(err error) bool {

return false
}

func IsConflict(err error) bool {
var errDefault409 gophercloud.ErrDefault409
if errors.As(err, &errDefault409) {
return true
}

var errUnexpectedResponseCode gophercloud.ErrUnexpectedResponseCode
if errors.As(err, &errUnexpectedResponseCode) {
if errUnexpectedResponseCode.Actual == http.StatusConflict {
return true
}
}

return false
}