Skip to content

Commit

Permalink
chore!: change crs flag/key to cri
Browse files Browse the repository at this point in the history
BREAKING CHANGE: change crs flag to cri
  • Loading branch information
geyslan committed Oct 30, 2023
1 parent d153274 commit 86c1209
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 59 deletions.
4 changes: 2 additions & 2 deletions cmd/tracee-ebpf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func main() {
Usage: "process tree options. run '--proctree help' for more info.",
},
&cli.StringSliceFlag{
Name: "crs",
Usage: "define connected container runtimes. run '--crs help' for more info.",
Name: "cri",
Usage: "define connected container runtimes. run '--cri help' for more info.",
Value: cli.NewStringSlice(),
},
&cli.IntFlag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/tracee/cmd/man.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ var configCmd = &cobra.Command{
}

var containersCmd = &cobra.Command{
Use: "crs",
Use: "cri",
Aliases: []string{},
Short: "containers flag help",
RunE: func(cmd *cobra.Command, args []string) error {
return runManForFlag("crs")
return runManForFlag("cri")
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/tracee/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ func initCmd() error {
}

rootCmd.Flags().StringArray(
"crs",
"cri",
[]string{},
"<runtime:socket>\t\t\tDefine connected container runtimes",
)
err = viper.BindPFlag("crs", rootCmd.Flags().Lookup("crs"))
err = viper.BindPFlag("cri", rootCmd.Flags().Lookup("cri"))
if err != nil {
return errfmt.WrapError(err)
}
Expand Down
4 changes: 2 additions & 2 deletions deploy/helm/tracee/templates/tracee-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ data:
capabilities:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.config.crs }}
crs:
{{- with .Values.config.cri }}
cri:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.config.rego }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/tracee/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ config:
installPath: ""
signaturesDir: ""
capabilities: []
crs: []
cri: []
rego: []
cache:
- cache-type=mem
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/deep-dive/caching-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sudo ./dist/tracee \
-o format:json \
-o option:parse-arguments \
-trace container \
--crs docker:/var/run/docker.sock
--cri docker:/var/run/docker.sock
```

!!! Attention
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/flags/containers.1.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
title: TRACEE-CRS
title: TRACEE-CRI
section: 1
header: Tracee CRS Flag Manual
header: Tracee CRI Flag Manual
date: 2023/10
...

## NAME

tracee **\-\-crs** - Select container runtimes to connect to for container events enrichment
tracee **\-\-cri** - Select container runtimes to connect to for container events enrichment

## SYNOPSIS

tracee **\-\-crs** <[crio|containerd|docker|podman]:socket\> [**\-\-crs** ...] ...
tracee **\-\-cri** <[crio|containerd|docker|podman]:socket\> [**\-\-cri** ...] ...

## DESCRIPTION

Expand All @@ -22,7 +22,7 @@ By default, if no flag is passed, Tracee will automatically detect installed run
3. **CRI-O**: `/var/run/crio/crio.sock`
4. **Podman**: `/var/run/podman/podman.sock`

If runtimes are specified using the **\-\-crs** flag, only the ones passed through the flags will be connected to through the provided socket file path.
If runtimes are specified using the **\-\-cri** flag, only the ones passed through the flags will be connected to through the provided socket file path.

Supported runtimes are:

Expand All @@ -36,7 +36,7 @@ Supported runtimes are:
- To connect to CRI-O using the socket file path `/var/run/crio/crio.sock`, use the following flag:

```console
--crs crio:/var/run/crio/crio.sock
--cri crio:/var/run/crio/crio.sock
```

Please refer to the [documentation](../integrating/container-engines.md) for more information on container events enrichment.
12 changes: 6 additions & 6 deletions docs/man/containers.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "TRACEE-CRS" "1" "2023/10" "" "Tracee CRS Flag Manual"
.TH "TRACEE-CRI" "1" "2023/10" "" "Tracee CRI Flag Manual"
.hy
.SS NAME
.PP
tracee \f[B]--crs\f[R] - Select container runtimes to connect to for
tracee \f[B]--cri\f[R] - Select container runtimes to connect to for
container events enrichment
.SS SYNOPSIS
.PP
tracee \f[B]--crs\f[R] <[crio|containerd|docker|podman]:socket>
[\f[B]--crs\f[R] \&...]
tracee \f[B]--cri\f[R] <[crio|containerd|docker|podman]:socket>
[\f[B]--cri\f[R] \&...]
\&...
.SS DESCRIPTION
.PP
Expand All @@ -39,7 +39,7 @@ for the following paths:
.IP "4." 3
\f[B]Podman\f[R]: \f[V]/var/run/podman/podman.sock\f[R]
.PP
If runtimes are specified using the \f[B]--crs\f[R] flag, only the ones
If runtimes are specified using the \f[B]--cri\f[R] flag, only the ones
passed through the flags will be connected to through the provided
socket file path.
.PP
Expand All @@ -60,7 +60,7 @@ To connect to CRI-O using the socket file path
.IP
.nf
\f[C]
--crs crio:/var/run/crio/crio.sock
--cri crio:/var/run/crio/crio.sock
\f[R]
.fi
.RE
Expand Down
2 changes: 1 addition & 1 deletion examples/config/global_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"none"
],
"capabilities": [],
"crs": [],
"cri": [],
"healthz": false,
"install-path": "/tmp/tracee",
"listen-addr": ":3366",
Expand Down
2 changes: 1 addition & 1 deletion examples/config/global_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ capabilities:
# drop:
# - cap_chown

crs:
cri:
# - runtime:
# name: containerd
# socket: /var/run/containerd/containerd.sock
Expand Down
2 changes: 1 addition & 1 deletion examples/config/global_config_cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ proctree:
- none
capabilities: []
containers: false
crs: []
cri: []
healthz: false
install-path: /tmp/tracee
listen-addr: :3366
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ nav:
- output: docs/flags/output.1.md
- capture: docs/flags/capture.1.md
- config: docs/flags/config.1.md
- crs: docs/flags/containers.1.md
- cri: docs/flags/containers.1.md
- rego: docs/flags/rego.1.md
- cache: docs/flags/cache.1.md
- capabilities: docs/flags/capabilities.1.md
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cobra/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ func GetTraceeRunner(c *cobra.Command, version string) (cmd.Runner, error) {
// Container Runtime command line flags

if !cfg.NoContainersEnrich {
crsFlags, err := GetFlagsFromViper("crs")
criFlags, err := GetFlagsFromViper("cri")
if err != nil {
return runner, err
}

sockets, err := flags.PrepareContainers(crsFlags)
sockets, err := flags.PrepareContainers(criFlags)
if err != nil {
return runner, err
}
Expand Down
30 changes: 15 additions & 15 deletions pkg/cmd/cobra/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func GetFlagsFromViper(key string) ([]string, error) {
flagger = &ProcTreeConfig{}
case "capabilities":
flagger = &CapabilitiesConfig{}
case "crs":
case "cri":
switch v := rawValue.(type) {
case []string: // via cli
return getConfigFlags(rawValue, nil, "crs")
return getConfigFlags(rawValue, nil, "cri")
case []interface{}: // via config file
return getCRSConfigFlags(rawValue)
return getCRIConfigFlags(rawValue)
default:
return nil, errfmt.Errorf("unrecognized type %T for crs", v)
return nil, errfmt.Errorf("unrecognized type %T for cri", v)
}
case "log":
flagger = &LogConfig{}
Expand Down Expand Up @@ -76,29 +76,29 @@ func getConfigFlags(rawValue interface{}, flagger cliFlagger, key string) ([]str
}
}

// getCRSConfigFlags handles the crs config key, which is a special case.
// getCRIConfigFlags handles the cri config key, which is a special case.
// For structured flags, it uses mapstructure to decode the config into a
// CRSConfig struct. For raw cli flags, it returns the raw values as strings.
func getCRSConfigFlags(rawValue interface{}) ([]string, error) {
// CRIConfig struct. For raw cli flags, it returns the raw values as strings.
func getCRIConfigFlags(rawValue interface{}) ([]string, error) {
rawValues, ok := rawValue.([]interface{})
if !ok {
return nil, errfmt.Errorf("unrecognized type %T for crs", rawValue)
return nil, errfmt.Errorf("unrecognized type %T for cri", rawValue)
}

flags := make([]string, 0)
flagger := &CRSConfig{}
flagger := &CRIConfig{}
for _, raw := range rawValues {
switch v := raw.(type) {
// raw cli flags
case string:
// crs:
// cri:
// - containerd:/var/run/containerd/containerd.sock
// - docker:/var/run/docker.sock
flags = append(flags, v)

// structured flags
case map[string]interface{}:
// crs:
// cri:
// - runtime:
// name: containerd
// socket: /var/run/containerd/containerd.sock
Expand All @@ -115,7 +115,7 @@ func getCRSConfigFlags(rawValue interface{}) ([]string, error) {
flags = append(flags, flagger.flags()...)

default:
return nil, errfmt.Errorf("unrecognized type %T for crs", v)
return nil, errfmt.Errorf("unrecognized type %T for cri", v)
}
}

Expand Down Expand Up @@ -225,15 +225,15 @@ func (c *CapabilitiesConfig) flags() []string {
}

//
// crs flag
// cri flag
//

type CRSConfig struct {
type CRIConfig struct {
Name string `mapstructure:"name"`
Socket string `mapstructure:"socket"`
}

func (c *CRSConfig) flags() []string {
func (c *CRIConfig) flags() []string {
flags := make([]string, 0)

if c.Name != "" && c.Socket != "" {
Expand Down
22 changes: 11 additions & 11 deletions pkg/cmd/cobra/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,32 +146,32 @@ capabilities:
},
},
{
name: "Test crs configuration (cli flags)",
name: "Test cri configuration (cli flags)",
yamlContent: `
crs:
cri:
- test1:/var/run/test1.sock
- test2:/var/run/test2.sock
`,
key: "crs",
key: "cri",
expectedFlags: []string{
"test1:/var/run/test1.sock",
"test2:/var/run/test2.sock",
},
},
{
name: "Test crs configuration (structured flags)",
name: "Test cri configuration (structured flags)",
// test1: /var/run/test1.sock
// test2: /var/run/test2.sock
yamlContent: `
crs:
cri:
- runtime:
name: test1
socket: /var/run/test1.sock
- runtime:
name: test2
socket: /var/run/test2.sock
`,
key: "crs",
key: "cri",
expectedFlags: []string{
"test1:/var/run/test1.sock",
"test2:/var/run/test2.sock",
Expand Down Expand Up @@ -737,28 +737,28 @@ func TestCapabilitiesConfigFlags(t *testing.T) {
}

//
// crs
// cri
//

func TestCRSConfigFlag(t *testing.T) {
func TestCRIConfigFlag(t *testing.T) {
t.Parallel()

tests := []struct {
name string
config CRSConfig
config CRIConfig
expected []string
}{
{
name: "empty config",
config: CRSConfig{
config: CRIConfig{
Name: "",
Socket: "",
},
expected: []string{},
},
{
name: "valid config",
config: CRSConfig{
config: CRIConfig{
Name: "testName",
Socket: "/var/run/socket.sock",
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/flags/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Supported runtimes are:
4. Podman (podman)
Example:
--crs crio:/var/run/crio/crio.sock
--cri crio:/var/run/crio/crio.sock
`
}

Expand Down Expand Up @@ -63,7 +63,7 @@ func PrepareContainers(containerFlags []string) (runtime.Sockets, error) {
containerRuntime := parts[0]

if !contains(supportedRuntimes, containerRuntime) {
return sockets, errfmt.Errorf("provided unsupported container runtime (see --crs help for supported runtimes)")
return sockets, errfmt.Errorf("provided unsupported container runtime (see --cri help for supported runtimes)")
}

socket := parts[1]
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/flags/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// It is used only by the old binary (tracee-ebpf).
func PrintAndExitIfHelp(ctx *cli.Context) {
keys := []string{
"crs",
"cri",
"cache",
"proctree",
"capture",
Expand Down Expand Up @@ -48,7 +48,7 @@ func GetHelpString(key string) string {
switch key {
case "config":
return configHelp()
case "crs":
case "cri":
return containersHelp()
case "cache":
return cacheHelp()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/urfave/urfave.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func GetTraceeRunner(c *cli.Context, version string) (cmd.Runner, error) {
// Container Runtime command line flags

if !cfg.NoContainersEnrich {
sockets, err := flags.PrepareContainers(c.StringSlice("crs"))
sockets, err := flags.PrepareContainers(c.StringSlice("cri"))
if err != nil {
return runner, err
}
Expand Down

0 comments on commit 86c1209

Please sign in to comment.