Skip to content

Commit

Permalink
debugd: use runc as podman runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerdev committed Jun 26, 2024
1 parent 27946c6 commit 35fb857
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions debugd/internal/debugd/logcollector/logcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -193,14 +193,14 @@ func startPod(ctx context.Context, logger *slog.Logger) error {
"--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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 podman(ctx, args...)
}

type providerMetadata interface {
// Self retrieves the current instance.
Self(ctx context.Context) (metadata.InstanceMetadata, error)
Expand Down

0 comments on commit 35fb857

Please sign in to comment.