Skip to content

Commit

Permalink
tetragon: Add support to pass options for spec
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Oct 20, 2023
1 parent f2325e8 commit c088f3d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,19 @@ func createGenericKprobeSensor(
kprobes := spec.KProbes
lists := spec.Lists

options, err := getKprobeOptions(spec.Options)
if err != nil {
return nil, fmt.Errorf("failed to set options: %s", err)
}

// use multi kprobe only if:
// - it's not disable via spec options
// - it's not disabled by user
// - there's support detected
useMulti = !option.Config.DisableKprobeMulti &&
bpf.HasKprobeMulti()
if !options.DisableKprobeMulti {
useMulti = !option.Config.DisableKprobeMulti &&
bpf.HasKprobeMulti()
}

in := addKprobeIn{
useMulti: useMulti,
Expand Down
51 changes: 51 additions & 0 deletions pkg/sensors/tracing/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package tracing

import (
"fmt"
"strconv"

"github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1"
"github.com/cilium/tetragon/pkg/logger"
"github.com/cilium/tetragon/pkg/option"
)

type kprobeOptions struct {
DisableKprobeMulti bool
}

func getKprobeOptions(specs []v1alpha1.OptionSpec) (*kprobeOptions, error) {
type opt struct {
name string
set func(val string) error
}

options := &kprobeOptions{}

var opts = []opt{
opt{
// local --disable-kprobe-multi
name: option.KeyDisableKprobeMulti,
set: func(str string) (err error) {
options.DisableKprobeMulti, err = strconv.ParseBool(str)
return err
},
},
}

for i := range specs {
spec := specs[i]

for j := range opts {
opt := opts[j]

if opt.name == spec.Name {
if err := opt.set(spec.Value); err != nil {
return nil, fmt.Errorf("failed to set option %s: %s", opt.name, err)
}
logger.GetLogger().Infof("Set option %s = %s", spec.Name, spec.Value)
}
}
}

return options, nil
}

0 comments on commit c088f3d

Please sign in to comment.