Skip to content

Commit

Permalink
tetragon: Plug in the config object
Browse files Browse the repository at this point in the history
Adding --config-file option that allows to start tetragon
with config file using the config object.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Mar 12, 2024
1 parent 474c54b commit 020d2c3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/tetragon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cilium/tetragon/pkg/bugtool"
"github.com/cilium/tetragon/pkg/checkprocfs"
"github.com/cilium/tetragon/pkg/cilium"
"github.com/cilium/tetragon/pkg/config"
"github.com/cilium/tetragon/pkg/defaults"
"github.com/cilium/tetragon/pkg/encoder"
"github.com/cilium/tetragon/pkg/exporter"
Expand Down Expand Up @@ -436,6 +437,12 @@ func tetragonExecute() error {
base.Unload()
}()

cfg := config.NewConfig(option.Config.ConfigFile, 5*time.Second,
func(_ uint64, spec config.Spec) {
config.OptionsReconfig(spec)
})
defer cfg.Stop()

// now that the base sensor was loaded, we can start the sensor manager
close(sensorMgWait)
sensorMgWait = nil
Expand Down
2 changes: 2 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.

12 changes: 12 additions & 0 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Tetragon

package config

import "github.com/cilium/tetragon/pkg/option"

func OptionsReconfig(spec Spec) {
if spec.Options.DisableKprobeMulti != nil {
option.Config.DisableKprobeMulti = *spec.Options.DisableKprobeMulti
}
}
2 changes: 2 additions & 0 deletions pkg/option/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type config struct {
EnableTracingPolicyCRD bool

ExposeKernelAddresses bool

ConfigFile string
}

var (
Expand Down
5 changes: 5 additions & 0 deletions pkg/option/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ const (
KeyExposeKernelAddresses = "expose-kernel-addresses"

KeyGenerateDocs = "generate-docs"

KeyConfigFile = "config-file"
)

func ReadAndSetFlags() error {
Expand Down Expand Up @@ -172,6 +174,7 @@ func ReadAndSetFlags() error {

Config.ExposeKernelAddresses = viper.GetBool(KeyExposeKernelAddresses)

Config.ConfigFile = viper.GetString(KeyConfigFile)
return nil
}

Expand Down Expand Up @@ -278,4 +281,6 @@ func AddFlags(flags *pflag.FlagSet) {
flags.Bool(KeyExposeKernelAddresses, false, "Expose real kernel addresses in events stack traces")

flags.Bool(KeyGenerateDocs, false, "Generate documentation in YAML format to stdout")

flags.String(KeyConfigFile, "", "configuration file")
}

0 comments on commit 020d2c3

Please sign in to comment.