Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions npm/ipsm/ipsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (ipsMgr *IpsetManager) CreateList(listName string) error {
set: util.GetHashedName(listName),
spec: []string{util.IpsetSetListFlag},
}
log.Printf("Creating List: %+v", entry)
log.Logf("Creating List: %+v", entry)
if errCode, err := ipsMgr.Run(entry); err != nil && errCode != 1 {
log.Errorf("Error: failed to create ipset list %s.", listName)
return err
Expand Down Expand Up @@ -148,7 +148,7 @@ func (ipsMgr *IpsetManager) AddToList(listName string, setName string) error {
// DeleteFromList removes an ipset to an ipset list.
func (ipsMgr *IpsetManager) DeleteFromList(listName string, setName string) error {
if _, exists := ipsMgr.listMap[listName]; !exists {
log.Printf("ipset list with name %s not found", listName)
log.Logf("ipset list with name %s not found", listName)
return nil
}

Expand Down Expand Up @@ -193,7 +193,7 @@ func (ipsMgr *IpsetManager) CreateSet(setName string, spec []string) error {
set: util.GetHashedName(setName),
spec: spec,
}
log.Printf("Creating Set: %+v", entry)
log.Logf("Creating Set: %+v", entry)
if errCode, err := ipsMgr.Run(entry); err != nil && errCode != 1 {
log.Errorf("Error: failed to create ipset.")
return err
Expand All @@ -207,7 +207,7 @@ func (ipsMgr *IpsetManager) CreateSet(setName string, spec []string) error {
// DeleteSet removes a set from ipset.
func (ipsMgr *IpsetManager) DeleteSet(setName string) error {
if _, exists := ipsMgr.setMap[setName]; !exists {
log.Printf("ipset with name %s not found", setName)
log.Logf("ipset with name %s not found", setName)
return nil
}

Expand Down Expand Up @@ -254,7 +254,7 @@ func (ipsMgr *IpsetManager) AddToSet(setName, ip, spec string) error {
}

if errCode, err := ipsMgr.Run(entry); err != nil && errCode != 1 {
log.Printf("Error: failed to create ipset rules. %+v", entry)
log.Logf("Error: failed to create ipset rules. %+v", entry)
return err
}

Expand All @@ -266,7 +266,7 @@ func (ipsMgr *IpsetManager) AddToSet(setName, ip, spec string) error {
// DeleteFromSet removes an ip from an entry in setMap, and delete/update the corresponding ipset.
func (ipsMgr *IpsetManager) DeleteFromSet(setName, ip string) error {
if _, exists := ipsMgr.setMap[setName]; !exists {
log.Printf("ipset with name %s not found", setName)
log.Logf("ipset with name %s not found", setName)
return nil
}

Expand Down Expand Up @@ -348,7 +348,7 @@ func (ipsMgr *IpsetManager) Run(entry *ipsEntry) (int, error) {
cmdArgs := append([]string{entry.operationFlag, util.IpsetExistFlag, entry.set}, entry.spec...)
cmdArgs = util.DropEmptyFields(cmdArgs)

log.Printf("Executing ipset command %s %v", cmdName, cmdArgs)
log.Logf("Executing ipset command %s %v", cmdName, cmdArgs)
_, err := exec.Command(cmdName, cmdArgs...).Output()
if msg, failed := err.(*exec.ExitError); failed {
errCode := msg.Sys().(syscall.WaitStatus).ExitStatus()
Expand Down
22 changes: 11 additions & 11 deletions npm/iptm/iptm.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewIptablesManager() *IptablesManager {

// InitNpmChains initializes Azure NPM chains in iptables.
func (iptMgr *IptablesManager) InitNpmChains() error {
log.Printf("Initializing AZURE-NPM chains.")
log.Logf("Initializing AZURE-NPM chains.")

if err := iptMgr.AddChain(util.IptablesAzureChain); err != nil {
return err
Expand Down Expand Up @@ -187,7 +187,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
if !exists {
iptMgr.OperationFlag = util.IptablesAppendFlag
if _, err = iptMgr.Run(entry); err != nil {
log.Printf("Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
log.Logf("Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
return err
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func (iptMgr *IptablesManager) AddChain(chain string) error {
errCode, err := iptMgr.Run(entry)
if err != nil {
if errCode == iptablesErrDoesNotExist {
log.Printf("Chain already exists %s.", entry.Chain)
log.Logf("Chain already exists %s.", entry.Chain)
return nil
}

Expand All @@ -285,7 +285,7 @@ func (iptMgr *IptablesManager) DeleteChain(chain string) error {
errCode, err := iptMgr.Run(entry)
if err != nil {
if errCode == iptablesErrDoesNotExist {
log.Printf("Chain doesn't exist %s.", entry.Chain)
log.Logf("Chain doesn't exist %s.", entry.Chain)
return nil
}

Expand All @@ -298,7 +298,7 @@ func (iptMgr *IptablesManager) DeleteChain(chain string) error {

// Add adds a rule in iptables.
func (iptMgr *IptablesManager) Add(entry *IptEntry) error {
log.Printf("Adding iptables entry: %+v.", entry)
log.Logf("Adding iptables entry: %+v.", entry)

if entry.IsJumpEntry {
iptMgr.OperationFlag = util.IptablesAppendFlag
Expand All @@ -315,7 +315,7 @@ func (iptMgr *IptablesManager) Add(entry *IptEntry) error {

// Delete removes a rule in iptables.
func (iptMgr *IptablesManager) Delete(entry *IptEntry) error {
log.Printf("Deleting iptables entry: %+v", entry)
log.Logf("Deleting iptables entry: %+v", entry)

exists, err := iptMgr.Exists(entry)
if err != nil {
Expand Down Expand Up @@ -349,7 +349,7 @@ func (iptMgr *IptablesManager) Run(entry *IptEntry) (int, error) {
cmdArgs := append([]string{util.IptablesWaitFlag, entry.LockWaitTimeInSeconds, iptMgr.OperationFlag, entry.Chain}, entry.Specs...)

if iptMgr.OperationFlag != util.IptablesCheckFlag {
log.Printf("Executing iptables command %s %v", cmdName, cmdArgs)
log.Logf("Executing iptables command %s %v", cmdName, cmdArgs)
}

_, err := exec.Command(cmdName, cmdArgs...).Output()
Expand Down Expand Up @@ -378,7 +378,7 @@ func (iptMgr *IptablesManager) Save(configFile string) error {

defer func(l *os.File) {
if err = l.Close(); err != nil {
log.Printf("Failed to close iptables locks")
log.Logf("Failed to close iptables locks")
}
}(l)

Expand Down Expand Up @@ -414,7 +414,7 @@ func (iptMgr *IptablesManager) Restore(configFile string) error {

defer func(l *os.File) {
if err = l.Close(); err != nil {
log.Printf("Failed to close iptables locks")
log.Logf("Failed to close iptables locks")
}
}(l)

Expand Down Expand Up @@ -452,7 +452,7 @@ func grabIptablesLocks() (*os.File, error) {
// Grab 1.6.x style lock.
l, err := os.OpenFile(util.IptablesLockFile, os.O_CREATE, 0600)
if err != nil {
log.Printf("Error: failed to open iptables lock file %s.", util.IptablesLockFile)
log.Logf("Error: failed to open iptables lock file %s.", util.IptablesLockFile)
return nil, err
}

Expand All @@ -463,7 +463,7 @@ func grabIptablesLocks() (*os.File, error) {

return true, nil
}); err != nil {
log.Printf("Error: failed to acquire new iptables lock: %v.", err)
log.Logf("Error: failed to acquire new iptables lock: %v.", err)
return nil, err
}

Expand Down
14 changes: 7 additions & 7 deletions npm/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (npMgr *NetworkPolicyManager) AddNamespace(nsObj *corev1.Namespace) error {
var err error

nsName, nsLabel := "ns-"+nsObj.ObjectMeta.Name, nsObj.ObjectMeta.Labels
log.Printf("NAMESPACE CREATING: [%s/%v]", nsName, nsLabel)
log.Logf("NAMESPACE CREATING: [%s/%v]", nsName, nsLabel)

ipsMgr := npMgr.nsMap[util.KubeAllNamespacesFlag].ipsMgr
// Create ipset for the namespace.
Expand All @@ -120,14 +120,14 @@ func (npMgr *NetworkPolicyManager) AddNamespace(nsObj *corev1.Namespace) error {
nsLabels := nsObj.ObjectMeta.Labels
for nsLabelKey, nsLabelVal := range nsLabels {
labelKey := "ns-" + nsLabelKey
log.Printf("Adding namespace %s to ipset list %s", nsName, labelKey)
log.Logf("Adding namespace %s to ipset list %s", nsName, labelKey)
if err = ipsMgr.AddToList(labelKey, nsName); err != nil {
log.Errorf("Error: failed to add namespace %s to ipset list %s", nsName, labelKey)
return err
}

label := "ns-" + nsLabelKey + ":" + nsLabelVal
log.Printf("Adding namespace %s to ipset list %s", nsName, label)
log.Logf("Adding namespace %s to ipset list %s", nsName, label)
if err = ipsMgr.AddToList(label, nsName); err != nil {
log.Errorf("Error: failed to add namespace %s to ipset list %s", nsName, label)
return err
Expand All @@ -152,7 +152,7 @@ func (npMgr *NetworkPolicyManager) UpdateNamespace(oldNsObj *corev1.Namespace, n
var err error
oldNsNs, oldNsLabel := "ns-"+oldNsObj.ObjectMeta.Name, oldNsObj.ObjectMeta.Labels
newNsNs, newNsLabel := "ns-"+newNsObj.ObjectMeta.Name, newNsObj.ObjectMeta.Labels
log.Printf(
log.Logf(
"NAMESPACE UPDATING:\n old namespace: [%s/%v]\n new namespace: [%s/%v]",
oldNsNs, oldNsLabel, newNsNs, newNsLabel,
)
Expand All @@ -175,7 +175,7 @@ func (npMgr *NetworkPolicyManager) DeleteNamespace(nsObj *corev1.Namespace) erro
var err error

nsName, nsLabel := "ns-"+nsObj.ObjectMeta.Name, nsObj.ObjectMeta.Labels
log.Printf("NAMESPACE DELETING: [%s/%v]", nsName, nsLabel)
log.Logf("NAMESPACE DELETING: [%s/%v]", nsName, nsLabel)

_, exists := npMgr.nsMap[nsName]
if !exists {
Expand All @@ -187,14 +187,14 @@ func (npMgr *NetworkPolicyManager) DeleteNamespace(nsObj *corev1.Namespace) erro
nsLabels := nsObj.ObjectMeta.Labels
for nsLabelKey, nsLabelVal := range nsLabels {
labelKey := "ns-" + nsLabelKey
log.Printf("Deleting namespace %s from ipset list %s", nsName, labelKey)
log.Logf("Deleting namespace %s from ipset list %s", nsName, labelKey)
if err = ipsMgr.DeleteFromList(labelKey, nsName); err != nil {
log.Errorf("Error: failed to delete namespace %s from ipset list %s", nsName, labelKey)
return err
}

label := "ns-" + nsLabelKey + ":" + nsLabelVal
log.Printf("Deleting namespace %s from ipset list %s", nsName, label)
log.Logf("Deleting namespace %s from ipset list %s", nsName, label)
if err = ipsMgr.DeleteFromList(label, nsName); err != nil {
log.Errorf("Error: failed to delete namespace %s from ipset list %s", nsName, label)
return err
Expand Down
22 changes: 11 additions & 11 deletions npm/nwpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func (npMgr *NetworkPolicyManager) AddNetworkPolicy(npObj *networkingv1.NetworkP
allNs = npMgr.nsMap[util.KubeAllNamespacesFlag]
)

log.Printf("NETWORK POLICY CREATING: %v", npObj)
log.Logf("NETWORK POLICY CREATING: NameSpace%s, Name:%s", npNs, npName)

if ns, exists = npMgr.nsMap[npNs]; !exists {
ns, err = newNs(npNs)
if err != nil {
log.Printf("Error creating namespace %s\n", npNs)
log.Logf("Error creating namespace %s\n", npNs)
}
npMgr.nsMap[npNs] = ns
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func (npMgr *NetworkPolicyManager) AddNetworkPolicy(npObj *networkingv1.NetworkP
if oldPolicy, oldPolicyExists := ns.processedNpMap[hashedSelector]; oldPolicyExists {
addedPolicy, err = addPolicy(oldPolicy, npObj)
if err != nil {
log.Printf("Error adding policy %s to %s", npName, oldPolicy.ObjectMeta.Name)
log.Logf("Error adding policy %s to %s", npName, oldPolicy.ObjectMeta.Name)
}
}

Expand All @@ -99,24 +99,24 @@ func (npMgr *NetworkPolicyManager) AddNetworkPolicy(npObj *networkingv1.NetworkP

sets, namedPorts, lists, ingressIPCidrs, egressIPCidrs, iptEntries = translatePolicy(npObj)
for _, set := range sets {
log.Printf("Creating set: %v, hashedSet: %v", set, util.GetHashedName(set))
log.Logf("Creating set: %v, hashedSet: %v", set, util.GetHashedName(set))
if err = ipsMgr.CreateSet(set, append([]string{util.IpsetNetHashFlag})); err != nil {
log.Printf("Error creating ipset %s", set)
log.Logf("Error creating ipset %s", set)
}
}
for _, set := range namedPorts {
log.Printf("Creating set: %v, hashedSet: %v", set, util.GetHashedName(set))
log.Logf("Creating set: %v, hashedSet: %v", set, util.GetHashedName(set))
if err = ipsMgr.CreateSet(set, append([]string{util.IpsetIPPortHashFlag})); err != nil {
log.Printf("Error creating ipset named port %s", set)
log.Logf("Error creating ipset named port %s", set)
}
}
for _, list := range lists {
if err = ipsMgr.CreateList(list); err != nil {
log.Printf("Error creating ipset list %s", list)
log.Logf("Error creating ipset list %s", list)
}
}
if err = npMgr.InitAllNsList(); err != nil {
log.Printf("Error initializing all-namespace ipset list.")
log.Logf("Error initializing all-namespace ipset list.")
}
createCidrsRule("in", npObj.ObjectMeta.Name, npObj.ObjectMeta.Namespace, ingressIPCidrs, ipsMgr)
createCidrsRule("out", npObj.ObjectMeta.Name, npObj.ObjectMeta.Namespace, egressIPCidrs, ipsMgr)
Expand All @@ -133,7 +133,7 @@ func (npMgr *NetworkPolicyManager) AddNetworkPolicy(npObj *networkingv1.NetworkP
// UpdateNetworkPolicy handles updateing network policy in iptables.
func (npMgr *NetworkPolicyManager) UpdateNetworkPolicy(oldNpObj *networkingv1.NetworkPolicy, newNpObj *networkingv1.NetworkPolicy) error {
if newNpObj.ObjectMeta.DeletionTimestamp == nil && newNpObj.ObjectMeta.DeletionGracePeriodSeconds == nil {
log.Printf("NETWORK POLICY UPDATING:\n old policy:[%v]\n new policy:[%v]", oldNpObj, newNpObj)
log.Logf("NETWORK POLICY UPDATING")
return npMgr.AddNetworkPolicy(newNpObj)
}

Expand All @@ -149,7 +149,7 @@ func (npMgr *NetworkPolicyManager) DeleteNetworkPolicy(npObj *networkingv1.Netwo
)

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

var exists bool
if ns, exists = npMgr.nsMap[npNs]; !exists {
Expand Down
20 changes: 10 additions & 10 deletions npm/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,31 @@ func (npMgr *NetworkPolicyManager) AddPod(podObj *corev1.Pod) error {
ipsMgr = npMgr.nsMap[util.KubeAllNamespacesFlag].ipsMgr
)

log.Printf("POD CREATING: [%s/%s/%s%+v%s]", podNs, podName, podNodeName, podLabels, podIP)
log.Logf("POD CREATING: [%s/%s/%s%+v%s]", podNs, podName, podNodeName, podLabels, podIP)

// Add pod namespace if it doesn't exist
if _, exists := npMgr.nsMap[podNs]; !exists {
log.Printf("Creating set: %v, hashedSet: %v", podNs, util.GetHashedName(podNs))
log.Logf("Creating set: %v, hashedSet: %v", podNs, util.GetHashedName(podNs))
if err = ipsMgr.CreateSet(podNs, append([]string{util.IpsetNetHashFlag})); err != nil {
log.Printf("Error creating ipset %s", podNs)
log.Logf("Error creating ipset %s", podNs)
}
}

// Add the pod to its namespace's ipset.
log.Printf("Adding pod %s to ipset %s", podIP, podNs)
log.Logf("Adding pod %s to ipset %s", podIP, podNs)
if err = ipsMgr.AddToSet(podNs, podIP, util.IpsetNetHashFlag); err != nil {
log.Errorf("Error: failed to add pod to namespace ipset.")
}

// Add the pod to its label's ipset.
for podLabelKey, podLabelVal := range podLabels {
log.Printf("Adding pod %s to ipset %s", podIP, podLabelKey)
log.Logf("Adding pod %s to ipset %s", podIP, podLabelKey)
if err = ipsMgr.AddToSet(podLabelKey, podIP, util.IpsetNetHashFlag); err != nil {
log.Errorf("Error: failed to add pod to label ipset.")
}

label := podLabelKey + ":" + podLabelVal
log.Printf("Adding pod %s to ipset %s", podIP, label)
log.Logf("Adding pod %s to ipset %s", podIP, label)
if err = ipsMgr.AddToSet(label, podIP, util.IpsetNetHashFlag); err != nil {
log.Errorf("Error: failed to add pod to label ipset.")
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (npMgr *NetworkPolicyManager) UpdatePod(oldPodObj, newPodObj *corev1.Pod) e
newPodObjIP = newPodObj.Status.PodIP
)

log.Printf(
log.Logf(
"POD UPDATING:\n old pod: [%s/%s/%+v/%s/%s]\n new pod: [%s/%s/%+v/%s/%s]",
oldPodObjNs, oldPodObjName, oldPodObjLabel, oldPodObjPhase, oldPodObjIP,
newPodObjNs, newPodObjName, newPodObjLabel, newPodObjPhase, newPodObjIP,
Expand Down Expand Up @@ -169,7 +169,7 @@ func (npMgr *NetworkPolicyManager) DeletePod(podObj *corev1.Pod) error {
return nil
}

log.Printf("POD DELETING: [%s/%s/%s%+v%s]", podNs, podName, podNodeName, podLabels, podIP)
log.Logf("POD DELETING: [%s/%s/%s%+v%s]", podNs, podName, podNodeName, podLabels, podIP)

// Delete the pod from its namespace's ipset.
if err = ipsMgr.DeleteFromSet(podNs, podIP); err != nil {
Expand All @@ -178,13 +178,13 @@ func (npMgr *NetworkPolicyManager) DeletePod(podObj *corev1.Pod) error {

// Delete the pod from its label's ipset.
for podLabelKey, podLabelVal := range podLabels {
log.Printf("Deleting pod %s from ipset %s", podIP, podLabelKey)
log.Logf("Deleting pod %s from ipset %s", podIP, podLabelKey)
if err = ipsMgr.DeleteFromSet(podLabelKey, podIP); err != nil {
log.Errorf("Error: failed to delete pod from label ipset.")
}

label := podLabelKey + ":" + podLabelVal
log.Printf("Deleting pod %s from ipset %s", podIP, label)
log.Logf("Deleting pod %s from ipset %s", podIP, label)
if err = ipsMgr.DeleteFromSet(label, podIP); err != nil {
log.Errorf("Error: failed to delete pod from label ipset.")
}
Expand Down
Loading