Skip to content

Commit

Permalink
fix: improve error handling for tracing policies directory access
Browse files Browse the repository at this point in the history
improve error display when policy dir do not exist when starting tetragon.

Signed-off-by: arthur-zhang <[email protected]>
  • Loading branch information
arthur-zhang authored and mtardy committed Jan 13, 2025
1 parent cd597cb commit 97c115c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmd/tetragon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,18 +577,19 @@ func waitCRDs(config *rest.Config) error {
}

func loadTpFromDir(ctx context.Context, dir string) error {
tpMaxDepth := 1
tpFS := os.DirFS(dir)

if dir == defaults.DefaultTpDir {
// If the default directory does not exist then do not fail
// Probably tetragon not fully installed, developers testing, etc
if _, err := os.Stat(dir); os.IsNotExist(err) {
if _, err := os.Stat(dir); err != nil {
// Do not fail if the default directory doesn't exist,
// it might because of developer setup or incomplete installation
if os.IsNotExist(err) && dir == defaults.DefaultTpDir {
log.WithField("tracing-policy-dir", dir).Info("Loading Tracing Policies from directory ignored, directory does not exist")
return nil
}
return fmt.Errorf("Failed to access tracing policies dir %s: %w", dir, err)
}

tpMaxDepth := 1
tpFS := os.DirFS(dir)

err := fs.WalkDir(tpFS, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
Expand Down

0 comments on commit 97c115c

Please sign in to comment.