Skip to content

Commit

Permalink
Merge pull request #57 from kubescape/bugfix/field-selector
Browse files Browse the repository at this point in the history
Fixing field selector
  • Loading branch information
amitschendel authored Jan 16, 2024
2 parents 2f0a091 + 6485e6e commit 3e18e9f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/collector/pod_finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func (cm *CollectorManager) StartFinalizerWatcher() {
Group: "",
Version: "v1",
Resource: "pods",
}, metav1.ListOptions{})
}, metav1.ListOptions{
FieldSelector: fmt.Sprintf("spec.nodeName=%s", cm.config.NodeName),
})

if err != nil {
log.Printf("Error starting watcher: %v", err)
Expand Down Expand Up @@ -82,10 +84,10 @@ func (cm *CollectorManager) handlePodAddEvent(obj interface{}) {
// Get mutex
cm.podFinalizerStateMutex.Lock()
// Get finalizer state
_, ok := cm.podFinalizerState[generateTableKey(&pod.ObjectMeta)]
_, ok := cm.podFinalizerState[generateTableKey(pod)]
if !ok {
// Add pod to map
cm.podFinalizerState[generateTableKey(&pod.ObjectMeta)] = &PodProfileFinalizerState{
cm.podFinalizerState[generateTableKey(pod)] = &PodProfileFinalizerState{
PodName: pod.GetName(),
Namespace: pod.GetNamespace(),
}
Expand All @@ -110,7 +112,7 @@ func (cm *CollectorManager) handlePodUpdateEvent(obj interface{}) {

// Check if recoding
cm.podFinalizerStateMutex.Lock()
finalizerState, ok := cm.podFinalizerState[generateTableKey(&pod.ObjectMeta)]
finalizerState, ok := cm.podFinalizerState[generateTableKey(pod)]
if !ok || !finalizerState.Recording {
// Discard
cm.podFinalizerStateMutex.Unlock()
Expand All @@ -133,7 +135,7 @@ func (cm *CollectorManager) handlePodUpdateEvent(obj interface{}) {
defer cm.podFinalizerStateMutex.Unlock()

// Check if pod is in map
podState, ok := cm.podFinalizerState[generateTableKey(&pod.ObjectMeta)]
podState, ok := cm.podFinalizerState[generateTableKey(pod)]
if !ok {
log.Printf("Pod %s in namespace %s not in finalizer map", pod.GetName(), pod.GetNamespace())
return
Expand Down

0 comments on commit 3e18e9f

Please sign in to comment.