Skip to content

Commit

Permalink
tetragon: Add keep-sensors-on-exit option
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Jun 24, 2024
1 parent 23364bb commit 2b70b05
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/tetragon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func tetragonExecute() error {
log.Info("Force loading smallprograms")
}

if option.Config.KeepSensorsOnExit {
log.Info("Not unloading sensors on exit")
}

if viper.IsSet(option.KeyNetnsDir) {
defaults.NetnsDir = viper.GetString(option.KeyNetnsDir)
}
Expand Down Expand Up @@ -457,7 +461,9 @@ func tetragonExecute() error {
return err
}
defer func() {
initialSensor.Unload()
if !option.Config.KeepSensorsOnExit {
initialSensor.Unload()
}
}()

cgrouprate.NewCgroupRate(ctx, pm, base.CgroupRateMap, &option.Config.CgroupRate)
Expand All @@ -468,7 +474,9 @@ func tetragonExecute() error {
sensorMgWait = nil
observer.GetSensorManager().LogSensorsAndProbes(ctx)
defer func() {
observer.RemoveSensors(ctx)
if !option.Config.KeepSensorsOnExit {
observer.RemoveSensors(ctx)
}
}()

err = loadTpFromDir(ctx, option.Config.TracingPolicyDir)
Expand Down
3 changes: 3 additions & 0 deletions docs/data/tetragon_flags.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/option/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ type config struct {

HealthServerAddress string
HealthServerInterval int

KeepSensorsOnExit bool
}

var (
Expand Down
6 changes: 6 additions & 0 deletions pkg/option/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ const (
KeyHealthTimeInterval = "health-server-interval"

KeyBpfDir = "bpf-dir"

KeyKeepSensorsOnExit = "keep-sensors-on-exit"
)

type UsernameMetadaCode int
Expand Down Expand Up @@ -220,6 +222,8 @@ func ReadAndSetFlags() error {
Config.HealthServerInterval = viper.GetInt(KeyHealthTimeInterval)

Config.BpfDir = viper.GetString(KeyBpfDir)

Config.KeepSensorsOnExit = viper.GetBool(KeyKeepSensorsOnExit)
return nil
}

Expand Down Expand Up @@ -376,4 +380,6 @@ func AddFlags(flags *pflag.FlagSet) {
flags.Int(KeyHealthTimeInterval, 10, "Health server interval in seconds")

flags.String(KeyBpfDir, defaults.DefaultMapPrefix, "Set tetragon bpf directory (default 'tetragon')")

flags.Bool(KeyKeepSensorsOnExit, false, "Do not unload sensors on exit")
}

0 comments on commit 2b70b05

Please sign in to comment.