From 094abd8cfb346582ccc43856b8a11732781aedaf Mon Sep 17 00:00:00 2001 From: Michi Mutsuzaki Date: Fri, 25 Aug 2023 16:54:01 +0000 Subject: [PATCH] refactor: Clean up unused stuff - Remove ciliumState field from ProcessManager - Delete GetProcessEndpoint() Signed-off-by: Michi Mutsuzaki --- cmd/tetragon/main.go | 3 +-- pkg/bench/bench.go | 1 - pkg/grpc/process_manager.go | 12 ++++-------- pkg/grpc/process_manager_test.go | 1 - .../observertesthelper/observer_test_helper.go | 3 +-- pkg/process/process.go | 16 ---------------- 6 files changed, 6 insertions(+), 30 deletions(-) diff --git a/cmd/tetragon/main.go b/cmd/tetragon/main.go index 13bc9ed51ee..44cc2849bbf 100644 --- a/cmd/tetragon/main.go +++ b/cmd/tetragon/main.go @@ -304,7 +304,7 @@ func tetragonExecute() error { if err != nil { return err } - ciliumState, err := cilium.InitCiliumState(ctx, option.Config.EnableCilium) + _, err := cilium.InitCiliumState(ctx, option.Config.EnableCilium) if err != nil { return err } @@ -333,7 +333,6 @@ func tetragonExecute() error { pm, err := tetragonGrpc.NewProcessManager( ctx, &cleanupWg, - ciliumState, observer.SensorManager, hookRunner) if err != nil { diff --git a/pkg/bench/bench.go b/pkg/bench/bench.go index 5ed949b4e29..738987f2ef4 100644 --- a/pkg/bench/bench.go +++ b/pkg/bench/bench.go @@ -227,7 +227,6 @@ func startBenchmarkExporter(ctx context.Context, obs *observer.Observer, summary processManager, err := grpc.NewProcessManager( ctx, &wg, - cilium.GetFakeCiliumState(), observer.SensorManager, hookRunner) if err != nil { diff --git a/pkg/grpc/process_manager.go b/pkg/grpc/process_manager.go index 9bed2cd8dff..39013cbab10 100644 --- a/pkg/grpc/process_manager.go +++ b/pkg/grpc/process_manager.go @@ -11,7 +11,6 @@ import ( "github.com/cilium/tetragon/pkg/eventcache" "github.com/cilium/tetragon/pkg/logger" "github.com/cilium/tetragon/pkg/metrics/eventmetrics" - "github.com/cilium/tetragon/pkg/oldhubble/cilium" "github.com/cilium/tetragon/pkg/option" "github.com/cilium/tetragon/pkg/reader/node" "github.com/cilium/tetragon/pkg/reader/notify" @@ -26,23 +25,20 @@ type ProcessManager struct { nodeName string Server *server.Server // synchronize access to the listeners map. - mux sync.Mutex - listeners map[server.Listener]struct{} - ciliumState *cilium.State + mux sync.Mutex + listeners map[server.Listener]struct{} } // NewProcessManager returns a pointer to an initialized ProcessManager struct. func NewProcessManager( ctx context.Context, wg *sync.WaitGroup, - ciliumState *cilium.State, manager *sensors.Manager, hookRunner *rthooks.Runner, ) (*ProcessManager, error) { pm := &ProcessManager{ - nodeName: node.GetNodeNameForExport(), - ciliumState: ciliumState, - listeners: make(map[server.Listener]struct{}), + nodeName: node.GetNodeNameForExport(), + listeners: make(map[server.Listener]struct{}), } pm.Server = server.NewServer(ctx, wg, pm, manager, hookRunner) diff --git a/pkg/grpc/process_manager_test.go b/pkg/grpc/process_manager_test.go index c33f2ee9161..072ac4d89c9 100644 --- a/pkg/grpc/process_manager_test.go +++ b/pkg/grpc/process_manager_test.go @@ -160,7 +160,6 @@ func TestProcessManager_GetProcessExec(t *testing.T) { _, err = NewProcessManager( context.Background(), &wg, - cilium.GetFakeCiliumState(), nil, &rthooks.Runner{}) assert.NoError(t, err) diff --git a/pkg/observer/observertesthelper/observer_test_helper.go b/pkg/observer/observertesthelper/observer_test_helper.go index f58f847e5ce..5d4ae257cb1 100644 --- a/pkg/observer/observertesthelper/observer_test_helper.go +++ b/pkg/observer/observertesthelper/observer_test_helper.go @@ -349,7 +349,6 @@ func GetDefaultObserverWithFileNoTest(t *testing.T, ctx context.Context, file, l func loadExporter(t *testing.T, ctx context.Context, obs *observer.Observer, opts *testExporterOptions, oo *testObserverOptions) error { watcher := opts.watcher - ciliumState := opts.ciliumState processCacheSize := 32768 dataCacheSize := 1024 @@ -397,7 +396,7 @@ func loadExporter(t *testing.T, ctx context.Context, obs *observer.Observer, opt option.Config.EnableProcessNs = true option.Config.EnableProcessCred = true option.Config.EnableCilium = false - processManager, err := tetragonGrpc.NewProcessManager(ctx, &cancelWg, ciliumState, sensorManager, hookRunner) + processManager, err := tetragonGrpc.NewProcessManager(ctx, &cancelWg, sensorManager, hookRunner) if err != nil { return err } diff --git a/pkg/process/process.go b/pkg/process/process.go index c7cbd5fa723..f27865dc55b 100644 --- a/pkg/process/process.go +++ b/pkg/process/process.go @@ -355,19 +355,3 @@ func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) error { func Get(execId string) (*ProcessInternal, error) { return procCache.get(execId) } - -func GetProcessEndpoint(p *tetragon.Process) *hubblev1.Endpoint { - if p == nil { - return nil - } - if p.Docker == "" { - return nil - } - pod, _, ok := k8s.FindContainer(p.Docker) - if !ok { - logger.GetLogger().WithField("container id", p.Docker).Trace("failed to get pod") - return nil - } - endpoint, _ := cilium.GetCiliumState().GetEndpointsHandler().GetEndpointByPodName(pod.Namespace, pod.Name) - return endpoint -}