debugd: use runc as podman runtime (#3205)

This commit is contained in:
Markus Rudy 2024-06-26 11:49:15 +02:00 committed by Markus Rudy
parent ca8d11861d
commit 3b64e654d1

View File

@ -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)