Skip to content

Commit a556ca4

Browse files
mateiidavidolix0r
andauthored
Lowercase logs and remove redundant lines (#57)
This change cleans up the logging by: * Lowercasing start of log records * Removing redundant lines Signed-off-by: Matei David <[email protected]> Co-authored-by: Oliver Gould <[email protected]>
1 parent 13ac73f commit a556ca4

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

iptables/iptables.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ type FirewallConfiguration struct {
6161
// the pod to join the service mesh. A lot of this logic was based on
6262
// https://github.com/istio/istio/blob/e83411e/pilot/docker/prepare_proxy.sh
6363
func ConfigureFirewall(firewallConfiguration FirewallConfiguration) error {
64-
log.Debugf("Tracing this script execution as [%s]", ExecutionTraceID)
64+
log.Debugf("tracing script execution as [%s]", ExecutionTraceID)
6565

6666
b := bytes.Buffer{}
6767
if err := executeCommand(firewallConfiguration, makeShowAllRules(), &b); err != nil {
68-
log.Error("Aborting firewall configuration")
68+
log.Error("aborting firewall configuration")
6969
return err
7070
}
7171

7272
commands := make([]*exec.Cmd, 0)
7373

7474
matches := chainRegex.FindAllString(b.String(), 1)
7575
if len(matches) > 0 {
76-
log.Infof("Found %d existing chains. Skipping iptables setup.", len(matches))
77-
log.Debugf("Chains: %v", matches)
76+
log.Infof("skipping iptables setup: found %d existing chains", len(matches))
77+
log.Debugf("matching chains: %v", matches)
7878
return nil
7979
}
8080

@@ -84,7 +84,6 @@ func ConfigureFirewall(firewallConfiguration FirewallConfiguration) error {
8484

8585
for _, cmd := range commands {
8686
if err := executeCommand(firewallConfiguration, cmd, nil); err != nil {
87-
log.Error("Aborting firewall configuration")
8887
return err
8988
}
9089
}
@@ -105,18 +104,14 @@ func addOutgoingTrafficRules(commands []*exec.Cmd, firewallConfiguration Firewal
105104

106105
// Ignore traffic from the proxy
107106
if firewallConfiguration.ProxyUID > 0 {
108-
log.Infof("Ignoring uid %d", firewallConfiguration.ProxyUID)
109107
commands = append(commands, makeIgnoreUserID(outputChainName, firewallConfiguration.ProxyUID, "ignore-proxy-user-id"))
110-
} else {
111-
log.Info("Not ignoring any uid")
112108
}
113109

114110
// Ignore loopback
115111
commands = append(commands, makeIgnoreLoopback(outputChainName, "ignore-loopback"))
116112
// Ignore ports
117113
commands = addRulesForIgnoredPorts(firewallConfiguration.OutboundPortsToIgnore, outputChainName, commands)
118114

119-
log.Infof("Redirecting all OUTPUT to %d", firewallConfiguration.ProxyOutgoingPort)
120115
commands = append(commands, makeRedirectChainToPort(outputChainName, firewallConfiguration.ProxyOutgoingPort, "redirect-all-outgoing-to-proxy-port"))
121116

122117
// Redirect all remaining outbound traffic to the proxy.
@@ -151,14 +146,12 @@ func addIncomingTrafficRules(commands []*exec.Cmd, firewallConfiguration Firewal
151146

152147
func addRulesForInboundPortRedirect(firewallConfiguration FirewallConfiguration, chainName string, commands []*exec.Cmd) []*exec.Cmd {
153148
if firewallConfiguration.Mode == RedirectAllMode {
154-
log.Info("Will redirect all INPUT ports to proxy")
155149
// Create a new chain for redirecting inbound and outbound traffic to the proxy port.
156150
commands = append(commands, makeRedirectChainToPort(chainName,
157151
firewallConfiguration.ProxyInboundPort,
158152
"redirect-all-incoming-to-proxy-port"))
159153

160154
} else if firewallConfiguration.Mode == RedirectListedMode {
161-
log.Infof("Will redirect some INPUT ports to proxy: %v", firewallConfiguration.PortsToRedirectInbound)
162155
for _, port := range firewallConfiguration.PortsToRedirectInbound {
163156
commands = append(
164157
commands,
@@ -174,17 +167,13 @@ func addRulesForInboundPortRedirect(firewallConfiguration FirewallConfiguration,
174167

175168
func addRulesForIgnoredPorts(portsToIgnore []string, chainName string, commands []*exec.Cmd) []*exec.Cmd {
176169
for _, destinations := range makeMultiportDestinations(portsToIgnore) {
177-
log.Infof("Will ignore port %s on chain %s", destinations, chainName)
178-
179170
commands = append(commands, makeIgnorePorts(chainName, destinations, fmt.Sprintf("ignore-port-%s", strings.Join(destinations, ","))))
180171
}
181172
return commands
182173
}
183174

184175
func addRulesForIgnoredSubnets(subnetsToIgnore []string, chainName string, commands []*exec.Cmd) []*exec.Cmd {
185176
for _, subnet := range subnetsToIgnore {
186-
log.Infof("Will ignore subnet %s on chain %s", subnet, chainName)
187-
188177
commands = append(commands, makeIgnoreSubnet(chainName, subnet, fmt.Sprintf("ignore-subnet-%s", subnet)))
189178
}
190179
return commands
@@ -214,15 +203,15 @@ func makeMultiportDestinations(portsToIgnore []string) [][]string {
214203
destinations = append(destinations, asDestination(portRange))
215204
destinationPortCount += portCount
216205
} else {
217-
log.Errorf("Invalid port configuration of \"%s\": %s", portOrRange, err.Error())
206+
log.Errorf("invalid port configuration of \"%s\": %s", portOrRange, err.Error())
218207
}
219208
}
220209
return append(destinationSlices, destinations)
221210
}
222211

223212
func executeCommand(firewallConfiguration FirewallConfiguration, cmd *exec.Cmd, cmdOut io.Writer) error {
224213
if strings.HasSuffix(cmd.Path, "iptables") && firewallConfiguration.UseWaitFlag {
225-
log.Info("Setting UseWaitFlag: iptables will wait for xtables to become available")
214+
log.Info("'useWaitFlag' set: iptables will wait for xtables to become available")
226215
cmd.Args = append(cmd.Args, "-w")
227216
}
228217

0 commit comments

Comments
 (0)