From 3b64e654d132435574a7cfe7d46b6f3de42e001b Mon Sep 17 00:00:00 2001 From: Markus Rudy Date: Wed, 26 Jun 2024 11:49:15 +0200 Subject: [PATCH] debugd: use runc as podman runtime (#3205) --- .../debugd/logcollector/logcollector.go | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/debugd/internal/debugd/logcollector/logcollector.go b/debugd/internal/debugd/logcollector/logcollector.go index 59964287d..20bd4dfac 100644 --- a/debugd/internal/debugd/logcollector/logcollector.go +++ b/debugd/internal/debugd/logcollector/logcollector.go @@ -130,7 +130,7 @@ func getTemplate(ctx context.Context, logger *slog.Logger, image, templateDir, d "--name=template", image, } - createContainerCmd := exec.CommandContext(ctx, "podman", createContainerArgs...) + createContainerCmd := podman(ctx, createContainerArgs...) logger.Info("Creating template container") if out, err := createContainerCmd.CombinedOutput(); err != nil { return nil, fmt.Errorf("creating template container: %w\n%s", err, out) @@ -145,7 +145,7 @@ func getTemplate(ctx context.Context, logger *slog.Logger, image, templateDir, d "template:/usr/share/constellogs/templates/", destDir, } - copyFromCmd := exec.CommandContext(ctx, "podman", copyFromArgs...) + copyFromCmd := podman(ctx, copyFromArgs...) logger.Info("Copying templates") if out, err := copyFromCmd.CombinedOutput(); err != nil { return nil, fmt.Errorf("copying templates: %w\n%s", err, out) @@ -155,7 +155,7 @@ func getTemplate(ctx context.Context, logger *slog.Logger, image, templateDir, d "rm", "template", } - removeContainerCmd := exec.CommandContext(ctx, "podman", removeContainerArgs...) + removeContainerCmd := podman(ctx, removeContainerArgs...) logger.Info("Removing template container") if out, err := removeContainerCmd.CombinedOutput(); err != nil { return nil, fmt.Errorf("removing template container: %w\n%s", err, out) @@ -176,7 +176,7 @@ func startPod(ctx context.Context, logger *slog.Logger) error { "create", "logcollection", } - createPodCmd := exec.CommandContext(ctx, "podman", createPodArgs...) + createPodCmd := podman(ctx, createPodArgs...) logger.Info(fmt.Sprintf("Create pod command: %v", createPodCmd.String())) if out, err := createPodCmd.CombinedOutput(); err != nil { return fmt.Errorf("failed to create pod: %w; output: %s", err, out) @@ -189,18 +189,18 @@ func startPod(ctx context.Context, logger *slog.Logger) error { "--rm", "--name=logstash", "--pod=logcollection", - "--log-driver=none", + "--log-driver=journald", "--volume=/run/logstash/pipeline:/usr/share/logstash/pipeline/:ro", versions.LogstashImage, } - runLogstashCmd := exec.CommandContext(ctx, "podman", runLogstashArgs...) + runLogstashCmd := podman(ctx, runLogstashArgs...) logger.Info(fmt.Sprintf("Run logstash command: %v", runLogstashCmd.String())) runLogstashCmd.Stdout = logstashLog runLogstashCmd.Stderr = logstashLog if err := runLogstashCmd.Start(); err != nil { return fmt.Errorf("failed to start logstash: %w", err) } - if out, err := exec.CommandContext(ctx, "podman", "wait", "logstash", "--condition=running", "--interval=15s").CombinedOutput(); err != nil { + if out, err := podman(ctx, "wait", "logstash", "--condition=running", "--interval=15s").CombinedOutput(); err != nil { logger.Error("Logstash container failed to reach healthy status", "err", err, "output", out) return fmt.Errorf("waiting for logstash container to reach healthy status: %w; output: %s", err, out) } @@ -213,7 +213,7 @@ func startPod(ctx context.Context, logger *slog.Logger) error { "--name=filebeat", "--pod=logcollection", "--privileged", - "--log-driver=none", + "--log-driver=journald", "--volume=/run/log/journal:/run/log/journal:ro", "--volume=/etc/machine-id:/etc/machine-id:ro", "--volume=/run/systemd:/run/systemd:ro", @@ -222,14 +222,14 @@ func startPod(ctx context.Context, logger *slog.Logger) error { "--volume=/run/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro", versions.FilebeatImage, } - runFilebeatCmd := exec.CommandContext(ctx, "podman", runFilebeatArgs...) + runFilebeatCmd := podman(ctx, runFilebeatArgs...) logger.Info(fmt.Sprintf("Run filebeat command: %v", runFilebeatCmd.String())) runFilebeatCmd.Stdout = filebeatLog runFilebeatCmd.Stderr = filebeatLog if err := runFilebeatCmd.Start(); err != nil { return fmt.Errorf("failed to run filebeat: %w", err) } - if out, err := exec.CommandContext(ctx, "podman", "wait", "filebeat", "--condition=running", "--interval=15s").CombinedOutput(); err != nil { + if out, err := podman(ctx, "wait", "filebeat", "--condition=running", "--interval=15s").CombinedOutput(); err != nil { logger.Error("Filebeat container failed to reach healthy status", "err", err, "output", out) return fmt.Errorf("waiting for filebeat container to reach healthy status: %w; output: %s", err, out) } @@ -316,6 +316,11 @@ func (c *cmdLogger) Write(p []byte) (n int, err error) { return len(p), nil } +func podman(ctx context.Context, args ...string) *exec.Cmd { + args = append([]string{"--runtime=runc"}, args...) + return exec.CommandContext(ctx, "podman", args...) +} + type providerMetadata interface { // Self retrieves the current instance. Self(ctx context.Context) (metadata.InstanceMetadata, error)