Skip to content

Commit

Permalink
Pick more nits
Browse files Browse the repository at this point in the history
  • Loading branch information
cybertron committed Jul 30, 2020
1 parent 510b82e commit dad4d9e
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions pkg/monitor/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

const (
table = "nat"
isLoopback = true
notLoopback = false
)

func getHAProxyRuleSpec(apiVip string, apiPort, lbPort uint16, loopback bool) (ruleSpec []string, err error) {
Expand All @@ -37,7 +39,7 @@ func cleanHAProxyFirewallRules(apiVip string, apiPort, lbPort uint16) error {
return err
}

ruleSpec, err := getHAProxyRuleSpec(apiVip, apiPort, lbPort, false)
ruleSpec, err := getHAProxyRuleSpec(apiVip, apiPort, lbPort, notLoopback)
if err != nil {
return err
}
Expand All @@ -52,7 +54,7 @@ func cleanHAProxyFirewallRules(apiVip string, apiPort, lbPort uint16) error {
return err
}
}
ruleSpec, err = getHAProxyRuleSpec(apiVip, apiPort, lbPort, true)
ruleSpec, err = getHAProxyRuleSpec(apiVip, apiPort, lbPort, isLoopback)
if err != nil {
return err
}
Expand All @@ -72,35 +74,33 @@ func ensureHAProxyFirewallRules(apiVip string, apiPort, lbPort uint16) error {
return err
}

ruleSpec, err := getHAProxyRuleSpec(apiVip, apiPort, lbPort, false)
ruleSpec, err := getHAProxyRuleSpec(apiVip, apiPort, lbPort, notLoopback)
if err != nil {
return err
}
chain := "PREROUTING"
if exists, _ := ipt.Exists(table, chain, ruleSpec...); exists {
return nil
} else {
log.WithFields(logrus.Fields{
"spec": strings.Join(ruleSpec, " "),
}).Info("Inserting nat PREROUTING rule")
err = ipt.Insert(table, chain, 1, ruleSpec...)
if err != nil {
return err
}
}
ruleSpec, err = getHAProxyRuleSpec(apiVip, apiPort, lbPort, true)
log.WithFields(logrus.Fields{
"spec": strings.Join(ruleSpec, " "),
}).Info("Inserting nat PREROUTING rule")
err = ipt.Insert(table, chain, 1, ruleSpec...)
if err != nil {
return err
}
ruleSpec, err = getHAProxyRuleSpec(apiVip, apiPort, lbPort, isLoopback)
if err != nil {
return err
}
chain = "OUTPUT"
if exists, _ := ipt.Exists(table, chain, ruleSpec...); exists {
return nil
} else {
log.WithFields(logrus.Fields{
"spec": strings.Join(ruleSpec, " "),
}).Info("Inserting nat OUTPUT rule")
return ipt.Insert(table, chain, 1, ruleSpec...)
}
log.WithFields(logrus.Fields{
"spec": strings.Join(ruleSpec, " "),
}).Info("Inserting nat OUTPUT rule")
return ipt.Insert(table, chain, 1, ruleSpec...)
}

func checkHAProxyFirewallRules(apiVip string, apiPort, lbPort uint16) (bool, error) {
Expand All @@ -109,13 +109,13 @@ func checkHAProxyFirewallRules(apiVip string, apiPort, lbPort uint16) (bool, err
return false, err
}

ruleSpec, err := getHAProxyRuleSpec(apiVip, apiPort, lbPort, false)
ruleSpec, err := getHAProxyRuleSpec(apiVip, apiPort, lbPort, notLoopback)
if err != nil {
return false, err
}
preroutingExists, _ := ipt.Exists(table, "PREROUTING", ruleSpec...)

ruleSpec, err = getHAProxyRuleSpec(apiVip, apiPort, lbPort, true)
ruleSpec, err = getHAProxyRuleSpec(apiVip, apiPort, lbPort, isLoopback)
if err != nil {
return false, err
}
Expand Down

0 comments on commit dad4d9e

Please sign in to comment.