From fa56ad8bc3313de1892e11fccca27c83e4cdc6e0 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 19 May 2017 14:26:10 +0000 Subject: [PATCH] Refactor: move logging of ipset entries down to ipset package --- npc/ipset/ipset.go | 8 ++++++-- npc/selector.go | 2 -- prog/weave-npc/main.go | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/npc/ipset/ipset.go b/npc/ipset/ipset.go index d4dd5160..b88e05b4 100644 --- a/npc/ipset/ipset.go +++ b/npc/ipset/ipset.go @@ -1,6 +1,7 @@ package ipset import ( + "log" "os/exec" "strings" @@ -31,10 +32,11 @@ type Interface interface { type ipset struct { refCount + *log.Logger } -func New() Interface { - return &ipset{refCount: newRefCount()} +func New(logger *log.Logger) Interface { + return &ipset{refCount: newRefCount(), Logger: logger} } func (i *ipset) Create(ipsetName Name, ipsetType Type) error { @@ -42,6 +44,7 @@ func (i *ipset) Create(ipsetName Name, ipsetType Type) error { } func (i *ipset) AddEntry(ipsetName Name, entry string) error { + i.Logger.Printf("adding entry %s to %s", entry, ipsetName) if i.inc(ipsetName, entry) > 1 { // already in the set return nil } @@ -49,6 +52,7 @@ func (i *ipset) AddEntry(ipsetName Name, entry string) error { } func (i *ipset) DelEntry(ipsetName Name, entry string) error { + i.Logger.Printf("deleting entry %s from %s", entry, ipsetName) if i.dec(ipsetName, entry) > 0 { // still needed return nil } diff --git a/npc/selector.go b/npc/selector.go index 1f34fa3b..ba897ad1 100644 --- a/npc/selector.go +++ b/npc/selector.go @@ -43,12 +43,10 @@ func (s *selector) matches(labelMap map[string]string) bool { } func (s *selector) addEntry(entry string) error { - common.Log.Infof("adding entry %s to %s", entry, s.spec.ipsetName) return s.ips.AddEntry(s.spec.ipsetName, entry) } func (s *selector) delEntry(entry string) error { - common.Log.Infof("deleting entry %s from %s", entry, s.spec.ipsetName) return s.ips.DelEntry(s.spec.ipsetName, entry) } diff --git a/prog/weave-npc/main.go b/prog/weave-npc/main.go index 185b1d91..4a303387 100644 --- a/prog/weave-npc/main.go +++ b/prog/weave-npc/main.go @@ -135,7 +135,7 @@ func root(cmd *cobra.Command, args []string) { ipt, err := iptables.New() handleError(err) - ips := ipset.New() + ips := ipset.New(common.LogLogger()) handleError(resetIPTables(ipt)) handleError(resetIPSets(ips))