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 argument to the CLI for the delete, enable, and disable commands. If the namespace argument is unset, it will reference the global TracingPolicy.

Fixes: cilium#2299

Signed-off-by: Joshua Jorel Lee <[email protected]>
  • Loading branch information
joshuajorel committed May 15, 2024
1 parent d5641fd commit 0c7d2b1
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions cmd/tetra/tracingpolicy/tracingpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@ func New() *cobra.Command {
}

tpDelCmd := &cobra.Command{
Use: "delete <name>",
Use: "delete <name> <namespace>",
Short: "delete a tracing policy",
Args: cobra.ExactArgs(1),
Long: "Delete a tracing policy. If namespace is unset, defaults to global namespace.",
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
c := common.NewConnectedClient()
defer c.Close()
namespace := ""
if len(args) > 1 {
namespace = args[1]
}

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

tpEnableCmd := &cobra.Command{
Use: "enable <name>",
Use: "enable <name> <namespace>",
Short: "enable a tracing policy",
Long: "Enable a disabled tracing policy. Use disable to re-disable the tracing policy.",
Args: cobra.ExactArgs(1),
Long: "Enable a disabled tracing policy. Use disable to re-disable the tracing policy. If namespace is unset, defaults to global namespace.",
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
c := common.NewConnectedClient()
defer c.Close()
namespace := ""
if len(args) > 1 {
namespace = args[1]
}

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

tpDisableCmd := &cobra.Command{
Use: "disable <name>",
Use: "disable <name> <namespace>",
Short: "disable a tracing policy",
Long: "Disable an enabled tracing policy. Use enable to re-enable the tracing policy.",
Args: cobra.ExactArgs(1),
Long: "Disable an enabled tracing policy. Use enable to re-enable the tracing policy. If namespace is unset, defaults to global namespace.",
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
c := common.NewConnectedClient()
defer c.Close()
namespace := ""
if len(args) > 1 {
namespace = args[1]
}

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

if err != nil {
Expand Down

0 comments on commit 0c7d2b1

Please sign in to comment.