Skip to content

Commit

Permalink
fix(ingress-rule): while checking or existing backend do different qu…
Browse files Browse the repository at this point in the history
…eries based on target type (#1100) (#1101)

(cherry picked from commit 8ca7bb9)

Co-authored-by: Tanmoy Sarkar <[email protected]>
  • Loading branch information
mergify[bot] and tanmoysrt authored Nov 24, 2024
1 parent 415fa60 commit 7255ced
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions swiftwave_service/worker/process_ingress_rule_delete_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,21 @@ func (m Manager) IngressRuleDelete(request IngressRuleDeleteRequest, ctx context

// delete backend
backendUsedByOther := true
var ingressRuleCheck core.IngressRule
err = m.ServiceManager.DbClient.Where("id != ? AND application_id = ? AND target_port = ?", ingressRule.ID, ingressRule.ApplicationID, ingressRule.TargetPort).First(&ingressRuleCheck).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
backendUsedByOther = false
var ingressRuleCheckForApplication core.IngressRule
if ingressRule.TargetType == core.ApplicationIngressRule {
err = m.ServiceManager.DbClient.Where("id != ? AND application_id = ? AND target_port = ?", ingressRule.ID, ingressRule.ApplicationID, ingressRule.TargetPort).First(&ingressRuleCheckForApplication).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
backendUsedByOther = false
}
}
}
if ingressRule.TargetType == core.ExternalServiceIngressRule {
err = m.ServiceManager.DbClient.Where("id != ? AND external_service = ?", ingressRule.ID, ingressRule.ExternalService).First(&ingressRuleCheckForApplication).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
backendUsedByOther = false
}
}
}
if !backendUsedByOther {
Expand Down

0 comments on commit 7255ced

Please sign in to comment.