Skip to content

Commit b92d8c6

Browse files
authored
Update NPM logs to use Logf instead of Printf. (#610)
1 parent 644642b commit b92d8c6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

npm/nwpolicy.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ func (npMgr *NetworkPolicyManager) DeleteNetworkPolicy(npObj *networkingv1.Netwo
149149
)
150150

151151
npNs, npName := "ns-"+npObj.ObjectMeta.Namespace, npObj.ObjectMeta.Name
152-
log.Printf("NETWORK POLICY DELETING: Namespace: %s, Name:%s", npNs, npName)
152+
log.Logf("NETWORK POLICY DELETING: Namespace: %s, Name:%s", npNs, npName)
153153

154154
var exists bool
155155
if ns, exists = npMgr.nsMap[npNs]; !exists {
156156
ns, err = newNs(npName)
157157
if err != nil {
158-
log.Printf("Error creating namespace %s", npNs)
158+
log.Logf("Error creating namespace %s", npNs)
159159
}
160160
npMgr.nsMap[npNs] = ns
161161
}
@@ -178,7 +178,7 @@ func (npMgr *NetworkPolicyManager) DeleteNetworkPolicy(npObj *networkingv1.Netwo
178178
if oldPolicy, oldPolicyExists := ns.processedNpMap[hashedSelector]; oldPolicyExists {
179179
deductedPolicy, err := deductPolicy(oldPolicy, npObj)
180180
if err != nil {
181-
log.Printf("Error deducting policy %s from %s", npName, oldPolicy.ObjectMeta.Name)
181+
log.Logf("Error deducting policy %s from %s", npName, oldPolicy.ObjectMeta.Name)
182182
}
183183

184184
if deductedPolicy == nil {
@@ -206,9 +206,9 @@ func createCidrsRule(ingressOrEgress, policyName, ns string, ipsetEntries [][]st
206206
continue
207207
}
208208
setName := policyName + "-in-ns-" + ns + "-" + strconv.Itoa(i) + ingressOrEgress
209-
log.Printf("Creating set: %v, hashedSet: %v", setName, util.GetHashedName(setName))
209+
log.Logf("Creating set: %v, hashedSet: %v", setName, util.GetHashedName(setName))
210210
if err := ipsMgr.CreateSet(setName, spec); err != nil {
211-
log.Printf("Error creating ipset %s", ipCidrSet)
211+
log.Logf("Error creating ipset %s", ipCidrSet)
212212
}
213213
for _, ipCidrEntry := range util.DropEmptyFields(ipCidrSet) {
214214
// Ipset doesn't allow 0.0.0.0/0 to be added. A general solution is split 0.0.0.0/1 in half which convert to
@@ -217,12 +217,12 @@ func createCidrsRule(ingressOrEgress, policyName, ns string, ipsetEntries [][]st
217217
splitEntry := [2]string{"1.0.0.0/1", "128.0.0.0/1"}
218218
for _, entry := range splitEntry {
219219
if err := ipsMgr.AddToSet(setName, entry, util.IpsetNetHashFlag, ""); err != nil {
220-
log.Printf("Error adding ip cidrs %s into ipset %s", entry, ipCidrSet)
220+
log.Logf("Error adding ip cidrs %s into ipset %s", entry, ipCidrSet)
221221
}
222222
}
223223
} else {
224224
if err := ipsMgr.AddToSet(setName, ipCidrEntry, util.IpsetNetHashFlag, ""); err != nil {
225-
log.Printf("Error adding ip cidrs %s into ipset %s", ipCidrEntry, ipCidrSet)
225+
log.Logf("Error adding ip cidrs %s into ipset %s", ipCidrEntry, ipCidrSet)
226226
}
227227
}
228228
}
@@ -235,9 +235,9 @@ func removeCidrsRule(ingressOrEgress, policyName, ns string, ipsetEntries [][]st
235235
continue
236236
}
237237
setName := policyName + "-in-ns-" + ns + "-" + strconv.Itoa(i) + ingressOrEgress
238-
log.Printf("Delete set: %v, hashedSet: %v", setName, util.GetHashedName(setName))
238+
log.Logf("Delete set: %v, hashedSet: %v", setName, util.GetHashedName(setName))
239239
if err := ipsMgr.DeleteSet(setName); err != nil {
240-
log.Printf("Error deleting ipset %s", ipCidrSet)
240+
log.Logf("Error deleting ipset %s", ipCidrSet)
241241
}
242242
}
243243
}

npm/translatePolicy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func translateIngress(ns string, policyName string, targetSelector metav1.LabelS
163163
addedIngressFromEntry, addedPortEntry bool // add drop entries at the end of the chain when there are non ALLOW-ALL* rules
164164
)
165165

166-
log.Printf("started parsing ingress rule")
166+
log.Logf("started parsing ingress rule")
167167

168168
labelsWithOps, _, _ := parseSelector(&targetSelector)
169169
ops, labels := GetOperatorsAndLabels(labelsWithOps)

0 commit comments

Comments
 (0)