Skip to content

Commit

Permalink
sysdump: gather tetragon pod logs and configmap
Browse files Browse the repository at this point in the history
This patch adds the following teragon sysdump tasks: i) tetragon pod
logs, ii) tetragon operator pod logs, tetragon config map.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt authored and michi-covalent committed Mar 11, 2024
1 parent a722a62 commit 59ffc68
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sysdump/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const (
DefaultCNIConfigMapName = "cni-configuration"
DefaultTetragonNamespace = "kube-system"
DefaultTetragonLabelSelector = "app.kubernetes.io/name=tetragon"
DefaultTetragonOperatorLabelSelector = "app.kubernetes.io/name=tetragon-operator"
DefaultTetragonAgentContainerName = "tetragon"
DefaultTetragonConfigMapName = "tetragon-config"
DefaultTetragonBugtoolPrefix = "tetragon-bugtool"
DefaultTetragonCLICommand = "tetra"
DefaultTetragonPodInfo = "tetragonpodinfo-<ts>.yaml"
Expand Down
60 changes: 60 additions & 0 deletions sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ type Options struct {
CNIConfigMapName string
// The labels used to target Tetragon pods.
TetragonLabelSelector string
// The labels used to target Tetragon oeprator pods.
TetragonOperatorLabelSelector string
// The namespace Namespace is running in.
TetragonNamespace string
// Retry limit for copying files from pods
Expand Down Expand Up @@ -1284,6 +1286,42 @@ func (c *Collector) Run() error {
}

tetragonTasks := []Task{
{
CreatesSubtasks: true,
Description: "Collecting logs from Tetragon pods",
Quick: false,
Task: func(ctx context.Context) error {
p, err := c.Client.ListPods(ctx, c.Options.TetragonNamespace, metav1.ListOptions{
LabelSelector: c.Options.TetragonLabelSelector,
})
if err != nil {
return fmt.Errorf("failed to get Tetragon pods: %w", err)
}

if err := c.SubmitLogsTasks(FilterPods(p, c.NodeList), c.Options.LogsSinceTime, c.Options.LogsLimitBytes); err != nil {
return fmt.Errorf("failed to collect logs from Tetragon pods")
}
return nil
},
},
{
CreatesSubtasks: true,
Description: "Collecting logs from Tetragon operator pods",
Quick: false,
Task: func(ctx context.Context) error {
p, err := c.Client.ListPods(ctx, c.Options.TetragonNamespace, metav1.ListOptions{
LabelSelector: c.Options.TetragonOperatorLabelSelector,
})
if err != nil {
return fmt.Errorf("failed to get Tetragon operator pods: %w", err)
}

if err := c.SubmitLogsTasks(FilterPods(p, c.NodeList), c.Options.LogsSinceTime, c.Options.LogsLimitBytes); err != nil {
return fmt.Errorf("failed to collect logs from Tetragon operator pods")
}
return nil
},
},
{
CreatesSubtasks: true,
Description: "Collecting bugtool output from Tetragon pods",
Expand All @@ -1303,6 +1341,25 @@ func (c *Collector) Run() error {
return nil
},
},
{
Description: "Collecting Tetragon configmap",
Quick: true,
Task: func(ctx context.Context) error {
cmName := DefaultTetragonConfigMapName
v, err := c.Client.GetConfigMap(ctx, c.Options.TetragonNamespace, cmName, metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
c.logDebug("CNI configmap %s not found: %w", cmName, err)
return nil
}
if err != nil {
return fmt.Errorf("failed to collect the Tetragon configmap: %w", err)
}
if err := c.WriteYAML("tetragon-configmap-<ts>.yaml", v); err != nil {
return fmt.Errorf("failed to write the Tetragon configmap: %w", err)
}
return nil
},
},
{
CreatesSubtasks: true,
Description: "Collecting Tetragon PodInfo custom resources",
Expand Down Expand Up @@ -2632,6 +2689,9 @@ func InitSysdumpFlags(cmd *cobra.Command, options *Options, optionPrefix string,
cmd.Flags().StringVar(&options.TetragonLabelSelector,
optionPrefix+"tetragon-label-selector", DefaultTetragonLabelSelector,
"The labels used to target Tetragon pods")
cmd.Flags().StringVar(&options.TetragonOperatorLabelSelector,
optionPrefix+"tetragon-operator-label-selector", DefaultTetragonOperatorLabelSelector,
"The labels used to target Tetragon operator pods")
cmd.Flags().IntVar(&options.CopyRetryLimit,
optionPrefix+"copy-retry-limit", DefaultCopyRetryLimit,
"Retry limit for file copying operations. If set to -1, copying will be retried indefinitely. Useful for collecting sysdump while on unreliable connection.")
Expand Down

0 comments on commit 59ffc68

Please sign in to comment.