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

fix(ingress-rule): while checking or existing backend do different queries based on target type #1100

Merged
merged 1 commit into from
Nov 24, 2024
Merged
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
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
Loading