Skip to content

Conversation

@ajoshua2004
Copy link
Contributor

@ajoshua2004 ajoshua2004 commented Aug 1, 2025

This adds support for configuring container log paths via container.conf, matching the functionality of --log-opts path=... at runtime

Fixes customer RFE for per-user container.conf log configuration for use with podman-kube systemd services.

Summary by Sourcery

Add support for configuring a custom log path for containers via the containers.conf file, including validation, documentation, and tests

New Features:

  • Introduce a new ‘log_path’ setting in ContainersConfig to specify the directory for container log files

Enhancements:

  • Implement validation for log_path to reject invalid characters and stub remote validation for consistency

Documentation:

  • Document the log_path option in the manpage and sample containers.conf

Tests:

  • Add unit tests to verify log_path parsing and validation against various path formats

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 1, 2025

Reviewer's Guide

Introduce a new log_path option in container configuration by extending the data model, adding validation logic, updating docs and defaults, and covering the functionality with tests.

Class diagram for updated ContainersConfig struct with log_path

classDiagram
    class ContainersConfig {
        +string LogDriver
        +string LogPath
        +int64 LogSizeMax
        +Validate() error
        +validateLogPath() error
        ...
    }
Loading

File-Level Changes

Change Details Files
Add log_path support to ContainersConfig and validation
  • Introduce LogPath field in ContainersConfig struct
  • Call validateLogPath in configuration Validate method
  • Implement validateLogPath in local config to check for invalid characters
  • Provide a no-op stub validateLogPath in remote config
pkg/config/config.go
pkg/config/config_local.go
pkg/config/config_remote.go
Update documentation and default config template for log_path
  • Add log_path description in manpage containers.conf.5.md
  • Include commented log_path entry in default containers.conf sample
docs/containers.conf.5.md
pkg/config/containers.conf
Add tests for log_path validation and parsing
  • Validate various log_path scenarios (empty, absolute, env var, relative, invalid)
  • Test reading log_path value from testdata config file
pkg/config/config_local_test.go
pkg/config/testdata/containers_default.conf

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @2004joshua - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

ajoshua2004 added a commit to ajoshua2004/podman that referenced this pull request Aug 5, 2025
Add support for log_path configuration option in containers.conf that allows users to specify
a custom directory for container log files. A log path is read from the [containers] section in
a containers.conf. For each container a sub-directory within log_path is created where each directory
is named after the container id and inside the subdirectory lives the default name for logs which is
ctr.log. This option can be overridden when using the `--log-opt` flag.

Vendor was modified until containers/common#2491 is merged.

Signed-off-by: Joshua Arrevillaga <2004jarrevillaga@gmail.com>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter is complaining, otherwise change LGTM

Comment on lines 113 to 116
return fmt.Errorf("log_path must be an absolute path - instead got %q", c.LogPath)
}
if strings.ContainsAny(c.LogPath, "\x00") {
return fmt.Errorf("log_path contains null bytes - instead got %q", c.LogPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop the "instead" from the message, the instead seems confusing in this context because the message is log_path contains null bytes - instead got Maybe it is my language barrier but should it be
log_path should not contain null bytes - instead got in order for the instead to make sense?

But I think just having got %q there is likely already enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

This adds support for configuring container log paths via container.conf, matching
the functionality of --log-opts path=... at runtime

Fixes customer RFE for per-user container.conf log configuration for use with
podman-kube systemd services.

Signed-off-by: Joshua Arrevillaga <2004jarrevillaga@gmail.com>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 6, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 2004joshua, Luap99, sourcery-ai[bot]

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Aug 6, 2025
@mheon
Copy link
Member

mheon commented Aug 6, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Aug 6, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 57def96 into containers:main Aug 6, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants