Skip to content

Commit

Permalink
BUG: fix ssl-redirect precedence order with configmap and ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmatmati authored and oktalz committed Aug 4, 2022
1 parent 7fe7393 commit e1f2299
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions pkg/haproxy/rules/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func (r SectionRules) AddRule(frontend string, rule Rule, ingressRule bool) erro
// Update frontend ruleSet
ruleType := rule.GetType()
ruleID := GetID(rule)
_, ok = ftRuleSet.meta[ruleID]
if ok {
// rule already created
ftRuleSet.meta[ruleID].state = CREATED
} else {
// rule to be created at next refresh
ruleInf, ok := ftRuleSet.meta[ruleID]
if ok && ruleInf.state == TO_DELETE {
// rule already created and planned to be deleted
ruleInf.state = CREATED
} else if !ok {
ftRuleSet.rules[ruleType] = append(ftRuleSet.rules[ruleType], rule)
ftRuleSet.meta[ruleID] = &ruleInfo{state: TO_CREATE}
}

if ingressRule {
ftRuleSet.meta[ruleID].ingress = true
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (i *Ingress) handleAnnotations(k store.K8s, h haproxy.HAProxy) {
var err error
var result = rules.List{}
for _, a := range i.annotations.Frontend(i.resource, &result, h.Maps) {
err = a.Process(k, i.resource.Annotations)
err = a.Process(k, i.resource.Annotations, k.ConfigMaps.Main.Annotations)
if err != nil {
logger.Errorf("Ingress '%s/%s': annotation %s: %s", i.resource.Namespace, i.resource.Name, a.GetName(), err)
}
Expand All @@ -168,6 +168,8 @@ func HandleCfgMapAnnotations(k store.K8s, h haproxy.HAProxy, a annotations.Annot

func addRules(list rules.List, h haproxy.HAProxy, ingressRule bool) []rules.RuleID {
ruleIDs := make([]rules.RuleID, 0, len(list))
// To avoid inserting twice the same rule id in destinating map file
ruleIDSet := map[rules.RuleID]struct{}{}
defaultFrontends := []string{h.FrontHTTP, h.FrontHTTPS}
for _, rule := range list {
frontends := defaultFrontends
Expand All @@ -185,8 +187,12 @@ func addRules(list rules.List, h haproxy.HAProxy, ingressRule bool) []rules.Rule
}
}
for _, frontend := range frontends {
logger.Error(h.AddRule(frontend, rule, ingressRule))
ruleIDs = append(ruleIDs, rules.GetID(rule))
logger.Error(h.AddRule(frontend, rule, ingressRule || rule.GetType() == rules.REQ_REDIRECT))
idRule := rules.GetID(rule)
if _, ok := ruleIDSet[idRule]; !ok {
ruleIDs = append(ruleIDs, idRule)
ruleIDSet[idRule] = struct{}{}
}
}
}
return ruleIDs
Expand Down

0 comments on commit e1f2299

Please sign in to comment.