Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysdump: refactor submitTetragonBugtoolTasks to take defaults as parameters #1665

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions sysdump/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,3 @@ var (
Version: "v1alpha2",
}
)

var (
tetragonAgentContainerName = "tetragon"
tetragonBugtoolPrefix = "tetragon-bugtool"
tetragonCliCommand = "tetra"
tetragonTracingPolicy = "tetragontracingpolicy-<ts>.yaml"
)
4 changes: 4 additions & 0 deletions sysdump/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-<ts>.yaml"
)

var (
Expand Down
11 changes: 7 additions & 4 deletions sysdump/sysdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down