Skip to content

Conversation

@AritraDey-Dev
Copy link
Member

@AritraDey-Dev AritraDey-Dev commented Nov 20, 2025

Fixes #2073

Description

See commit.

Changelog

new(cmd/tetra): add explain command for standalone CRD documentation

@AritraDey-Dev AritraDey-Dev requested a review from a team as a code owner November 20, 2025 17:34
@netlify
Copy link

netlify bot commented Nov 20, 2025

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit 9d341ec
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/691f510ccabc9600099b7cce
😎 Deploy Preview https://deploy-preview-4362--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mtardy mtardy self-requested a review November 20, 2025 17:39
@AritraDey-Dev AritraDey-Dev force-pushed the feat/cli-tetra-explain branch 2 times, most recently from df12a48 to a67900a Compare November 20, 2025 17:54
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a suggestion to improve the implementation.

@FedeDP
Copy link
Contributor

FedeDP commented Nov 21, 2025

Can you squash the commits into a single one?

@AritraDey-Dev AritraDey-Dev force-pushed the feat/cli-tetra-explain branch 2 times, most recently from b49b93d to 7e19e98 Compare November 21, 2025 11:38
@AritraDey-Dev AritraDey-Dev requested a review from FedeDP November 21, 2025 13:47
}

// Handle array notation like field[] or field[0]
if strings.Contains(part, "[") && strings.Contains(part, "]") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question about this one: what are we supporting by doing so (considering we are leaving out the string between "[" and "]")?

Should we expand this a little bit to support eg:

./tetra explain tracingpolicy[spec][uprobes]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a limitation and needs to be expanded. It requires a separate function to handle it. I will implement this in the next commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented!

./tetra explain tracingpolicy[spec][uprobes]
KIND:     TracingPolicy
VERSION:  v1alpha1

FIELD:    uprobes <[]object>

DESCRIPTION:
     A list of uprobe specs.

FIELDS:
   addrs        <[]integer>
     List of the traced addresses

   args <[]object>
     A list of function arguments to include in the trace output.

   btfPath      <string>
     path for a BTF file for the traced binary

   data <[]object>
     A list of data to include in the trace output.

   message      <string>
     A short message of 256 characters max that will be included
in the event output to inform users what is going on.

   offsets      <[]integer>
     List of the traced offsets

   path <string> -required-
     Name of the traced binary

   refCtrOffsets        <[]integer>
     List of the traced ref_ctr_offsets

   return       <boolean>
     Indicates whether to collect return value of the traced function.

   returnArg    <object>
     A return argument to include in the trace output.

   selectors    <[]object>
     Selectors to apply before producing trace output

   symbols      <[]string>
     List of the traced symbols

   tags <[]string>
     Tags to categorize the event, will be include in the event output.
Maximum of 16 Tags are supported.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@FedeDP
Copy link
Contributor

FedeDP commented Nov 21, 2025

This is quite ready; left some comments :)
Btw let me take one moment and thank you for this! Not only does this close a requested feature from long ago, but i think it is really useful! 🚀

@AritraDey-Dev AritraDey-Dev force-pushed the feat/cli-tetra-explain branch 2 times, most recently from 711f048 to 878f1fa Compare November 21, 2025 14:32
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdyt if we drop supportedResources in favor of using client.AllCRDs?
I got a patch that should work fine. At that point we basically have no custom code in explain.go :)
explain.patch

We also use aliases (ie: short names) from the crds.

Example:

$ ./tetra explain --list
NAME                     SHORTNAMES
TracingPolicy            tgtp
TracingPolicyNamespaced  tgtpn
PodInfo                  tgpi

And

$ ./tetra explain tracingpolicies
Error: unsupported resource: tracingpolicies (supported resources: PodInfo, TracingPolicy, TracingPolicyNamespaced, tgpi, tgtp, tgtpn)

And:

$ ./tetra explain tracingpolicy
KIND:     TracingPolicy
VERSION:  v1alpha1

DESCRIPTION:


FIELDS:
   apiVersion	<string>
     APIVersion defines the versioned schema of this representation of an object.

   kind	<string>
     Kind is a string value representing the REST resource this object represents.

   metadata	<object> -required-

   spec	<object> -required-
     Tracing policy specification.

@AritraDey-Dev
Copy link
Member Author

Got it — usingclient.AllCRDsmakes sense and removes the need for maintaining supportedResources.
I’ll update the PR accordingly.

Users need kubectl and cluster access to explore Tetragon CRD schemas.
Add tetra explain command to provide kubectl-like functionality locally:

- Explore TracingPolicy, TracingPolicyNamespaced, PodInfo schemas
- Field navigation with dot notation (e.g., tracingpolicy.spec.kprobes)
- JSON/YAML output formats and recursive field listing
- Works without Kubernetes cluster dependency

Fixes cilium#2073

Signed-off-by: Aritra Dey <[email protected]>
@FedeDP
Copy link
Contributor

FedeDP commented Nov 24, 2025

Thanks! And sorry for the scattered review :) I am going through it piece by piece!
After this we will be finally over! Thanks for your patience!

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you very much!

@FedeDP FedeDP added the release-note/minor This PR introduces a minor user-visible change label Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/minor This PR introduces a minor user-visible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New command in Tetragon CLI: tetra explain

2 participants