Skip to content

Commit 230122f

Browse files
authored
[NPM] Fixing log noise and removing GetClusterState (#784) (#786)
* Fixing log noise for hotnet pods * Removing GetClusterState usage
1 parent d4f1f4d commit 230122f

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

npm/npm.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,16 @@ func (npMgr *NetworkPolicyManager) SendClusterMetrics() {
116116

117117
for {
118118
<-heartbeat
119-
clusterState := npMgr.GetClusterState()
120-
podCount.Value = float64(clusterState.PodCount)
121-
nsCount.Value = float64(clusterState.NsCount)
122-
nwPolicyCount.Value = float64(clusterState.NwPolicyCount)
119+
npMgr.Lock()
120+
podCount.Value = float64(len(npMgr.podMap))
121+
//Reducing one to remove all-namespaces ns obj
122+
nsCount.Value = float64(len(npMgr.nsMap) - 1)
123+
nwPolCount := 0
124+
for _, ns := range npMgr.nsMap {
125+
nwPolCount = nwPolCount + len(ns.rawNpMap)
126+
}
127+
nwPolicyCount.Value = float64(nwPolCount)
128+
npMgr.Unlock()
123129

124130
metrics.SendMetric(podCount)
125131
metrics.SendMetric(nsCount)

npm/pod.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,21 @@ func (npMgr *NetworkPolicyManager) UpdatePod(oldPodObj, newPodObj *corev1.Pod) e
126126
return nil
127127
}
128128

129+
if isInvalidPodUpdate(oldPodObj, newPodObj) {
130+
return nil
131+
}
132+
129133
// today K8s does not allow updating HostNetwork flag for an existing Pod. So NPM can safely
130134
// check on the oldPodObj for hostNework value
131135
if isHostNetworkPod(oldPodObj) {
132136
log.Logf(
133-
"POD UPDATING ignored for HostNetwork Pod:\n old pod: [%s/%s/%+v/%s/%s]\n new pod: [%s/%s/%+v/%s/%s]",
137+
"POD UPDATING ignored for HostNetwork Pod:\n old pod: [%s/%s/%s]\n new pod: [%s/%s/%s]",
134138
oldPodObj.ObjectMeta.Namespace, oldPodObj.ObjectMeta.Name, oldPodObj.Status.PodIP,
135139
newPodObj.ObjectMeta.Namespace, newPodObj.ObjectMeta.Name, newPodObj.Status.PodIP,
136140
)
137141
return nil
138142
}
139143

140-
if isInvalidPodUpdate(oldPodObj, newPodObj) {
141-
return nil
142-
}
143-
144144
var (
145145
err error
146146
oldPodObjNs = oldPodObj.ObjectMeta.Namespace

0 commit comments

Comments
 (0)