Skip to content

Commit

Permalink
Updating k8s-interface pkg (#109)
Browse files Browse the repository at this point in the history
* wip: remove files after return

* wip: removing files after creating sboms

* do not continue on invalid sboms

* reduce default mem size

Signed-off-by: David Wertenteil <[email protected]>

* update deps

Signed-off-by: David Wertenteil <[email protected]>

* Handle files using workerpool

Signed-off-by: David Wertenteil <[email protected]>

* fixed channel release

Signed-off-by: David Wertenteil <[email protected]>

* remove log

Signed-off-by: David Wertenteil <[email protected]>

* Adding unit tests

Signed-off-by: David Wertenteil <[email protected]>

---------

Signed-off-by: David Wertenteil <[email protected]>
  • Loading branch information
David Wertenteil authored Jul 30, 2023
1 parent 88d7a7f commit 47bffb0
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 60 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/gammazero/workerpool v1.1.3
github.com/inspektor-gadget/inspektor-gadget v0.18.0
github.com/kubescape/go-logger v0.0.13
github.com/kubescape/k8s-interface v0.0.130
github.com/kubescape/k8s-interface v0.0.134
github.com/kubescape/storage v0.0.8
github.com/spf13/afero v1.9.5
github.com/spf13/viper v1.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubescape/go-logger v0.0.13 h1:Rio+grBhpcdExZIVT+HcBVcgbvwrU/aVSV99iKP1NNM=
github.com/kubescape/go-logger v0.0.13/go.mod h1:Tod++iNn5kofkhjpfwjUrqie2YHkLZNoH0Pq0+KldMo=
github.com/kubescape/k8s-interface v0.0.130 h1:lImLm7Y9XvZn1yGb/E8X0CPGT5ukpWnQOs2sa7LH4mA=
github.com/kubescape/k8s-interface v0.0.130/go.mod h1:JHRoGqyMJaALx9mVXfYhOnCDxlEAn9Aw8EIqZOFED80=
github.com/kubescape/k8s-interface v0.0.134 h1:dbXNGM0GH+xj8NadMu5pp1ZPFR90E+62DvWnyU0bdnA=
github.com/kubescape/k8s-interface v0.0.134/go.mod h1:JHRoGqyMJaALx9mVXfYhOnCDxlEAn9Aw8EIqZOFED80=
github.com/kubescape/storage v0.0.8 h1:QnFdBASsiner/TY0lKpimEk/dbxMDHPnPyzCVJKCuW0=
github.com/kubescape/storage v0.0.8/go.mod h1:LDJDA+AxRosIer/1Ma/HSf2SvXgxCH8bYQ9eejAAv8s=
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
Expand Down
14 changes: 7 additions & 7 deletions pkg/containerwatcher/v1/container_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
)

const (
concurrency = 4
execTraceName = "trace_exec"
openTraceName = "trace_open"
eventsWorkersConcurrency = 10
execTraceName = "trace_exec"
openTraceName = "trace_open"
)

type IGContainerWatcher struct {
Expand All @@ -35,7 +35,7 @@ type IGContainerWatcher struct {
tracerCollection *tracercollection.TracerCollection
tracerExec *tracerexec.Tracer
tracerOpen *traceropen.Tracer
workerPool *workerpool.WorkerPool
eventWorkerPool *workerpool.WorkerPool
}

var _ containerwatcher.ContainerWatcher = (*IGContainerWatcher)(nil)
Expand All @@ -54,7 +54,7 @@ func CreateIGContainerWatcher(k8sClient *k8sinterface.KubernetesApi, relevancyMa
k8sClient: k8sClient,
tracerCollection: tracerCollection,
relevancyManager: relevancyManager,
workerPool: workerpool.New(concurrency),
eventWorkerPool: workerpool.New(eventsWorkersConcurrency),
}, nil
}

Expand Down Expand Up @@ -118,7 +118,7 @@ func (ch *IGContainerWatcher) Start(ctx context.Context) error {
if len(event.Args) > 0 {
procImageName = event.Args[0]
}
ch.workerPool.Submit(func() {
ch.eventWorkerPool.Submit(func() {
ch.relevancyManager.ReportFileAccess(ctx, event.Namespace, event.Pod, event.Container, procImageName)
})
}
Expand All @@ -135,7 +135,7 @@ func (ch *IGContainerWatcher) Start(ctx context.Context) error {
return
}
if event.Ret > -1 {
ch.workerPool.Submit(func() {
ch.eventWorkerPool.Submit(func() {
ch.relevancyManager.ReportFileAccess(ctx, event.Namespace, event.Pod, event.Container, event.FullPath)
})
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/filehandler/v1/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ func (s *InMemoryFileHandler) GetFiles(bucket string) (map[string]bool, error) {
return map[string]bool{}, fmt.Errorf("bucket does not exist for container %s", bucket)
}

bucketFiles.lock.RLock()
bucketFiles.lock.Lock()
copy := shallowCopyMapStringBool(bucketFiles.files)
bucketFiles.files = make(map[string]bool, updateFileListLength)
bucketFiles.lock.RUnlock()
bucketFiles.lock.Unlock()

return copy, nil
}
Expand Down
Loading

0 comments on commit 47bffb0

Please sign in to comment.