Skip to content

Commit 6ed037d

Browse files
watcher: Remove unused AddPodInformer function
The pod informer logic has moved to the manager package [^1]. [^1]: #3679 Signed-off-by: Michi Mutsuzaki <[email protected]>
1 parent 43f7b15 commit 6ed037d

File tree

3 files changed

+5
-335
lines changed

3 files changed

+5
-335
lines changed

pkg/process/podinfo_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ package process
55

66
import (
77
"testing"
8-
"time"
98

109
"github.com/cilium/tetragon/api/v1/tetragon"
1110
"github.com/cilium/tetragon/pkg/watcher"
1211
"github.com/stretchr/testify/assert"
13-
"github.com/stretchr/testify/require"
1412
"google.golang.org/protobuf/proto"
1513
"google.golang.org/protobuf/types/known/wrapperspb"
1614
v1 "k8s.io/api/core/v1"
1715
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18-
"k8s.io/client-go/kubernetes/fake"
1916
)
2017

2118
func TestK8sWatcher_GetPodInfo(t *testing.T) {
2219
controller := true
23-
pod := v1.Pod{
20+
var pods []interface{}
21+
pod := &v1.Pod{
2422
ObjectMeta: metav1.ObjectMeta{
2523
Name: "test-pod",
2624
Namespace: "kube-system",
@@ -48,14 +46,11 @@ func TestK8sWatcher_GetPodInfo(t *testing.T) {
4846
},
4947
},
5048
}
49+
pods = append(pods, pod)
5150

52-
k8sClient := fake.NewSimpleClientset(&pod)
53-
k8sWatcher := watcher.NewK8sWatcher(k8sClient, nil, time.Hour)
54-
err := watcher.AddPodInformer(k8sWatcher, true)
55-
require.NoError(t, err)
56-
k8sWatcher.Start()
51+
podAccessor := watcher.NewFakeK8sWatcher(pods)
5752
pid := uint32(1)
58-
podInfo := getPodInfo(k8sWatcher, "abcd1234", "curl", "cilium.io", 1)
53+
podInfo := getPodInfo(podAccessor, "abcd1234", "curl", "cilium.io", 1)
5954
assert.True(t, proto.Equal(podInfo, &tetragon.Pod{
6055
Namespace: pod.Namespace,
6156
Workload: pod.OwnerReferences[0].Name,

pkg/watcher/pod.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010

1111
corev1 "k8s.io/api/core/v1"
1212
"k8s.io/client-go/tools/cache"
13-
14-
"github.com/cilium/tetragon/pkg/podhooks"
1513
)
1614

1715
const (
@@ -40,39 +38,6 @@ type PodAccessor interface {
4038
FindMirrorPod(hash string) (*corev1.Pod, error)
4139
}
4240

43-
func AddPodInformer(w *K8sWatcher, local bool) error {
44-
if w == nil {
45-
return errors.New("k8s watcher not initialized")
46-
}
47-
factory := w.GetK8sInformerFactory()
48-
if local {
49-
factory = w.GetLocalK8sInformerFactory()
50-
}
51-
if factory == nil {
52-
return errors.New("k8s informer factory not initialized")
53-
}
54-
55-
// initialize deleted pod cache
56-
var err error
57-
w.deletedPodCache, err = NewDeletedPodCache()
58-
if err != nil {
59-
return fmt.Errorf("failed to initialize deleted pod cache: %w", err)
60-
}
61-
62-
// add informer to the watcher
63-
informer := factory.Core().V1().Pods().Informer()
64-
w.AddInformer(podInformerName, informer, map[string]cache.IndexFunc{
65-
ContainerIdx: ContainerIndexFunc,
66-
PodIdx: PodIndexFunc,
67-
})
68-
69-
// add event handlers to the informer
70-
informer.AddEventHandler(w.deletedPodCache.EventHandler())
71-
podhooks.InstallHooks(informer)
72-
73-
return nil
74-
}
75-
7641
func ContainerIDKey(contID string) (string, error) {
7742
parts := strings.Split(contID, "//")
7843
if len(parts) != 2 {

pkg/watcher/pod_test.go

Lines changed: 0 additions & 290 deletions
This file was deleted.

0 commit comments

Comments
 (0)