in pkg/cloudmap/resource_manager.go [298:340]
func (m *defaultResourceManager) deleteCloudMapService(ctx context.Context, vn *appmesh.VirtualNode, nsSummary *servicediscovery.NamespaceSummary, svcSummary *serviceSummary) error {
getServiceInput := &servicediscovery.GetServiceInput{Id: awssdk.String(svcSummary.serviceID)}
getServiceOutput, err := m.cloudMapSDK.GetServiceWithContext(ctx, getServiceInput)
if err != nil {
return errors.Wrapf(err, "failed to get cloudMap service")
}
if !m.isCloudMapServiceOwnedByVirtualNode(ctx, getServiceOutput.Service, vn) {
m.log.V(1).Info("skip cloudMap service deletion since it's not owned",
"namespaceName", awssdk.StringValue(nsSummary.Name),
"namespaceID", awssdk.StringValue(nsSummary.Id),
"serviceName", awssdk.StringValue(getServiceOutput.Service.Name),
"serviceID", awssdk.StringValue(getServiceOutput.Service.Id),
)
return nil
}
deleteServiceInput := &servicediscovery.DeleteServiceInput{
Id: awssdk.String(svcSummary.serviceID),
}
deleteServiceBackoff := wait.Backoff{
Steps: 4,
Duration: 15 * time.Second,
Factor: 1.0,
Jitter: 0.1,
Cap: 60 * time.Second,
}
// Delete Service. Ideally we should delete it if there are no registered instances but the call will
// fail if that is the case and we move on. Saves us an additional GET to check the instance count.
if err := retry.OnError(deleteServiceBackoff, func(err error) bool {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == servicediscovery.ErrCodeResourceInUse {
return true
}
return false
}, func() error {
_, err := m.cloudMapSDK.DeleteServiceWithContext(ctx, deleteServiceInput)
return err
}); err != nil {
return err
}
m.removeCloudMapServiceFromServiceSummaryCache(nsSummary, getServiceOutput.Service)
return nil
}