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

pkg/config: lookup InitPath in HelperBinariesDir #1698

Merged
merged 1 commit into from
Oct 18, 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
15 changes: 15 additions & 0 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ Run an init inside the container that forwards signals and reaps processes.

**init_path**="/usr/libexec/podman/catatonit"

If this option is not set catatonit is searched in the directories listed under
the **helper_binaries_dir** option. It is recommended to just install catatonit
there instead of configuring this option here.

Path to the container-init binary, which forwards signals and reaps processes
within containers. Note that the container-init binary will only be used when
the `--init` for podman-create and podman-run is set.
Expand Down Expand Up @@ -574,6 +578,17 @@ with detailed information about the container. Set to false by default.
**helper_binaries_dir**=["/usr/libexec/podman", ...]

A is a list of directories which are used to search for helper binaries.
The following binaries are searched in these directories:
- aardvark-dns
- catatonit
- netavark
- pasta
- slirp4netns

Podman machine uses it for these binaries:
- gvproxy
- qemu
- vfkit

The default paths on Linux are:

Expand Down
21 changes: 21 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ type ContainersConfig struct {
Init bool `toml:"init,omitempty"`

// InitPath is the path for init to run if the Init bool is enabled
//
// Deprecated: Do not use this field directly use conf.FindInitBinary() instead.
InitPath string `toml:"init_path,omitempty"`

// IPCNS way to create a ipc namespace for the container
Expand Down Expand Up @@ -351,6 +353,8 @@ type EngineConfig struct {
InfraImage string `toml:"infra_image,omitempty"`

// InitPath is the path to the container-init binary.
//
// Deprecated: Do not use this field directly use conf.FindInitBinary() instead.
InitPath string `toml:"init_path,omitempty"`

// KubeGenerateType sets the Kubernetes kind/specification to generate by default
Expand Down Expand Up @@ -1223,3 +1227,20 @@ func ValidateImageVolumeMode(mode string) error {

return fmt.Errorf("invalid image volume mode %q required value: %s", mode, strings.Join(validImageVolumeModes, ", "))
}

// FindInitBinary will return the path to the init binary (catatonit)
func (c *Config) FindInitBinary() (string, error) {
// Sigh, for some reason we ended up with two InitPath field in containers.conf and
// both are used in podman so we have to keep supporting both to prevent regressions.
if c.Containers.InitPath != "" {
return c.Containers.InitPath, nil
}
if c.Engine.InitPath != "" {
return c.Engine.InitPath, nil
}
// keep old default working to guarantee backwards comapt
if _, err := os.Stat(DefaultInitPath); err == nil {
return DefaultInitPath, nil
}
return c.FindHelperBinary(defaultInitName, true)
}
3 changes: 3 additions & 0 deletions pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ default_sysctls = [
#init = false

# Container init binary, if init=true, this is the init binary to be used for containers.
# If this option is not set catatonit is searched in the directories listed under
# the helper_binaries_dir option. It is recommended to just install catatonit
# there instead of configuring this option here.
#
#init_path = "/usr/libexec/podman/catatonit"

Expand Down
3 changes: 3 additions & 0 deletions pkg/config/containers.conf-freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ default_sysctls = [
#init = false

# Container init binary, if init=true, this is the init binary to be used for containers.
# If this option is not set catatonit is searched in the directories listed under
# the helper_binaries_dir option. It is recommended to just install catatonit
# there instead of configuring this option here.
#
#init_path = "/usr/local/libexec/podman/catatonit"

Expand Down
9 changes: 3 additions & 6 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const (

// _defaultImageVolumeMode is a mode to handle built-in image volumes.
_defaultImageVolumeMode = _typeBind

// defaultInitName is the default name of the init binary
defaultInitName = "catatonit"
)

var (
Expand Down Expand Up @@ -432,7 +435,6 @@ func defaultEngineConfig() (*EngineConfig, error) {
}
c.RuntimeSupportsNoCgroups = []string{"crun", "krun"}
c.RuntimeSupportsKVM = []string{"kata", "kata-runtime", "kata-qemu", "kata-fc", "krun"}
c.InitPath = DefaultInitPath
c.NoPivotRoot = false

c.InfraImage = DefaultInfraImage
Expand Down Expand Up @@ -540,11 +542,6 @@ func (c *Config) Env() []string {
return c.Containers.Env
}

// InitPath returns location where init program added to containers when users specify the --init flag.
Copy link
Member

Choose a reason for hiding this comment

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

This would cause a breaking change, why not still return the init-path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this is a broken API, nobody should call that, the correct logic is in FindInintBinary(). Returning a single path just causes confusion for users who think this function does return something correct.
We do not guarantee a stable API in c/common so I can just nuke it here and update the only caller in podman.

func (c *Config) InitPath() string {
return c.Containers.InitPath
}

// IPCNS returns the default IPC Namespace configuration to run containers with.
func (c *Config) IPCNS() string {
return c.Containers.IPCNS
Expand Down