From f2dfd374a0fb0fbe481446ae24f036c6d0edf60c Mon Sep 17 00:00:00 2001 From: vakr Date: Fri, 12 Feb 2021 10:58:18 -0800 Subject: [PATCH 1/2] Fixing log noise for hotnet pods --- npm/pod.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/npm/pod.go b/npm/pod.go index 01f6f44b1c..fc4ffb121e 100644 --- a/npm/pod.go +++ b/npm/pod.go @@ -126,21 +126,21 @@ func (npMgr *NetworkPolicyManager) UpdatePod(oldPodObj, newPodObj *corev1.Pod) e return nil } + if isInvalidPodUpdate(oldPodObj, newPodObj) { + return nil + } + // today K8s does not allow updating HostNetwork flag for an existing Pod. So NPM can safely // check on the oldPodObj for hostNework value if isHostNetworkPod(oldPodObj) { log.Logf( - "POD UPDATING ignored for HostNetwork Pod:\n old pod: [%s/%s/%+v/%s/%s]\n new pod: [%s/%s/%+v/%s/%s]", + "POD UPDATING ignored for HostNetwork Pod:\n old pod: [%s/%s/%s]\n new pod: [%s/%s/%s]", oldPodObj.ObjectMeta.Namespace, oldPodObj.ObjectMeta.Name, oldPodObj.Status.PodIP, newPodObj.ObjectMeta.Namespace, newPodObj.ObjectMeta.Name, newPodObj.Status.PodIP, ) return nil } - if isInvalidPodUpdate(oldPodObj, newPodObj) { - return nil - } - var ( err error oldPodObjNs = oldPodObj.ObjectMeta.Namespace From 9f38595cdf8c290d0b969f7194b30594cc25cf0b Mon Sep 17 00:00:00 2001 From: vakr Date: Fri, 12 Feb 2021 15:45:08 -0800 Subject: [PATCH 2/2] Removing GetClusterState usage --- npm/npm.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/npm/npm.go b/npm/npm.go index b86337d7cc..a4b57afce9 100644 --- a/npm/npm.go +++ b/npm/npm.go @@ -116,10 +116,16 @@ func (npMgr *NetworkPolicyManager) SendClusterMetrics() { for { <-heartbeat - clusterState := npMgr.GetClusterState() - podCount.Value = float64(clusterState.PodCount) - nsCount.Value = float64(clusterState.NsCount) - nwPolicyCount.Value = float64(clusterState.NwPolicyCount) + npMgr.Lock() + podCount.Value = float64(len(npMgr.podMap)) + //Reducing one to remove all-namespaces ns obj + nsCount.Value = float64(len(npMgr.nsMap) - 1) + nwPolCount := 0 + for _, ns := range npMgr.nsMap { + nwPolCount = nwPolCount + len(ns.rawNpMap) + } + nwPolicyCount.Value = float64(nwPolCount) + npMgr.Unlock() metrics.SendMetric(podCount) metrics.SendMetric(nsCount)