From c640d8ea93f2db451c2278cdaa89aa82dd17ad55 Mon Sep 17 00:00:00 2001 From: Hemanth Nakkina Date: Sun, 24 Sep 2023 19:32:58 +0530 Subject: [PATCH] Handle ConsumeRemoteOffer when saas application already exists 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. --- internal/juju/offers.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/juju/offers.go b/internal/juju/offers.go index c448b424..7eb736f2 100644 --- a/internal/juju/offers.go +++ b/internal/juju/offers.go @@ -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{