Skip to content

Commit

Permalink
refactor: Clean up unused stuff
Browse files Browse the repository at this point in the history
- Remove ciliumState field from ProcessManager
- Delete GetProcessEndpoint()

Ref: #794

Signed-off-by: Michi Mutsuzaki <[email protected]>
  • Loading branch information
michi-covalent committed Aug 25, 2023
1 parent ba1b914 commit ec5f235
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 30 deletions.
3 changes: 1 addition & 2 deletions cmd/tetragon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -333,7 +333,6 @@ func tetragonExecute() error {
pm, err := tetragonGrpc.NewProcessManager(
ctx,
&cleanupWg,
ciliumState,
observer.SensorManager,
hookRunner)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/bench/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions pkg/grpc/process_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pkg/grpc/process_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func TestProcessManager_GetProcessExec(t *testing.T) {
_, err = NewProcessManager(
context.Background(),
&wg,
cilium.GetFakeCiliumState(),
nil,
&rthooks.Runner{})
assert.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions pkg/observer/observertesthelper/observer_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 0 additions & 16 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ec5f235

Please sign in to comment.