77 "errors"
88 "fmt"
99 "net/http"
10+ "net/netip"
1011 "sort"
1112 "strconv"
1213 "strings"
@@ -25,12 +26,11 @@ import (
2526 "github.com/containers/podman/v6/pkg/signal"
2627 "github.com/containers/podman/v6/pkg/specgenutil"
2728 "github.com/containers/podman/v6/pkg/util"
28- dockerBackend "github.com/docker/docker/api/types/backend"
29- "github.com/docker/docker/api/types/container"
30- "github.com/docker/docker/api/types/network"
31- "github.com/docker/docker/api/types/storage"
3229 "github.com/docker/go-connections/nat"
3330 "github.com/docker/go-units"
31+ "github.com/moby/moby/api/types/container"
32+ "github.com/moby/moby/api/types/network"
33+ "github.com/moby/moby/api/types/storage"
3434 spec "github.com/opencontainers/runtime-spec/specs-go"
3535 "github.com/sirupsen/logrus"
3636)
@@ -283,6 +283,15 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) {
283283 utils .WaitContainerDocker (w , r )
284284}
285285
286+ func convertSecondaryIPPrefixLen (input * define.InspectNetworkSettings , output * handlers.LegacyNetworkSettings ) {
287+ for index , ip := range input .SecondaryIPAddresses {
288+ output .SecondaryIPAddresses [index ].PrefixLen = ip .PrefixLength
289+ }
290+ for index , ip := range input .SecondaryIPv6Addresses {
291+ output .SecondaryIPv6Addresses [index ].PrefixLen = ip .PrefixLength
292+ }
293+ }
294+
286295func LibpodToContainer (l * libpod.Container , sz bool ) (* handlers.Container , error ) {
287296 imageID , imageName := l .Image ()
288297
@@ -348,7 +357,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
348357 return nil , err
349358 }
350359
351- ports := []container.Port {}
360+ ports := []container.PortSummary {}
352361 for portKey , bindings := range inspect .NetworkSettings .Ports {
353362 portNum , proto , ok := strings .Cut (portKey , "/" )
354363 if ! ok {
@@ -362,7 +371,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
362371
363372 if len (bindings ) == 0 {
364373 // Exposed but not published
365- ports = append (ports , container.Port {
374+ ports = append (ports , container.PortSummary {
366375 PrivatePort : uint16 (containerPort ),
367376 Type : proto ,
368377 })
@@ -372,9 +381,16 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
372381 if err != nil {
373382 return nil , fmt .Errorf ("invalid HostPort: %v" , err )
374383 }
384+ addr := netip.Addr {}
385+ if b .HostIP != "" {
386+ addr , err = netip .ParseAddr (b .HostIP )
387+ if err != nil {
388+ return nil , fmt .Errorf ("invalid HostIP: %v" , err )
389+ }
390+ }
375391
376- ports = append (ports , container.Port {
377- IP : b . HostIP ,
392+ ports = append (ports , container.PortSummary {
393+ IP : addr ,
378394 PrivatePort : uint16 (containerPort ),
379395 PublicPort : uint16 (hostPortInt ),
380396 Type : proto ,
@@ -402,7 +418,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
402418 }
403419
404420 return & handlers.Container {
405- Container : container.Summary {
421+ Summary : container.Summary {
406422 ID : l .ID (),
407423 Names : []string {fmt .Sprintf ("/%s" , l .Name ())},
408424 Image : imageName ,
@@ -413,7 +429,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
413429 SizeRw : sizeRW ,
414430 SizeRootFs : sizeRootFs ,
415431 Labels : l .Labels (),
416- State : stateStr ,
432+ State : container . ContainerState ( stateStr ) ,
417433 Status : status ,
418434 // FIXME: this seems broken, the field is never shown in the API output.
419435 HostConfig : struct {
@@ -426,20 +442,11 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
426442 NetworkSettings : & networkSettings ,
427443 Mounts : mounts ,
428444 },
429- ContainerCreateConfig : dockerBackend .ContainerCreateConfig {},
445+ ContainerCreateConfig : handlers .ContainerCreateConfig {},
430446 }, nil
431447}
432448
433- func convertSecondaryIPPrefixLen (input * define.InspectNetworkSettings , output * container.NetworkSettings ) {
434- for index , ip := range input .SecondaryIPAddresses {
435- output .SecondaryIPAddresses [index ].PrefixLen = ip .PrefixLength
436- }
437- for index , ip := range input .SecondaryIPv6Addresses {
438- output .SecondaryIPv6Addresses [index ].PrefixLen = ip .PrefixLength
439- }
440- }
441-
442- func LibpodToContainerJSON (l * libpod.Container , sz bool ) (* container.InspectResponse , error ) {
449+ func LibpodToContainerJSON (l * libpod.Container , sz bool ) (* handlers.LegacyImageInspect , error ) {
443450 imageID , imageName := l .Image ()
444451 inspect , err := l .Inspect (sz )
445452 if err != nil {
@@ -465,7 +472,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
465472 }
466473
467474 // map our statuses to Docker's statuses
468- switch state .Status {
475+ switch string ( state .Status ) {
469476 case define .ContainerStateConfigured .String (), define .ContainerStateCreated .String ():
470477 state .Status = "created"
471478 case define .ContainerStateRunning .String (), define .ContainerStateStopping .String ():
@@ -483,7 +490,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
483490 if l .HasHealthCheck () && state .Status != "created" {
484491 state .Health = & container.Health {}
485492 if inspect .State .Health != nil {
486- state .Health .Status = inspect .State .Health .Status
493+ state .Health .Status = container . HealthStatus ( inspect .State .Health .Status )
487494 state .Health .FailingStreak = inspect .State .Health .FailingStreak
488495 log := inspect .State .Health .Log
489496
@@ -537,29 +544,31 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
537544 Data : inspect .GraphDriver .Data ,
538545 }
539546
540- cb := container.ContainerJSONBase {
541- ID : l .ID (),
542- Created : l .CreatedTime ().UTC ().Format (time .RFC3339Nano ), // Docker uses UTC
543- Path : inspect .Path ,
544- Args : inspect .Args ,
545- State : & state ,
546- Image : "sha256:" + imageID ,
547- ResolvConfPath : inspect .ResolvConfPath ,
548- HostnamePath : inspect .HostnamePath ,
549- HostsPath : inspect .HostsPath ,
550- LogPath : l .LogPath (),
551- Name : fmt .Sprintf ("/%s" , l .Name ()),
552- RestartCount : int (inspect .RestartCount ),
553- Driver : inspect .Driver ,
554- Platform : "linux" ,
555- MountLabel : inspect .MountLabel ,
556- ProcessLabel : inspect .ProcessLabel ,
557- AppArmorProfile : inspect .AppArmorProfile ,
558- ExecIDs : inspect .ExecIDs ,
559- HostConfig : & hc ,
560- GraphDriver : graphDriver ,
561- SizeRw : inspect .SizeRw ,
562- SizeRootFs : & inspect .SizeRootFs ,
547+ cb := handlers.LegacyImageInspect {
548+ InspectResponse : container.InspectResponse {
549+ ID : l .ID (),
550+ Created : l .CreatedTime ().UTC ().Format (time .RFC3339Nano ), // Docker uses UTC
551+ Path : inspect .Path ,
552+ Args : inspect .Args ,
553+ State : & state ,
554+ Image : "sha256:" + imageID ,
555+ ResolvConfPath : inspect .ResolvConfPath ,
556+ HostnamePath : inspect .HostnamePath ,
557+ HostsPath : inspect .HostsPath ,
558+ LogPath : l .LogPath (),
559+ Name : fmt .Sprintf ("/%s" , l .Name ()),
560+ RestartCount : int (inspect .RestartCount ),
561+ Driver : inspect .Driver ,
562+ Platform : "linux" ,
563+ MountLabel : inspect .MountLabel ,
564+ ProcessLabel : inspect .ProcessLabel ,
565+ AppArmorProfile : inspect .AppArmorProfile ,
566+ ExecIDs : inspect .ExecIDs ,
567+ HostConfig : & hc ,
568+ GraphDriver : & graphDriver ,
569+ SizeRw : inspect .SizeRw ,
570+ SizeRootFs : & inspect .SizeRootFs ,
571+ },
563572 }
564573
565574 // set Path and Args
@@ -583,42 +592,47 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
583592 }
584593 }
585594
586- // Apparently the compiler can't convert a map[string]struct{} into a nat.PortSet
587- // (Despite a nat.PortSet being that exact struct with some types added)
588- var exposedPorts nat.PortSet
595+ // Convert to moby PortSet.
596+ var exposedPorts network.PortSet
589597 if len (inspect .Config .ExposedPorts ) > 0 {
590- exposedPorts = make (nat .PortSet )
598+ exposedPorts = make (network .PortSet , len ( inspect . Config . ExposedPorts ) )
591599 for p := range inspect .Config .ExposedPorts {
592- exposedPorts [nat .Port (p )] = struct {}{}
600+ mp , err := network .ParsePort (p )
601+ if err != nil {
602+ return nil , fmt .Errorf ("invalid exposed port %q: %w" , p , err )
603+ }
604+ exposedPorts [mp ] = struct {}{}
593605 }
594606 }
595607
596- config := container.Config {
597- Hostname : l .Hostname (),
598- Domainname : inspect .Config .DomainName ,
599- User : l .User (),
600- AttachStdin : inspect .Config .AttachStdin ,
601- AttachStdout : inspect .Config .AttachStdout ,
602- AttachStderr : inspect .Config .AttachStderr ,
603- ExposedPorts : exposedPorts ,
604- Tty : inspect .Config .Tty ,
605- OpenStdin : inspect .Config .OpenStdin ,
606- StdinOnce : inspect .Config .StdinOnce ,
607- Env : inspect .Config .Env ,
608- Cmd : l .Command (),
609- Healthcheck : healthcheck ,
610- ArgsEscaped : false ,
611- Image : imageName ,
612- Volumes : nil ,
613- WorkingDir : l .WorkingDir (),
614- Entrypoint : l .Entrypoint (),
615- NetworkDisabled : false ,
616- MacAddress : "" ,
617- OnBuild : nil ,
618- Labels : l .Labels (),
619- StopSignal : strconv .Itoa (int (l .StopSignal ())),
620- StopTimeout : & stopTimeout ,
621- Shell : nil ,
608+ config := handlers.ContainerConfig {
609+ Config : container.Config {
610+ Hostname : l .Hostname (),
611+ Domainname : inspect .Config .DomainName ,
612+ User : l .User (),
613+ AttachStdin : inspect .Config .AttachStdin ,
614+ AttachStdout : inspect .Config .AttachStdout ,
615+ AttachStderr : inspect .Config .AttachStderr ,
616+ ExposedPorts : exposedPorts ,
617+ Tty : inspect .Config .Tty ,
618+ OpenStdin : inspect .Config .OpenStdin ,
619+ StdinOnce : inspect .Config .StdinOnce ,
620+ Env : inspect .Config .Env ,
621+ Cmd : l .Command (),
622+ Healthcheck : healthcheck ,
623+ ArgsEscaped : false ,
624+ Image : imageName ,
625+ Volumes : nil ,
626+ WorkingDir : l .WorkingDir (),
627+ Entrypoint : l .Entrypoint (),
628+ NetworkDisabled : false ,
629+ OnBuild : nil ,
630+ Labels : l .Labels (),
631+ StopSignal : strconv .Itoa (int (l .StopSignal ())),
632+ StopTimeout : & stopTimeout ,
633+ Shell : nil ,
634+ },
635+ MacAddress : "" ,
622636 }
623637
624638 m , err := json .Marshal (inspect .Mounts )
@@ -644,7 +658,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
644658 return nil , err
645659 }
646660
647- networkSettings := container. NetworkSettings {}
661+ networkSettings := handlers. LegacyNetworkSettings {}
648662 if err := json .Unmarshal (n , & networkSettings ); err != nil {
649663 return nil , err
650664 }
@@ -656,13 +670,10 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
656670 networkSettings .Networks = map [string ]* network.EndpointSettings {}
657671 }
658672
659- c := container.InspectResponse {
660- ContainerJSONBase : & cb ,
661- Mounts : mounts ,
662- Config : & config ,
663- NetworkSettings : & networkSettings ,
664- }
665- return & c , nil
673+ cb .Mounts = mounts
674+ cb .Config = & config
675+ cb .NetworkSettings = & networkSettings
676+ return & cb , nil
666677}
667678
668679func formatCapabilities (slice []string ) {
0 commit comments