Move container platform migration logic

Defer the logic to fill in the container platform information from the
image service until container restore. During container restore the
image backend is fully initialized and can be used to fill in the
missing platform fields for older containers.

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2025-10-20 10:39:16 -07:00
parent 663aa7aeab
commit 600edfe55c
2 changed files with 12 additions and 10 deletions

View File

@@ -79,16 +79,6 @@ func (daemon *Daemon) load(id string) (*container.Container, error) {
}
selinux.ReserveLabel(ctr.ProcessLabel)
if ctr.ImagePlatform.Architecture == "" {
migration := daemonPlatformReader{
imageService: daemon.imageService,
}
if daemon.containerdClient != nil {
migration.content = daemon.containerdClient.ContentStore()
}
migrateContainerOS(context.TODO(), migration, ctr)
}
if ctr.ID != id {
return ctr, fmt.Errorf("Container %s is stored at %s", ctr.ID, id)
}

View File

@@ -327,6 +327,18 @@ func (daemon *Daemon) restore(ctx context.Context, cfg *configStore, containers
baseLogger := log.G(ctx).WithField("container", c.ID)
// Fill in missing platform information with platform from image for older containers
// Remove this in a future release
if c.ImagePlatform.Architecture == "" {
migration := daemonPlatformReader{
imageService: daemon.imageService,
}
if daemon.containerdClient != nil {
migration.content = daemon.containerdClient.ContentStore()
}
migrateContainerOS(ctx, migration, c)
}
if c.HostConfig != nil {
// Migrate containers that don't have the default ("no") restart-policy set.
// The RestartPolicy.Name field may be empty for containers that were