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,16 @@ func WaitContainer(w http.ResponseWriter, r *http.Request) {
283283 utils .WaitContainerDocker (w , r )
284284}
285285
286+ //nolint:staticcheck
287+ func convertSecondaryIPPrefixLen (input * define.InspectNetworkSettings , output * handlers.LegacyNetworkSettings ) {
288+ for index , ip := range input .SecondaryIPAddresses {
289+ output .SecondaryIPAddresses [index ].PrefixLen = ip .PrefixLength
290+ }
291+ for index , ip := range input .SecondaryIPv6Addresses {
292+ output .SecondaryIPv6Addresses [index ].PrefixLen = ip .PrefixLength
293+ }
294+ }
295+
286296func LibpodToContainer (l * libpod.Container , sz bool ) (* handlers.Container , error ) {
287297 imageID , imageName := l .Image ()
288298
@@ -348,7 +358,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
348358 return nil , err
349359 }
350360
351- ports := []container.Port {}
361+ ports := []container.PortSummary {}
352362 for portKey , bindings := range inspect .NetworkSettings .Ports {
353363 portNum , proto , ok := strings .Cut (portKey , "/" )
354364 if ! ok {
@@ -362,7 +372,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
362372
363373 if len (bindings ) == 0 {
364374 // Exposed but not published
365- ports = append (ports , container.Port {
375+ ports = append (ports , container.PortSummary {
366376 PrivatePort : uint16 (containerPort ),
367377 Type : proto ,
368378 })
@@ -372,9 +382,16 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
372382 if err != nil {
373383 return nil , fmt .Errorf ("invalid HostPort: %v" , err )
374384 }
385+ addr := netip.Addr {}
386+ if b .HostIP != "" {
387+ addr , err = netip .ParseAddr (b .HostIP )
388+ if err != nil {
389+ return nil , fmt .Errorf ("invalid HostIP: %v" , err )
390+ }
391+ }
375392
376- ports = append (ports , container.Port {
377- IP : b . HostIP ,
393+ ports = append (ports , container.PortSummary {
394+ IP : addr ,
378395 PrivatePort : uint16 (containerPort ),
379396 PublicPort : uint16 (hostPortInt ),
380397 Type : proto ,
@@ -402,7 +419,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
402419 }
403420
404421 return & handlers.Container {
405- Container : container.Summary {
422+ Summary : container.Summary {
406423 ID : l .ID (),
407424 Names : []string {fmt .Sprintf ("/%s" , l .Name ())},
408425 Image : imageName ,
@@ -413,7 +430,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
413430 SizeRw : sizeRW ,
414431 SizeRootFs : sizeRootFs ,
415432 Labels : l .Labels (),
416- State : stateStr ,
433+ State : container . ContainerState ( stateStr ) ,
417434 Status : status ,
418435 // FIXME: this seems broken, the field is never shown in the API output.
419436 HostConfig : struct {
@@ -426,20 +443,12 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
426443 NetworkSettings : & networkSettings ,
427444 Mounts : mounts ,
428445 },
429- ContainerCreateConfig : dockerBackend .ContainerCreateConfig {},
446+ ContainerCreateConfig : handlers .ContainerCreateConfig {},
430447 }, nil
431448}
432449
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 ) {
450+ //nolint:staticcheck
451+ func LibpodToContainerJSON (l * libpod.Container , sz bool ) (* handlers.LegacyImageInspect , error ) {
443452 imageID , imageName := l .Image ()
444453 inspect , err := l .Inspect (sz )
445454 if err != nil {
@@ -465,7 +474,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
465474 }
466475
467476 // map our statuses to Docker's statuses
468- switch state .Status {
477+ switch string ( state .Status ) {
469478 case define .ContainerStateConfigured .String (), define .ContainerStateCreated .String ():
470479 state .Status = "created"
471480 case define .ContainerStateRunning .String (), define .ContainerStateStopping .String ():
@@ -483,7 +492,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
483492 if l .HasHealthCheck () && state .Status != "created" {
484493 state .Health = & container.Health {}
485494 if inspect .State .Health != nil {
486- state .Health .Status = inspect .State .Health .Status
495+ state .Health .Status = container . HealthStatus ( inspect .State .Health .Status )
487496 state .Health .FailingStreak = inspect .State .Health .FailingStreak
488497 log := inspect .State .Health .Log
489498
@@ -537,29 +546,31 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
537546 Data : inspect .GraphDriver .Data ,
538547 }
539548
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 ,
549+ cb := handlers.LegacyImageInspect { //nolint:staticcheck
550+ InspectResponse : container.InspectResponse {
551+ ID : l .ID (),
552+ Created : l .CreatedTime ().UTC ().Format (time .RFC3339Nano ), // Docker uses UTC
553+ Path : inspect .Path ,
554+ Args : inspect .Args ,
555+ State : & state ,
556+ Image : "sha256:" + imageID ,
557+ ResolvConfPath : inspect .ResolvConfPath ,
558+ HostnamePath : inspect .HostnamePath ,
559+ HostsPath : inspect .HostsPath ,
560+ LogPath : l .LogPath (),
561+ Name : fmt .Sprintf ("/%s" , l .Name ()),
562+ RestartCount : int (inspect .RestartCount ),
563+ Driver : inspect .Driver ,
564+ Platform : "linux" ,
565+ MountLabel : inspect .MountLabel ,
566+ ProcessLabel : inspect .ProcessLabel ,
567+ AppArmorProfile : inspect .AppArmorProfile ,
568+ ExecIDs : inspect .ExecIDs ,
569+ HostConfig : & hc ,
570+ GraphDriver : & graphDriver ,
571+ SizeRw : inspect .SizeRw ,
572+ SizeRootFs : & inspect .SizeRootFs ,
573+ },
563574 }
564575
565576 // set Path and Args
@@ -583,42 +594,47 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
583594 }
584595 }
585596
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
597+ // Convert to moby PortSet.
598+ var exposedPorts network.PortSet
589599 if len (inspect .Config .ExposedPorts ) > 0 {
590- exposedPorts = make (nat .PortSet )
600+ exposedPorts = make (network .PortSet , len ( inspect . Config . ExposedPorts ) )
591601 for p := range inspect .Config .ExposedPorts {
592- exposedPorts [nat .Port (p )] = struct {}{}
602+ mp , err := network .ParsePort (p )
603+ if err != nil {
604+ return nil , fmt .Errorf ("invalid exposed port %q: %w" , p , err )
605+ }
606+ exposedPorts [mp ] = struct {}{}
593607 }
594608 }
595609
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 ,
610+ config := handlers.ContainerConfig {
611+ Config : container.Config {
612+ Hostname : l .Hostname (),
613+ Domainname : inspect .Config .DomainName ,
614+ User : l .User (),
615+ AttachStdin : inspect .Config .AttachStdin ,
616+ AttachStdout : inspect .Config .AttachStdout ,
617+ AttachStderr : inspect .Config .AttachStderr ,
618+ ExposedPorts : exposedPorts ,
619+ Tty : inspect .Config .Tty ,
620+ OpenStdin : inspect .Config .OpenStdin ,
621+ StdinOnce : inspect .Config .StdinOnce ,
622+ Env : inspect .Config .Env ,
623+ Cmd : l .Command (),
624+ Healthcheck : healthcheck ,
625+ ArgsEscaped : false ,
626+ Image : imageName ,
627+ Volumes : nil ,
628+ WorkingDir : l .WorkingDir (),
629+ Entrypoint : l .Entrypoint (),
630+ NetworkDisabled : false ,
631+ OnBuild : nil ,
632+ Labels : l .Labels (),
633+ StopSignal : strconv .Itoa (int (l .StopSignal ())),
634+ StopTimeout : & stopTimeout ,
635+ Shell : nil ,
636+ },
637+ MacAddress : "" ,
622638 }
623639
624640 m , err := json .Marshal (inspect .Mounts )
@@ -644,7 +660,7 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
644660 return nil , err
645661 }
646662
647- networkSettings := container. NetworkSettings {}
663+ networkSettings := handlers. LegacyNetworkSettings {} //nolint:staticcheck
648664 if err := json .Unmarshal (n , & networkSettings ); err != nil {
649665 return nil , err
650666 }
@@ -656,13 +672,10 @@ func LibpodToContainerJSON(l *libpod.Container, sz bool) (*container.InspectResp
656672 networkSettings .Networks = map [string ]* network.EndpointSettings {}
657673 }
658674
659- c := container.InspectResponse {
660- ContainerJSONBase : & cb ,
661- Mounts : mounts ,
662- Config : & config ,
663- NetworkSettings : & networkSettings ,
664- }
665- return & c , nil
675+ cb .Mounts = mounts
676+ cb .Config = & config
677+ cb .NetworkSettings = & networkSettings
678+ return & cb , nil
666679}
667680
668681func formatCapabilities (slice []string ) {
0 commit comments