Skip to content

Commit 90da220

Browse files
committed
consider include/exclude ns in continuous scanning
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
1 parent 23358ca commit 90da220

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

continuousscanning/service.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package continuousscanning
33
import (
44
"context"
55

6+
"github.com/kubescape/operator/config"
67
"github.com/kubescape/operator/watcher"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89
"k8s.io/apimachinery/pkg/watch"
@@ -14,6 +15,7 @@ import (
1415
)
1516

1617
type ContinuousScanningService struct {
18+
cfg config.IConfig
1719
tl TargetLoader
1820
shutdownRequested chan struct{}
1921
workDone chan struct{}
@@ -44,6 +46,7 @@ func (s *ContinuousScanningService) listen(ctx context.Context) <-chan armoapi.C
4446
"got event from channel",
4547
helpers.Interface("event", e),
4648
)
49+
s.cfg.SkipNamespace(e.Object.(metav1.Object).GetNamespace())
4750
out.Enqueue(e)
4851
case <-shutdownCh:
4952
return
@@ -100,12 +103,13 @@ func (s *ContinuousScanningService) Stop() {
100103
<-s.workDone
101104
}
102105

103-
func NewContinuousScanningService(client dynamic.Interface, tl TargetLoader, h ...EventHandler) *ContinuousScanningService {
106+
func NewContinuousScanningService(cfg config.IConfig, client dynamic.Interface, tl TargetLoader, h ...EventHandler) *ContinuousScanningService {
104107
doneCh := make(chan struct{})
105108
eventQueue := watcher.NewCooldownQueue()
106109
workDone := make(chan struct{})
107110

108111
return &ContinuousScanningService{
112+
cfg: cfg,
109113
tl: tl,
110114
k8sdynamic: client,
111115
shutdownRequested: doneCh,

continuousscanning/service_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ func TestAddEventHandler(t *testing.T) {
151151
tl := NewTargetLoader(f)
152152
// We use the spy handler later to verify if it's been called
153153
spyH := &spyHandler{called: false, wg: resourcesCreatedWg, mx: &sync.RWMutex{}}
154-
css := NewContinuousScanningService(dynClient, tl, spyH)
154+
operatorConfig := config.NewOperatorConfig(config.CapabilitiesConfig{}, utilsmetadata.ClusterConfig{}, &beUtils.Credentials{}, "", config.Config{Namespace: "kubescape"})
155+
css := NewContinuousScanningService(operatorConfig, dynClient, tl, spyH)
155156
css.Launch(ctx)
156157

157158
// Create Pods to be listened
@@ -264,7 +265,7 @@ func TestContinuousScanningService(t *testing.T) {
264265
triggeringHandler := NewTriggeringHandler(wp, operatorConfig)
265266
stubFetcher := &stubFetcher{podMatchRules}
266267
loader := NewTargetLoader(stubFetcher)
267-
css := NewContinuousScanningService(dynClient, loader, triggeringHandler)
268+
css := NewContinuousScanningService(operatorConfig, dynClient, loader, triggeringHandler)
268269
css.Launch(ctx)
269270

270271
// Create Pods to be listened

continuousscanning/watchbuilder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func NewDynamicWatch(ctx context.Context, client dynamic.Interface, gvr schema.G
1717
var w watch.Interface
1818
var err error
1919
if k8sinterface.IsNamespaceScope(&gvr) {
20-
w, err = client.Resource(gvr).Namespace("").Watch(ctx, opts) // TODO support ExcludeNamespaces and IncludeNamespaces
20+
w, err = client.Resource(gvr).Namespace("").Watch(ctx, opts)
2121
} else {
2222
w, err = client.Resource(gvr).Watch(ctx, opts)
2323
}

mainhandler/handlerequests.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (mainHandler *MainHandler) SetupContinuousScanning(ctx context.Context) err
133133
loader := cs.NewTargetLoader(fetcher)
134134

135135
dynClient := mainHandler.k8sAPI.DynamicClient
136-
svc := cs.NewContinuousScanningService(dynClient, loader, triggeringHandler, deletingHandler)
136+
svc := cs.NewContinuousScanningService(mainHandler.config, dynClient, loader, triggeringHandler, deletingHandler)
137137
svc.Launch(ctx)
138138

139139
return nil

0 commit comments

Comments
 (0)