From ae02197085accbba02440510cb59d0b8fe07a5f9 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 26 May 2023 11:15:35 +0200 Subject: [PATCH] sysdump: refactor submitTetragonBugtoolTasks to take defaults as parameters Let submitTetragonBugtoolTasks take these values as parameters rather than from global vars. This e.g. allows to override them based on command line options in a future change. Signed-off-by: Tobias Klauser --- sysdump/constants.go | 7 ------- sysdump/defaults.go | 4 ++++ sysdump/sysdump.go | 11 +++++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sysdump/constants.go b/sysdump/constants.go index 399f5c5e33..7c3163f533 100644 --- a/sysdump/constants.go +++ b/sysdump/constants.go @@ -183,10 +183,3 @@ var ( Version: "v1alpha2", } ) - -var ( - tetragonAgentContainerName = "tetragon" - tetragonBugtoolPrefix = "tetragon-bugtool" - tetragonCliCommand = "tetra" - tetragonTracingPolicy = "tetragontracingpolicy-.yaml" -) diff --git a/sysdump/defaults.go b/sysdump/defaults.go index 567da004f6..12d278fb46 100644 --- a/sysdump/defaults.go +++ b/sysdump/defaults.go @@ -47,6 +47,10 @@ const ( DefaultCNIConfigMapName = "cni-configuration" DefaultTetragonNamespace = "kube-system" DefaultTetragonLabelSelector = "app.kubernetes.io/name=tetragon" + DefaultTetragonAgentContainerName = "tetragon" + DefaultTetragonBugtoolPrefix = "tetragon-bugtool" + DefaultTetragonCLICommand = "tetra" + DefaultTetragonTracingPolicy = "tetragontracingpolicy-.yaml" ) var ( diff --git a/sysdump/sysdump.go b/sysdump/sysdump.go index e7d96a7050..3cf8a1526a 100644 --- a/sysdump/sysdump.go +++ b/sysdump/sysdump.go @@ -1088,7 +1088,9 @@ func (c *Collector) Run() error { if err != nil { return fmt.Errorf("failed to get Tetragon pods: %w", err) } - if err := c.submitTetragonBugtoolTasks(FilterPods(p, c.NodeList)); err != nil { + if err := c.SubmitTetragonBugtoolTasks(FilterPods(p, c.NodeList), + DefaultTetragonAgentContainerName, DefaultTetragonBugtoolPrefix, + DefaultTetragonCLICommand); err != nil { return fmt.Errorf("failed to collect 'tetragon-bugtool': %w", err) } return nil @@ -1147,7 +1149,7 @@ func (c *Collector) Run() error { if err != nil { return fmt.Errorf("failed to collect Tetragon tracing policies: %w", err) } - if err := c.WriteYAML(tetragonTracingPolicy, v); err != nil { + if err := c.WriteYAML(DefaultTetragonTracingPolicy, v); err != nil { return fmt.Errorf("failed to collect Tetragon tracing policies: %w", err) } return nil @@ -1434,7 +1436,8 @@ func (c *Collector) shouldSkipTask(t Task) bool { return c.Options.Quick && !t.Quick } -func (c *Collector) submitTetragonBugtoolTasks(pods []*corev1.Pod) error { +func (c *Collector) SubmitTetragonBugtoolTasks(pods []*corev1.Pod, tetragonAgentContainerName, + tetragonBugtoolPrefix, tetragonCLICommand string) error { for _, p := range pods { p := p workerID := fmt.Sprintf("%s-%s", tetragonBugtoolPrefix, p.Name) @@ -1452,7 +1455,7 @@ func (c *Collector) submitTetragonBugtoolTasks(pods []*corev1.Pod) error { tarGzFile := fmt.Sprintf("%s-%s.tar.gz", tetragonBugtoolPrefix, time.Now().Format(timeFormat)) // Run 'tetra bugtool' in the pod. - command := []string{tetragonCliCommand, "bugtool", "--out", tarGzFile} + command := []string{tetragonCLICommand, "bugtool", "--out", tarGzFile} c.logDebug("Executing 'tetragon-bugtool' command: %v", command) _, e, err := c.Client.ExecInPodWithStderr(ctx, p.Namespace, p.Name, containerName, command)