-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tetragon: Add support to pass options for spec
Signed-off-by: Jiri Olsa <[email protected]>
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |