Skip to content

Commit

Permalink
feat: Add namespace reference to tetra cli
Browse files Browse the repository at this point in the history
By adding a collectionKey to differentiate namespaces, the CLI needs to be updated to support this update. This change adds a namespace flag to the CLI for the delete, enable, and disable commands. If the namespace flag is unset, it will reference the global TracingPolicy.

Fixes: #2299

Signed-off-by: Joshua Jorel Lee <joshua.jorel.lee@gmail.com>
  • Loading branch information
joshuajorel committed May 20, 2024
1 parent d5641fd commit 6ec273f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/tetra/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
KeyServerAddress = "server-address" // string
KeyTimeout = "timeout" // duration
KeyRetries = "retries" // int
KeyNamespace = "namespace" //string
)

const (
Expand Down
18 changes: 15 additions & 3 deletions cmd/tetra/tracingpolicy/tracingpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func New() *cobra.Command {
},
}

var tpDelNamespaceFlag string
tpDelCmd := &cobra.Command{
Use: "delete <name>",
Short: "delete a tracing policy",
Expand All @@ -56,7 +57,8 @@ func New() *cobra.Command {
defer c.Close()

_, err := c.Client.DeleteTracingPolicy(c.Ctx, &tetragon.DeleteTracingPolicyRequest{
Name: args[0],
Name: args[0],
Namespace: tpDelNamespaceFlag,
})
if err != nil {
return fmt.Errorf("failed to delete tracing policy: %w", err)
Expand All @@ -67,6 +69,7 @@ func New() *cobra.Command {
},
}

var tpEnableNamespaceFlag string
tpEnableCmd := &cobra.Command{
Use: "enable <name>",
Short: "enable a tracing policy",
Expand All @@ -77,7 +80,8 @@ func New() *cobra.Command {
defer c.Close()

_, err := c.Client.EnableTracingPolicy(c.Ctx, &tetragon.EnableTracingPolicyRequest{
Name: args[0],
Name: args[0],
Namespace: tpEnableNamespaceFlag,
})
if err != nil {
return fmt.Errorf("failed to enable tracing policy: %w", err)
Expand All @@ -88,6 +92,7 @@ func New() *cobra.Command {
},
}

var tpDisableNamespaceFlag string
tpDisableCmd := &cobra.Command{
Use: "disable <name>",
Short: "disable a tracing policy",
Expand All @@ -98,7 +103,8 @@ func New() *cobra.Command {
defer c.Close()

_, err := c.Client.DisableTracingPolicy(c.Ctx, &tetragon.DisableTracingPolicyRequest{
Name: args[0],
Name: args[0],
Namespace: tpDisableNamespaceFlag,
})

if err != nil {
Expand Down Expand Up @@ -191,6 +197,12 @@ func New() *cobra.Command {
return nil
},
}
tpDelFlags := tpDelCmd.Flags()
tpDelFlags.StringVarP(&tpDelNamespaceFlag, common.KeyNamespace, "n", "", "Namespace of the tracing policy.")
tpEnableFlags := tpEnableCmd.Flags()
tpEnableFlags.StringVarP(&tpEnableNamespaceFlag, common.KeyNamespace, "n", "", "Namespace of the tracing policy.")
tpDisableFlags := tpDisableCmd.Flags()
tpDisableFlags.StringVarP(&tpDisableNamespaceFlag, common.KeyNamespace, "n", "", "Namespace of the tracing policy.")
tpListFlags := tpListCmd.Flags()
tpListFlags.StringVarP(&tpListOutputFlag, common.KeyOutput, "o", "text", "Output format. text or json")

Expand Down

0 comments on commit 6ec273f

Please sign in to comment.