Skip to content

Commit

Permalink
fix: make sensor ops cluster-wide for collectionKeys
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Jorel Lee <joshua.jorel.ee@gmail.com>
  • Loading branch information
Joshua Jorel Lee committed Apr 29, 2024
1 parent 9b6cafe commit 41f5a6e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 12 additions & 7 deletions pkg/sensors/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions pkg/sensors/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ type sensorOp interface {
type sensorAdd struct {
ctx context.Context
name string
ck collectionKey
sensor *Sensor
retChan chan error
}
Expand All @@ -407,7 +406,6 @@ type sensorAdd struct {
type sensorRemove struct {
ctx context.Context
name string
ck collectionKey
all bool
retChan chan error
}
Expand All @@ -416,15 +414,13 @@ type sensorRemove struct {
type sensorEnable struct {
ctx context.Context
name string
ck collectionKey
retChan chan error
}

// sensorDisable disables a sensor
type sensorDisable struct {
ctx context.Context
name string
ck collectionKey
retChan chan error
}

Expand Down

0 comments on commit 41f5a6e

Please sign in to comment.