Skip to content

Commit

Permalink
Handle ConsumeRemoteOffer when saas application already exists
Browse files Browse the repository at this point in the history
Creation of multiple resource integrations to same offer may lead
to error for one of the integration as both the integrations tries
to add remote offer to the model. One of them errors out with message
saas application already exists.
Check for the error message while consuming the remote offer. If the
error message says saas application is already created, proceed with
the integration instead of erroring out.
  • Loading branch information
hemanthnakkina committed Sep 28, 2023
1 parent 7f6d944 commit c640d8e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/juju/offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,19 @@ func (c offersClient) ConsumeRemoteOffer(input *ConsumeRemoteOfferInput) (*Consu

localName, err := client.Consume(consumeArgs)
if err != nil {
return nil, err
// Check if SAAS is already created. If so return offer response instead of error
if strings.Contains(err.Error(), "saas application already exists") {
/* The logic to populate localName is picked from on how the juju controller
derives localName in Consume request.
https://github.com/juju/juju/blob/3e561add5940a510f785c83076b2bcc6994db103/api/client/application/client.go#L803
*/
localName = consumeArgs.Offer.OfferName
if consumeArgs.ApplicationAlias != "" {
localName = consumeArgs.ApplicationAlias
}
} else {
return nil, err
}
}

response := ConsumeRemoteOfferResponse{
Expand Down

0 comments on commit c640d8e

Please sign in to comment.