Skip to content

Commit

Permalink
tetra: add cgroup id command in policyfilter
Browse files Browse the repository at this point in the history
When troubleshooting it is often useful to get the cgroup id from a
file. Add a CLI command for doing so.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Mar 6, 2024
1 parent 3c30bc0 commit 6cfaf0a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/tetra/policyfilter/policyfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package policyfilter

import (
"fmt"
"path/filepath"
"strconv"

Expand All @@ -26,11 +27,32 @@ func New() *cobra.Command {
ret.AddCommand(
dumpCmd(),
addCommand(),
cgroupGetIDCommand(),
)

return ret
}

func cgroupGetIDCommand() *cobra.Command {
mapFname := filepath.Join(defaults.DefaultMapRoot, defaults.DefaultMapPrefix, policyfilter.MapName)
ret := &cobra.Command{
Use: "cgroupid",
Short: "retrieve cgroup id from file",
Args: cobra.ExactArgs(1),
Run: func(_ *cobra.Command, args []string) {
cgID, err := cgroups.GetCgroupIdFromPath(args[0])
if err != nil {
logger.GetLogger().WithError(err).Fatal("Failed to parse cgroup")
}
fmt.Printf("%d\n", cgID)
},
}

flags := ret.Flags()
flags.StringVar(&mapFname, "map-fname", mapFname, "policyfilter map filename")
return ret
}

func dumpCmd() *cobra.Command {
mapFname := filepath.Join(defaults.DefaultMapRoot, defaults.DefaultMapPrefix, policyfilter.MapName)
ret := &cobra.Command{
Expand Down

0 comments on commit 6cfaf0a

Please sign in to comment.