From 41f5a6e2db504a5993f2b7a6c83c6382d3186a1f Mon Sep 17 00:00:00 2001 From: Joshua Jorel Lee Date: Mon, 29 Apr 2024 19:08:19 +0800 Subject: [PATCH] fix: make sensor ops cluster-wide for collectionKeys Signed-off-by: Joshua Jorel Lee --- pkg/sensors/handler.go | 19 ++++++++++++------- pkg/sensors/manager.go | 4 ---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/sensors/handler.go b/pkg/sensors/handler.go index 8dbf1cb067d..a1459ff92ab 100644 --- a/pkg/sensors/handler.go +++ b/pkg/sensors/handler.go @@ -247,10 +247,12 @@ func (h *handler) enableTracingPolicy(op *tracingPolicyEnable) error { } func (h *handler) addSensor(op *sensorAdd) error { - if _, exists := h.collections[op.ck]; exists { - return fmt.Errorf("sensor %s already exists", op.ck) + // Treat sensors as cluster-wide operations + ck := collectionKey{op.name, ""} + if _, exists := h.collections[ck]; exists { + return fmt.Errorf("sensor %s already exists", ck) } - h.collections[op.ck] = collection{ + h.collections[ck] = collection{ sensors: []*Sensor{op.sensor}, name: op.name, } @@ -273,17 +275,20 @@ func (h *handler) removeSensor(op *sensorRemove) error { removeAllSensors(h) return nil } - col, exists := h.collections[op.ck] + // Treat sensors as cluster-wide operations + ck := collectionKey{op.name, ""} + col, exists := h.collections[ck] if !exists { - return fmt.Errorf("sensor %s does not exist", op.ck) + return fmt.Errorf("sensor %s does not exist", ck) } col.destroy() - delete(h.collections, op.ck) + delete(h.collections, ck) return nil } func (h *handler) enableSensor(op *sensorEnable) error { + // Treat sensors as cluster-wide operations ck := collectionKey{op.name, ""} col, exists := h.collections[ck] if !exists { @@ -294,7 +299,7 @@ func (h *handler) enableSensor(op *sensorEnable) error { } func (h *handler) disableSensor(op *sensorDisable) error { - // assume sensors can only be enabled or disabled when not using k8s + // Treat sensors as cluster-wide operations ck := collectionKey{op.name, ""} col, exists := h.collections[ck] if !exists { diff --git a/pkg/sensors/manager.go b/pkg/sensors/manager.go index 4cb0dda7c14..7003e3f1f6a 100644 --- a/pkg/sensors/manager.go +++ b/pkg/sensors/manager.go @@ -398,7 +398,6 @@ type sensorOp interface { type sensorAdd struct { ctx context.Context name string - ck collectionKey sensor *Sensor retChan chan error } @@ -407,7 +406,6 @@ type sensorAdd struct { type sensorRemove struct { ctx context.Context name string - ck collectionKey all bool retChan chan error } @@ -416,7 +414,6 @@ type sensorRemove struct { type sensorEnable struct { ctx context.Context name string - ck collectionKey retChan chan error } @@ -424,7 +421,6 @@ type sensorEnable struct { type sensorDisable struct { ctx context.Context name string - ck collectionKey retChan chan error }