Skip to content

Commit

Permalink
cmd/tetragon: add --generate-docs flags to output YAML docs
Browse files Browse the repository at this point in the history
This YAML file is used in the docs to display a reference of the
tetragon options.

Signed-off-by: Mahe Tardy <[email protected]>
  • Loading branch information
mtardy committed Jan 4, 2024
1 parent f08c16f commit 86b7600
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/tetragon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import (
gops "github.com/google/gops/agent"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/durationpb"
Expand Down Expand Up @@ -749,6 +750,13 @@ func execute() error {
Use: "tetragon",
Short: "Tetragon - eBPF-based Security Observability and Runtime Enforcement",
Run: func(cmd *cobra.Command, args []string) {
if viper.GetBool(option.KeyGenerateDocs) {
if err := doc.GenYaml(cmd, os.Stdout); err != nil {
log.WithError(err).Fatal("Failed to generate docs")
}
return
}

if err := option.ReadAndSetFlags(); err != nil {
log.WithError(err).Fatal("Failed to start gops")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/option/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const (
KeyEnablePodInfo = "enable-pod-info"

KeyExposeKernelAddresses = "expose-kernel-addresses"

KeyGenerateDocs = "generate-docs"
)

func ReadAndSetFlags() error {
Expand Down Expand Up @@ -271,4 +273,6 @@ func AddFlags(flags *pflag.FlagSet) {
flags.Bool(KeyEnablePodInfo, false, "Enable PodInfo custom resource")

flags.Bool(KeyExposeKernelAddresses, false, "Expose real kernel addresses in events stack traces")

flags.Bool(KeyGenerateDocs, false, "Generate documentation in YAML format to stdout")
}

0 comments on commit 86b7600

Please sign in to comment.