vendor latest c/common main

Includes several rootless-netns fixes.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-04-02 18:45:45 +02:00
parent 976640474b
commit ce04fbc16a
47 changed files with 661 additions and 267 deletions

View File

@@ -328,6 +328,11 @@ type EngineConfig struct {
// this slice takes precedence.
HooksDir attributedstring.Slice `toml:"hooks_dir,omitempty"`
// Location of CDI configuration files. These define mounts devices and
// other configs according to the CDI spec. In particular this is used
// for GPU passthrough.
CdiSpecDirs attributedstring.Slice `toml:"cdi_spec_dirs,omitempty"`
// ImageBuildFormat (DEPRECATED) indicates the default image format to
// building container images. Should use ImageDefaultFormat
ImageBuildFormat string `toml:"image_build_format,omitempty"`
@@ -772,7 +777,7 @@ func (m *MachineConfig) URI() string {
}
func (c *EngineConfig) findRuntime() string {
// Search for crun first followed by runc, kata, runsc
// Search for crun first followed by runc, runj, kata, runsc, ocijail
for _, name := range []string{"crun", "runc", "runj", "kata", "runsc", "ocijail"} {
for _, v := range c.OCIRuntimes[name] {
if _, err := os.Stat(v); err == nil {

View File

@@ -544,6 +544,12 @@ default_sysctls = [
# "/usr/share/containers/oci/hooks.d",
#]
# Directories to scan for CDI Spec files.
#
#cdi_spec_dirs = [
# "/etc/cdi",
#]
# Manifest Type (oci, v2s2, or v2s1) to use when pulling, pushing, building
# container images. By default image pulled and pushed match the format of the
# source image. Building/committing defaults to OCI.

View File

@@ -414,6 +414,12 @@ default_sysctls = [
# "/usr/local/share/containers/oci/hooks.d",
#]
# Directories to scan for CDI Spec files.
#
#cdi_spec_dirs = [
# "/etc/cdi",
#]
# Manifest Type (oci, v2s2, or v2s1) to use when pulling, pushing, building
# container images. By default image pulled and pushed match the format of the
# source image. Building/committing defaults to OCI.

View File

@@ -74,6 +74,8 @@ var (
ErrInvalidArg = errors.New("invalid argument")
// DefaultHooksDirs defines the default hooks directory.
DefaultHooksDirs = []string{"/usr/share/containers/oci/hooks.d"}
// DefaultCdiSpecDirs defines the default cdi spec directories.
DefaultCdiSpecDirs = []string{"/etc/cdi"}
// DefaultCapabilities is the default for the default_capabilities option in the containers.conf file.
DefaultCapabilities = []string{
"CAP_CHOWN",
@@ -347,6 +349,7 @@ func defaultEngineConfig() (*EngineConfig, error) {
c.HelperBinariesDir.Set(append([]string{additionalHelperBinariesDir}, c.HelperBinariesDir.Get()...))
}
c.HooksDir.Set(DefaultHooksDirs)
c.CdiSpecDirs.Set(DefaultCdiSpecDirs)
c.ImageDefaultTransport = _defaultTransport
c.ImageVolumeMode = _defaultImageVolumeMode

View File

@@ -2,6 +2,7 @@ package config
import (
"fmt"
"strings"
)
// PullPolicy determines how and which images are being pulled from a container
@@ -73,14 +74,14 @@ func (p PullPolicy) Validate() error {
// * "newer" <-> PullPolicyNewer (also "ifnewer")
// * "never" <-> PullPolicyNever
func ParsePullPolicy(s string) (PullPolicy, error) {
switch s {
case "always", "Always":
switch strings.ToLower(s) {
case "always":
return PullPolicyAlways, nil
case "missing", "Missing", "ifnotpresent", "IfNotPresent", "":
case "missing", "ifmissing", "ifnotpresent", "":
return PullPolicyMissing, nil
case "newer", "Newer", "ifnewer", "IfNewer":
case "newer", "ifnewer":
return PullPolicyNewer, nil
case "never", "Never":
case "never":
return PullPolicyNever, nil
default:
return PullPolicyUnsupported, fmt.Errorf("unsupported pull policy %q", s)

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"strings"
"github.com/containers/common/internal"
"github.com/containers/image/v5/manifest"
@@ -80,10 +81,18 @@ func Create() List {
}
}
func sliceToMap(s []string) map[string]string {
m := make(map[string]string, len(s))
for _, spec := range s {
key, value, _ := strings.Cut(spec, "=")
m[key] = value
}
return m
}
// AddInstance adds an entry for the specified manifest digest, with assorted
// additional information specified in parameters, to the list or index.
func (l *list) AddInstance(manifestDigest digest.Digest, manifestSize int64, manifestType, osName, architecture, osVersion string, osFeatures []string, variant string, features, annotations []string) error { // nolint:revive
// FIXME: the annotations argument is currently ignored
if err := l.Remove(manifestDigest); err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
@@ -116,10 +125,11 @@ func (l *list) AddInstance(manifestDigest digest.Digest, manifestSize int64, man
ociv1platform = nil
}
l.oci.Manifests = append(l.oci.Manifests, v1.Descriptor{
MediaType: manifestType,
Size: manifestSize,
Digest: manifestDigest,
Platform: ociv1platform,
MediaType: manifestType,
Size: manifestSize,
Digest: manifestDigest,
Platform: ociv1platform,
Annotations: sliceToMap(annotations),
})
return nil

View File

@@ -15,21 +15,35 @@ const (
// Note: This function is copied from containers/podman libpod/util.go
// Please see https://github.com/containers/common/pull/1460
func queryPackageVersion(cmdArg ...string) string {
_, err := os.Stat(cmdArg[0])
if err != nil {
return ""
}
output := UnknownPackage
if 1 < len(cmdArg) {
cmd := exec.Command(cmdArg[0], cmdArg[1:]...)
if outp, err := cmd.Output(); err == nil {
output = string(outp)
deb := false
if cmdArg[0] == "/usr/bin/dlocate" {
// can return multiple matches
l := strings.Split(output, "\n")
output = l[0]
deb = true
r := strings.Split(output, ": ")
regexpFormat := `^..\s` + r[0] + `\s`
cmd = exec.Command(cmdArg[0], "-P", regexpFormat, "-l")
cmd.Env = []string{"COLUMNS=160"} // show entire value
// dlocate always returns exit code 1 for list command
if outp, _ = cmd.Output(); len(outp) > 0 {
lines := strings.Split(string(outp), "\n")
if len(lines) > 1 {
line := lines[len(lines)-2] // trailing newline
f := strings.Fields(line)
if len(f) >= 2 {
return f[1] + "_" + f[2]
}
}
}
} else if cmdArg[0] == "/usr/bin/dpkg" {
deb = true
}
if deb {
r := strings.Split(output, ": ")
queryFormat := `${Package}_${Version}_${Architecture}`
cmd = exec.Command("/usr/bin/dpkg-query", "-f", queryFormat, "-W", r[0])
@@ -53,22 +67,36 @@ func Package(program string) string { // program is full path
if err != nil {
return UnknownPackage
}
packagers := [][]string{
{"/usr/bin/rpm", "-q", "-f"},
{"/usr/bin/dlocate", "-F"}, // Debian, Ubuntu (quick)
{"/usr/bin/dpkg", "-S"}, // Debian, Ubuntu (slow)
{"/usr/bin/pacman", "-Qo"}, // Arch
{"/usr/bin/qfile", "-qv"}, // Gentoo (quick)
{"/usr/bin/equery", "b"}, // Gentoo (slow)
{"/sbin/apk", "info", "-W"}, // Alpine
{"/usr/local/sbin/pkg", "which", "-q"}, // FreeBSD
type Packager struct {
Format string
Command []string
}
packagers := []Packager{
{"rpm", []string{"/usr/bin/rpm", "-q", "-f"}},
{"deb", []string{"/usr/bin/dlocate", "-F"}}, // Debian, Ubuntu (quick)
{"deb", []string{"/usr/bin/dpkg", "-S"}}, // Debian, Ubuntu (slow)
{"pacman", []string{"/usr/bin/pacman", "-Qo"}}, // Arch
{"gentoo", []string{"/usr/bin/qfile", "-qv"}}, // Gentoo (quick)
{"gentoo", []string{"/usr/bin/equery", "b"}}, // Gentoo (slow)
{"apk", []string{"/sbin/apk", "info", "-W"}}, // Alpine
{"pkg", []string{"/usr/local/sbin/pkg", "which", "-q"}}, // FreeBSD
}
for _, cmd := range packagers {
lastformat := ""
for _, packager := range packagers {
if packager.Format == lastformat {
continue
}
cmd := packager.Command
cmd = append(cmd, program)
if out := queryPackageVersion(cmd...); out != UnknownPackage {
if out == "" {
continue
}
return out
}
lastformat = packager.Format
}
return UnknownPackage
}