Skip to content

Commit

Permalink
BUG: BackendSwitchingRuleDeleteAll does not delete all rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmatmati authored and oktalz committed Sep 13, 2022
1 parent 3acf675 commit 1ca13cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/haproxy/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type HAProxyClient interface {
BackendServerDelete(backendName string, serverName string) error
BackendServersGet(backendName string) (models.Servers, error)
BackendSwitchingRuleCreate(frontend string, rule models.BackendSwitchingRule) error
BackendSwitchingRuleDeleteAll(frontend string)
BackendSwitchingRuleDeleteAll(frontend string) error
DefaultsGetConfiguration() (*models.Defaults, error)
DefaultsPushConfiguration(models.Defaults) error
ExecuteRaw(command string) (result []string, err error)
Expand Down
16 changes: 10 additions & 6 deletions pkg/haproxy/api/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,22 @@ func (c *clientNative) BackendSwitchingRuleCreate(frontend string, rule models.B
return configuration.CreateBackendSwitchingRule(frontend, &rule, c.activeTransaction, 0)
}

func (c *clientNative) BackendSwitchingRuleDeleteAll(frontend string) {
logger := utils.GetLogger()
func (c *clientNative) BackendSwitchingRuleDeleteAll(frontend string) (err error) {
configuration, err := c.nativeAPI.Configuration()
if err != nil {
logger.Error(err)
return
}
c.activeTransactionHasChanges = true
err = configuration.DeleteBackendSwitchingRule(0, frontend, c.activeTransaction, 0)
for err != nil {
logger.Error(err)
_, switchingRules, err := configuration.GetBackendSwitchingRules(frontend, c.activeTransaction)
if err != nil {
return
}
for i := 0; i < len(switchingRules); i++ {
if err = configuration.DeleteBackendSwitchingRule(0, frontend, c.activeTransaction, 0); err != nil {
break
}
}
return
}

func (c *clientNative) ServerGet(serverName, backendName string) (models.Server, error) {
Expand Down
7 changes: 5 additions & 2 deletions pkg/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ func AddCustomRoute(route Route, routeACLAnn string, api api.HAProxyClient) (rel

func CustomRoutesReset(api api.HAProxyClient) (err error) {
for _, frontend := range []string{FrontendHTTP, FrontendHTTPS} {
api.BackendSwitchingRuleDeleteAll(frontend)
err = api.BackendSwitchingRuleDeleteAll(frontend)
if err != nil {
break
}
err = api.BackendSwitchingRuleCreate(frontend, models.BackendSwitchingRule{
Name: "%[var(txn.path_match),field(1,.)]",
Index: utils.PtrInt64(0),
Expand All @@ -144,5 +147,5 @@ func CustomRoutesReset(api api.HAProxyClient) (err error) {
return fmt.Errorf("unable to create main backendSwitching rule !!: %w", err)
}
}
return err
return
}

0 comments on commit 1ca13cf

Please sign in to comment.