Skip to content

Commit 65c3a6e

Browse files
committed
pkg/distro: add PodmanDefaultNetBackend to ImageConfig and wire it up
Add a new ImageConfig option that specifies the default network backend for Podman. When set and the image embeds container images, the value is written to /var/lib/containers/storage/defaultNetworkBackend during image build. This prevents Podman from falling back to the legacy 'cni' backend when it finds pre-existing container images in storage, which it interprets as a system migration. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
1 parent 024d96a commit 65c3a6e

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

pkg/distro/generic/images.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,18 @@ func osCustomizations(t *imageType, osPackageSet rpmmd.PackageSet, options distr
336336
osc.Files = append(osc.Files, imageConfig.Files...)
337337
osc.Directories = append(osc.Directories, imageConfig.Directories...)
338338

339+
if len(containers) > 0 && imageConfig.PodmanDefaultNetBackend != nil {
340+
var storagePath string
341+
if osc.ContainersStorage != nil {
342+
storagePath = *osc.ContainersStorage
343+
}
344+
defaultNetBackendFile, err := container.GenDefaultNetworkBackendFile(storagePath, *imageConfig.PodmanDefaultNetBackend)
345+
if err != nil {
346+
return osc, fmt.Errorf("generating default network backend file: %w", err)
347+
}
348+
osc.Files = append(osc.Files, defaultNetBackendFile)
349+
}
350+
339351
if imageConfig.NoBLS != nil {
340352
osc.NoBLS = *imageConfig.NoBLS
341353
}

pkg/distro/image_config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"reflect"
66

77
"github.com/osbuild/images/internal/common"
8+
"github.com/osbuild/images/pkg/container"
89
"github.com/osbuild/images/pkg/customizations/fsnode"
910
"github.com/osbuild/images/pkg/customizations/oci"
1011
"github.com/osbuild/images/pkg/customizations/ostreeserver"
@@ -153,6 +154,15 @@ type ImageConfig struct {
153154
// /usr/lib/ostree-boot into bootupd-compatible update metadata.
154155
// Only set this to true if the bootupd package is available in the image.
155156
BootupdGenMetadata *bool `yaml:"bootupd_gen_metadata,omitempty"`
157+
158+
// PodmanDefaultNetBackend sets the default network backend for Podman.
159+
// The value is written to /var/lib/containers/storage/defaultNetworkBackend
160+
// only when the image embeds container images.
161+
//
162+
// Certain versions of Podman fall back to 'cni' when they find existing
163+
// containers in the storage, assuming a migration from an older version.
164+
// This option prevents that behavior.
165+
PodmanDefaultNetBackend *container.NetworkBackend `yaml:"podman_default_net_backend,omitempty"`
156166
}
157167

158168
// shallowMerge creates a new struct by merging a child and a parent.

0 commit comments

Comments
 (0)