diff --git a/pkg/bindings/README.md b/pkg/bindings/README.md index 55255a22afc0..b972cc7bca63 100644 --- a/pkg/bindings/README.md +++ b/pkg/bindings/README.md @@ -239,3 +239,6 @@ $ You can also verify that the information being passed back and forth is correct by putting with a tool like `socat`, which can dump what the socket is seeing. + +## Reducing Binary Size with "remote" Build Tag +When building a program that uses the Podman Go bindings, you can reduce the binary size by passing the "remote" build tag to the go build command. This tag excludes code related to local Podman operations, which is not needed for applications that only interact with Podman over a network. diff --git a/pkg/bindings/containers/archive.go b/pkg/bindings/containers/archive.go index 660d9da6b335..6b229dac3d25 100644 --- a/pkg/bindings/containers/archive.go +++ b/pkg/bindings/containers/archive.go @@ -9,13 +9,13 @@ import ( "github.com/containers/podman/v4/pkg/bindings" "github.com/containers/podman/v4/pkg/copy" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) // Stat checks if the specified path is on the container. Note that the stat // report may be set even in case of an error. This happens when the path // resolves to symlink pointing to a non-existent path. -func Stat(ctx context.Context, nameOrID string, path string) (*entities.ContainerStatReport, error) { +func Stat(ctx context.Context, nameOrID string, path string) (*types.ContainerStatReport, error) { conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -36,7 +36,7 @@ func Stat(ctx context.Context, nameOrID string, path string) (*entities.Containe finalErr = errors.New(response.Status) } - var statReport *entities.ContainerStatReport + var statReport *types.ContainerStatReport fileInfo, err := copy.ExtractFileInfoFromHeader(&response.Header) if err != nil && finalErr == nil { @@ -44,18 +44,18 @@ func Stat(ctx context.Context, nameOrID string, path string) (*entities.Containe } if fileInfo != nil { - statReport = &entities.ContainerStatReport{FileInfo: *fileInfo} + statReport = &types.ContainerStatReport{FileInfo: *fileInfo} } return statReport, finalErr } -func CopyFromArchive(ctx context.Context, nameOrID string, path string, reader io.Reader) (entities.ContainerCopyFunc, error) { +func CopyFromArchive(ctx context.Context, nameOrID string, path string, reader io.Reader) (types.ContainerCopyFunc, error) { return CopyFromArchiveWithOptions(ctx, nameOrID, path, reader, nil) } // CopyFromArchiveWithOptions copy files into container -func CopyFromArchiveWithOptions(ctx context.Context, nameOrID string, path string, reader io.Reader, options *CopyOptions) (entities.ContainerCopyFunc, error) { +func CopyFromArchiveWithOptions(ctx context.Context, nameOrID string, path string, reader io.Reader, options *CopyOptions) (types.ContainerCopyFunc, error) { conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -82,7 +82,7 @@ func CopyFromArchiveWithOptions(ctx context.Context, nameOrID string, path strin } // CopyToArchive copy files from container -func CopyToArchive(ctx context.Context, nameOrID string, path string, writer io.Writer) (entities.ContainerCopyFunc, error) { +func CopyToArchive(ctx context.Context, nameOrID string, path string, writer io.Writer) (types.ContainerCopyFunc, error) { conn, err := bindings.GetClient(ctx) if err != nil { return nil, err diff --git a/pkg/bindings/containers/checkpoint.go b/pkg/bindings/containers/checkpoint.go index 8c072f588fb3..359a7d0f44c6 100644 --- a/pkg/bindings/containers/checkpoint.go +++ b/pkg/bindings/containers/checkpoint.go @@ -7,13 +7,13 @@ import ( "os" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) // Checkpoint checkpoints the given container (identified by nameOrID). All additional // options are options and allow for more fine grained control of the checkpoint process. -func Checkpoint(ctx context.Context, nameOrID string, options *CheckpointOptions) (*entities.CheckpointReport, error) { - var report entities.CheckpointReport +func Checkpoint(ctx context.Context, nameOrID string, options *CheckpointOptions) (*types.CheckpointReport, error) { + var report types.CheckpointReport if options == nil { options = new(CheckpointOptions) } @@ -52,13 +52,13 @@ func Checkpoint(ctx context.Context, nameOrID string, options *CheckpointOptions return nil, err } - return &entities.CheckpointReport{}, nil + return &types.CheckpointReport{}, nil } // Restore restores a checkpointed container to running. The container is identified by the nameOrID option. All // additional options are optional and allow finer control of the restore process. -func Restore(ctx context.Context, nameOrID string, options *RestoreOptions) (*entities.RestoreReport, error) { - var report entities.RestoreReport +func Restore(ctx context.Context, nameOrID string, options *RestoreOptions) (*types.RestoreReport, error) { + var report types.RestoreReport if options == nil { options = new(RestoreOptions) } diff --git a/pkg/bindings/containers/commit.go b/pkg/bindings/containers/commit.go index 6d094a2ff82c..e580961715fb 100644 --- a/pkg/bindings/containers/commit.go +++ b/pkg/bindings/containers/commit.go @@ -11,26 +11,26 @@ import ( "github.com/containers/podman/v4/pkg/bindings" "github.com/containers/podman/v4/pkg/bindings/images" - "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/storage/pkg/regexp" + dockerAPI "github.com/docker/docker/api/types" ) var iidRegex = regexp.Delayed(`^[0-9a-f]{12}`) // Commit creates a container image from a container. The container is defined by nameOrID. Use // the CommitOptions for finer grain control on characteristics of the resulting image. -func Commit(ctx context.Context, nameOrID string, options *CommitOptions) (entities.IDResponse, error) { +func Commit(ctx context.Context, nameOrID string, options *CommitOptions) (dockerAPI.IDResponse, error) { if options == nil { options = new(CommitOptions) } - id := entities.IDResponse{} + id := dockerAPI.IDResponse{} conn, err := bindings.GetClient(ctx) if err != nil { return id, err } params, err := options.ToParams() if err != nil { - return entities.IDResponse{}, err + return dockerAPI.IDResponse{}, err } params.Set("container", nameOrID) var requestBody io.Reader diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go index 0ca579a6c2d1..cb384853f9ba 100644 --- a/pkg/bindings/containers/containers.go +++ b/pkg/bindings/containers/containers.go @@ -12,8 +12,8 @@ import ( "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/api/handlers" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities/reports" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) var ( @@ -25,7 +25,7 @@ var ( // the most recent number of containers. The pod and size booleans indicate that pod information and rootfs // size information should also be included. Finally, the sync bool synchronizes the OCI runtime and // container state. -func List(ctx context.Context, options *ListOptions) ([]entities.ListContainer, error) { +func List(ctx context.Context, options *ListOptions) ([]types.ListContainer, error) { if options == nil { options = new(ListOptions) } @@ -33,7 +33,7 @@ func List(ctx context.Context, options *ListOptions) ([]entities.ListContainer, if err != nil { return nil, err } - var containers []entities.ListContainer + var containers []types.ListContainer params, err := options.ToParams() if err != nil { return nil, err @@ -218,7 +218,7 @@ func Start(ctx context.Context, nameOrID string, options *StartOptions) error { return response.Process(nil) } -func Stats(ctx context.Context, containers []string, options *StatsOptions) (chan entities.ContainerStatsReport, error) { +func Stats(ctx context.Context, containers []string, options *StatsOptions) (chan types.ContainerStatsReport, error) { if options == nil { options = new(StatsOptions) } @@ -243,7 +243,7 @@ func Stats(ctx context.Context, containers []string, options *StatsOptions) (cha return nil, response.Process(nil) } - statsChan := make(chan entities.ContainerStatsReport) + statsChan := make(chan types.ContainerStatsReport) go func() { defer close(statsChan) @@ -263,9 +263,9 @@ func Stats(ctx context.Context, containers []string, options *StatsOptions) (cha // fall through and do some work } - var report entities.ContainerStatsReport + var report types.ContainerStatsReport if err := dec.Decode(&report); err != nil { - report = entities.ContainerStatsReport{Error: err} + report = types.ContainerStatsReport{Error: err} } statsChan <- report diff --git a/pkg/bindings/containers/create.go b/pkg/bindings/containers/create.go index 9c090f67d4f8..6c639cad7e42 100644 --- a/pkg/bindings/containers/create.go +++ b/pkg/bindings/containers/create.go @@ -6,13 +6,13 @@ import ( "strings" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/specgen" jsoniter "github.com/json-iterator/go" ) -func CreateWithSpec(ctx context.Context, s *specgen.SpecGenerator, options *CreateOptions) (entities.ContainerCreateResponse, error) { - var ccr entities.ContainerCreateResponse +func CreateWithSpec(ctx context.Context, s *specgen.SpecGenerator, options *CreateOptions) (types.ContainerCreateResponse, error) { + var ccr types.ContainerCreateResponse if options == nil { options = new(CreateOptions) } diff --git a/pkg/bindings/containers/exec.go b/pkg/bindings/containers/exec.go index 395ef06dda45..7438e8966f86 100644 --- a/pkg/bindings/containers/exec.go +++ b/pkg/bindings/containers/exec.go @@ -11,7 +11,7 @@ import ( "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/api/handlers" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + dockerAPI "github.com/docker/docker/api/types" jsoniter "github.com/json-iterator/go" "github.com/sirupsen/logrus" ) @@ -43,7 +43,7 @@ func ExecCreate(ctx context.Context, nameOrID string, config *handlers.ExecCreat } defer resp.Body.Close() - respStruct := new(entities.IDResponse) + respStruct := new(dockerAPI.IDResponse) if err := resp.Process(respStruct); err != nil { return "", err } diff --git a/pkg/bindings/containers/update.go b/pkg/bindings/containers/update.go index 7cda7c3064ae..60b33292daf4 100644 --- a/pkg/bindings/containers/update.go +++ b/pkg/bindings/containers/update.go @@ -6,11 +6,11 @@ import ( "strings" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" jsoniter "github.com/json-iterator/go" ) -func Update(ctx context.Context, options *entities.ContainerUpdateOptions) (string, error) { +func Update(ctx context.Context, options *types.ContainerUpdateOptions) (string, error) { conn, err := bindings.GetClient(ctx) if err != nil { return "", err diff --git a/pkg/bindings/generate/generate.go b/pkg/bindings/generate/generate.go index 810aab2b34e3..d5c9207c6aa5 100644 --- a/pkg/bindings/generate/generate.go +++ b/pkg/bindings/generate/generate.go @@ -7,10 +7,10 @@ import ( "strconv" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) -func Systemd(ctx context.Context, nameOrID string, options *SystemdOptions) (*entities.GenerateSystemdReport, error) { +func Systemd(ctx context.Context, nameOrID string, options *SystemdOptions) (*types.GenerateSystemdReport, error) { if options == nil { options = new(SystemdOptions) } @@ -29,14 +29,14 @@ func Systemd(ctx context.Context, nameOrID string, options *SystemdOptions) (*en } defer response.Body.Close() - report := &entities.GenerateSystemdReport{} + report := &types.GenerateSystemdReport{} return report, response.Process(&report.Units) } // Kube generate Kubernetes YAML (v1 specification) // // Note: Caller is responsible for closing returned reader -func Kube(ctx context.Context, nameOrIDs []string, options *KubeOptions) (*entities.GenerateKubeReport, error) { +func Kube(ctx context.Context, nameOrIDs []string, options *KubeOptions) (*types.GenerateKubeReport, error) { if options == nil { options = new(KubeOptions) } @@ -64,7 +64,7 @@ func Kube(ctx context.Context, nameOrIDs []string, options *KubeOptions) (*entit } if response.StatusCode == http.StatusOK { - return &entities.GenerateKubeReport{Reader: response.Body}, nil + return &types.GenerateKubeReport{Reader: response.Body}, nil } // Unpack the error. diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index 0f0f2dee8965..d4089d0a400b 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -18,11 +18,11 @@ import ( "strings" "github.com/containers/buildah/define" - "github.com/containers/image/v5/types" + imageTypes "github.com/containers/image/v5/types" ldefine "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/auth" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/util" "github.com/containers/storage/pkg/fileutils" "github.com/containers/storage/pkg/ioutils" @@ -50,7 +50,7 @@ type BuildResponse struct { } // Build creates an image using a containerfile reference -func Build(ctx context.Context, containerFiles []string, options entities.BuildOptions) (*entities.BuildReport, error) { +func Build(ctx context.Context, containerFiles []string, options types.BuildOptions) (*types.BuildReport, error) { if options.CommonBuildOpts == nil { options.CommonBuildOpts = new(define.CommonBuildOptions) } @@ -255,9 +255,9 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } switch options.SkipUnusedStages { - case types.OptionalBoolTrue: + case imageTypes.OptionalBoolTrue: params.Set("skipunusedstages", "1") - case types.OptionalBoolFalse: + case imageTypes.OptionalBoolFalse: params.Set("skipunusedstages", "0") } @@ -342,9 +342,9 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO params.Set("pullpolicy", options.PullPolicy.String()) switch options.CommonBuildOpts.IdentityLabel { - case types.OptionalBoolTrue: + case imageTypes.OptionalBoolTrue: params.Set("identitylabel", "1") - case types.OptionalBoolFalse: + case imageTypes.OptionalBoolFalse: params.Set("identitylabel", "0") } if options.Quiet { @@ -416,7 +416,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO } else { headers, err = auth.MakeXRegistryConfigHeader(options.SystemContext, "", "") } - if options.SystemContext.DockerInsecureSkipTLSVerify == types.OptionalBoolTrue { + if options.SystemContext.DockerInsecureSkipTLSVerify == imageTypes.OptionalBoolTrue { params.Set("tlsVerify", "false") } } @@ -618,7 +618,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO // even when the server quit but it seems desirable to // distinguish a proper build from a transient EOF. case <-response.Request.Context().Done(): - return &entities.BuildReport{ID: id, SaveFormat: saveFormat}, nil + return &types.BuildReport{ID: id, SaveFormat: saveFormat}, nil default: // non-blocking select } @@ -632,7 +632,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO if errors.Is(err, io.EOF) && id != "" { break } - return &entities.BuildReport{ID: id, SaveFormat: saveFormat}, fmt.Errorf("decoding stream: %w", err) + return &types.BuildReport{ID: id, SaveFormat: saveFormat}, fmt.Errorf("decoding stream: %w", err) } switch { @@ -645,12 +645,12 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO case s.Error != nil: // If there's an error, return directly. The stream // will be closed on return. - return &entities.BuildReport{ID: id, SaveFormat: saveFormat}, errors.New(s.Error.Message) + return &types.BuildReport{ID: id, SaveFormat: saveFormat}, errors.New(s.Error.Message) default: - return &entities.BuildReport{ID: id, SaveFormat: saveFormat}, errors.New("failed to parse build results stream, unexpected input") + return &types.BuildReport{ID: id, SaveFormat: saveFormat}, errors.New("failed to parse build results stream, unexpected input") } } - return &entities.BuildReport{ID: id, SaveFormat: saveFormat}, nil + return &types.BuildReport{ID: id, SaveFormat: saveFormat}, nil } func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { diff --git a/pkg/bindings/images/images.go b/pkg/bindings/images/images.go index ef76bb9dfc63..d9ef13ddc4b6 100644 --- a/pkg/bindings/images/images.go +++ b/pkg/bindings/images/images.go @@ -10,11 +10,11 @@ import ( "strconv" imageTypes "github.com/containers/image/v5/types" - "github.com/containers/podman/v4/pkg/api/handlers/types" + handlersTypes "github.com/containers/podman/v4/pkg/api/handlers/types" "github.com/containers/podman/v4/pkg/auth" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities/reports" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) // Exists a lightweight way to determine if an image exists in local storage. It returns a @@ -35,11 +35,11 @@ func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool, // List returns a list of images in local storage. The all boolean and filters parameters are optional // ways to alter the image query. -func List(ctx context.Context, options *ListOptions) ([]*entities.ImageSummary, error) { +func List(ctx context.Context, options *ListOptions) ([]*types.ImageSummary, error) { if options == nil { options = new(ListOptions) } - var imageSummary []*entities.ImageSummary + var imageSummary []*types.ImageSummary conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -59,7 +59,7 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.ImageSummary, // Get performs an image inspect. To have the on-disk size of the image calculated, you can // use the optional size parameter. -func GetImage(ctx context.Context, nameOrID string, options *GetOptions) (*entities.ImageInspectReport, error) { +func GetImage(ctx context.Context, nameOrID string, options *GetOptions) (*types.ImageInspectReport, error) { if options == nil { options = new(GetOptions) } @@ -71,7 +71,7 @@ func GetImage(ctx context.Context, nameOrID string, options *GetOptions) (*entit if err != nil { return nil, err } - inspectedData := entities.ImageInspectReport{} + inspectedData := types.ImageInspectReport{} response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/images/%s/json", params, nil, nameOrID) if err != nil { return &inspectedData, err @@ -82,11 +82,11 @@ func GetImage(ctx context.Context, nameOrID string, options *GetOptions) (*entit } // Tree retrieves a "tree" based representation of the given image -func Tree(ctx context.Context, nameOrID string, options *TreeOptions) (*entities.ImageTreeReport, error) { +func Tree(ctx context.Context, nameOrID string, options *TreeOptions) (*types.ImageTreeReport, error) { if options == nil { options = new(TreeOptions) } - var report entities.ImageTreeReport + var report types.ImageTreeReport conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -105,12 +105,12 @@ func Tree(ctx context.Context, nameOrID string, options *TreeOptions) (*entities } // History returns the parent layers of an image. -func History(ctx context.Context, nameOrID string, options *HistoryOptions) ([]*types.HistoryResponse, error) { +func History(ctx context.Context, nameOrID string, options *HistoryOptions) ([]*handlersTypes.HistoryResponse, error) { if options == nil { options = new(HistoryOptions) } _ = options - var history []*types.HistoryResponse + var history []*handlersTypes.HistoryResponse conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -124,8 +124,8 @@ func History(ctx context.Context, nameOrID string, options *HistoryOptions) ([]* return history, response.Process(&history) } -func Load(ctx context.Context, r io.Reader) (*entities.ImageLoadReport, error) { - var report entities.ImageLoadReport +func Load(ctx context.Context, r io.Reader) (*types.ImageLoadReport, error) { + var report types.ImageLoadReport conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -242,11 +242,11 @@ func Untag(ctx context.Context, nameOrID, tag, repo string, options *UntagOption // Import adds the given image to the local image store. This can be done by file and the given reader // or via the url parameter. Additional metadata can be associated with the image by using the changes and // message parameters. The image can also be tagged given a reference. One of url OR r must be provided. -func Import(ctx context.Context, r io.Reader, options *ImportOptions) (*entities.ImageImportReport, error) { +func Import(ctx context.Context, r io.Reader, options *ImportOptions) (*types.ImageImportReport, error) { if options == nil { options = new(ImportOptions) } - var report entities.ImageImportReport + var report types.ImageImportReport if r != nil && options.URL != nil { return nil, errors.New("url and r parameters cannot be used together") } @@ -268,7 +268,7 @@ func Import(ctx context.Context, r io.Reader, options *ImportOptions) (*entities } // Search is the binding for libpod's v2 endpoints for Search images. -func Search(ctx context.Context, term string, options *SearchOptions) ([]entities.ImageSearchReport, error) { +func Search(ctx context.Context, term string, options *SearchOptions) ([]types.ImageSearchReport, error) { if options == nil { options = new(SearchOptions) } @@ -299,7 +299,7 @@ func Search(ctx context.Context, term string, options *SearchOptions) ([]entitie } defer response.Body.Close() - results := []entities.ImageSearchReport{} + results := []types.ImageSearchReport{} if err := response.Process(&results); err != nil { return nil, err } diff --git a/pkg/bindings/images/pull.go b/pkg/bindings/images/pull.go index 43592f6e216f..4172e8537309 100644 --- a/pkg/bindings/images/pull.go +++ b/pkg/bindings/images/pull.go @@ -10,10 +10,10 @@ import ( "os" "strconv" - "github.com/containers/image/v5/types" + imgTypes "github.com/containers/image/v5/types" "github.com/containers/podman/v4/pkg/auth" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/errorhandling" ) @@ -41,7 +41,7 @@ func Pull(ctx context.Context, rawImage string, options *PullOptions) ([]string, params.Set("tlsVerify", strconv.FormatBool(!options.GetSkipTLSVerify())) } - header, err := auth.MakeXRegistryAuthHeader(&types.SystemContext{AuthFilePath: options.GetAuthfile()}, options.GetUsername(), options.GetPassword()) + header, err := auth.MakeXRegistryAuthHeader(&imgTypes.SystemContext{AuthFilePath: options.GetAuthfile()}, options.GetUsername(), options.GetPassword()) if err != nil { return nil, err } @@ -71,7 +71,7 @@ func Pull(ctx context.Context, rawImage string, options *PullOptions) ([]string, var pullErrors []error LOOP: for { - var report entities.ImagePullReport + var report types.ImagePullReport if err := dec.Decode(&report); err != nil { if errors.Is(err, io.EOF) { break diff --git a/pkg/bindings/images/push.go b/pkg/bindings/images/push.go index ea1d96823e0f..33ad34dd1343 100644 --- a/pkg/bindings/images/push.go +++ b/pkg/bindings/images/push.go @@ -13,7 +13,7 @@ import ( imageTypes "github.com/containers/image/v5/types" "github.com/containers/podman/v4/pkg/auth" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) // Push is the binding for libpod's endpoints for push images. Note that @@ -69,7 +69,7 @@ func Push(ctx context.Context, source string, destination string, options *PushO dec := json.NewDecoder(response.Body) LOOP: for { - var report entities.ImagePushStream + var report types.ImagePushStream if err := dec.Decode(&report); err != nil { if errors.Is(err, io.EOF) { break diff --git a/pkg/bindings/images/rm.go b/pkg/bindings/images/rm.go index eb3eef10c47c..2d251e6ed744 100644 --- a/pkg/bindings/images/rm.go +++ b/pkg/bindings/images/rm.go @@ -4,19 +4,19 @@ import ( "context" "net/http" - "github.com/containers/podman/v4/pkg/api/handlers/types" + handlersTypes "github.com/containers/podman/v4/pkg/api/handlers/types" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/errorhandling" ) // Remove removes one or more images from the local storage. Use optional force option to remove an // image, even if it's used by containers. -func Remove(ctx context.Context, images []string, options *RemoveOptions) (*entities.ImageRemoveReport, []error) { +func Remove(ctx context.Context, images []string, options *RemoveOptions) (*types.ImageRemoveReport, []error) { if options == nil { options = new(RemoveOptions) } - var report types.LibpodImagesRemoveReport + var report handlersTypes.LibpodImagesRemoveReport conn, err := bindings.GetClient(ctx) if err != nil { return nil, []error{err} diff --git a/pkg/bindings/images/types.go b/pkg/bindings/images/types.go index e5c58df00a7d..66171087920f 100644 --- a/pkg/bindings/images/types.go +++ b/pkg/bindings/images/types.go @@ -3,7 +3,7 @@ package images import ( "io" - buildahDefine "github.com/containers/buildah/define" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) // RemoveOptions are optional options for image removal @@ -226,9 +226,7 @@ type PullOptions struct { } // BuildOptions are optional options for building images -type BuildOptions struct { - buildahDefine.BuildOptions -} +type BuildOptions = types.BuildOptions // ExistsOptions are optional options for checking if an image exists // diff --git a/pkg/bindings/kube/kube.go b/pkg/bindings/kube/kube.go index fefbe1a2f5fc..c9e2c025f62c 100644 --- a/pkg/bindings/kube/kube.go +++ b/pkg/bindings/kube/kube.go @@ -12,11 +12,11 @@ import ( "github.com/containers/podman/v4/pkg/auth" "github.com/containers/podman/v4/pkg/bindings" "github.com/containers/podman/v4/pkg/bindings/generate" - "github.com/containers/podman/v4/pkg/domain/entities" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/sirupsen/logrus" ) -func Play(ctx context.Context, path string, options *PlayOptions) (*entities.KubePlayReport, error) { +func Play(ctx context.Context, path string, options *PlayOptions) (*entitiesTypes.KubePlayReport, error) { f, err := os.Open(path) if err != nil { return nil, err @@ -26,8 +26,8 @@ func Play(ctx context.Context, path string, options *PlayOptions) (*entities.Kub return PlayWithBody(ctx, f, options) } -func PlayWithBody(ctx context.Context, body io.Reader, options *PlayOptions) (*entities.KubePlayReport, error) { - var report entities.KubePlayReport +func PlayWithBody(ctx context.Context, body io.Reader, options *PlayOptions) (*entitiesTypes.KubePlayReport, error) { + var report entitiesTypes.KubePlayReport if options == nil { options = new(PlayOptions) } @@ -88,7 +88,7 @@ func PlayWithBody(ctx context.Context, body io.Reader, options *PlayOptions) (*e return &report, nil } -func Down(ctx context.Context, path string, options DownOptions) (*entities.KubePlayReport, error) { +func Down(ctx context.Context, path string, options DownOptions) (*entitiesTypes.KubePlayReport, error) { f, err := os.Open(path) if err != nil { return nil, err @@ -102,8 +102,8 @@ func Down(ctx context.Context, path string, options DownOptions) (*entities.Kube return DownWithBody(ctx, f, options) } -func DownWithBody(ctx context.Context, body io.Reader, options DownOptions) (*entities.KubePlayReport, error) { - var report entities.KubePlayReport +func DownWithBody(ctx context.Context, body io.Reader, options DownOptions) (*entitiesTypes.KubePlayReport, error) { + var report entitiesTypes.KubePlayReport conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -125,7 +125,7 @@ func DownWithBody(ctx context.Context, body io.Reader, options DownOptions) (*en } // Kube generate Kubernetes YAML (v1 specification) -func Generate(ctx context.Context, nameOrIDs []string, options generate.KubeOptions) (*entities.GenerateKubeReport, error) { +func Generate(ctx context.Context, nameOrIDs []string, options generate.KubeOptions) (*entitiesTypes.GenerateKubeReport, error) { return generate.Kube(ctx, nameOrIDs, &options) } diff --git a/pkg/bindings/manifests/manifests.go b/pkg/bindings/manifests/manifests.go index ec3affce0d49..b825f47fb570 100644 --- a/pkg/bindings/manifests/manifests.go +++ b/pkg/bindings/manifests/manifests.go @@ -17,8 +17,9 @@ import ( "github.com/containers/podman/v4/pkg/auth" "github.com/containers/podman/v4/pkg/bindings" "github.com/containers/podman/v4/pkg/bindings/images" - "github.com/containers/podman/v4/pkg/domain/entities" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/errorhandling" + dockerAPI "github.com/docker/docker/api/types" jsoniter "github.com/json-iterator/go" ) @@ -27,7 +28,7 @@ import ( // of a list if the name provided is a manifest list. The ID of the new manifest list // is returned as a string. func Create(ctx context.Context, name string, images []string, options *CreateOptions) (string, error) { - var idr entities.IDResponse + var idr dockerAPI.IDResponse if options == nil { options = new(CreateOptions) } @@ -179,8 +180,8 @@ func Remove(ctx context.Context, name, digest string, _ *RemoveOptions) (string, } // Delete removes specified manifest from local storage. -func Delete(ctx context.Context, name string) (*entities.ManifestRemoveReport, error) { - var report entities.ManifestRemoveReport +func Delete(ctx context.Context, name string) (*entitiesTypes.ManifestRemoveReport, error) { + var report entitiesTypes.ManifestRemoveReport conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -250,7 +251,7 @@ func Push(ctx context.Context, name, destination string, options *images.PushOpt dec := json.NewDecoder(response.Body) for { - var report entities.ManifestPushReport + var report entitiesTypes.ManifestPushReport if err := dec.Decode(&report); err != nil { return "", err } @@ -320,7 +321,7 @@ func Modify(ctx context.Context, name string, images []string, options *ModifyOp } if response.IsSuccess() || response.IsRedirection() { - var report entities.ManifestModifyReport + var report entitiesTypes.ManifestModifyReport if err = jsoniter.Unmarshal(data, &report); err != nil { return "", fmt.Errorf("unable to decode API response: %w", err) } diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go index 79d26cbfa83b..f95fadb1f2ba 100644 --- a/pkg/bindings/network/network.go +++ b/pkg/bindings/network/network.go @@ -8,7 +8,7 @@ import ( "github.com/containers/common/libnetwork/types" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" jsoniter "github.com/json-iterator/go" ) @@ -88,8 +88,8 @@ func Inspect(ctx context.Context, nameOrID string, _ *InspectOptions) (types.Net // Remove deletes a defined network configuration by name. The optional force boolean // will remove all containers associated with the network when set to true. A slice // of NetworkRemoveReports are returned. -func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) ([]*entities.NetworkRmReport, error) { - var reports []*entities.NetworkRmReport +func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) ([]*entitiesTypes.NetworkRmReport, error) { + var reports []*entitiesTypes.NetworkRmReport if options == nil { options = new(RemoveOptions) } @@ -177,7 +177,7 @@ func Connect(ctx context.Context, networkName string, containerNameOrID string, return err } // Connect sends everything in body - connect := entities.NetworkConnectOptions{ + connect := entitiesTypes.NetworkConnectOptions{ Container: containerNameOrID, PerNetworkOptions: *options, } @@ -212,7 +212,7 @@ func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool, } // Prune removes unused networks -func Prune(ctx context.Context, options *PruneOptions) ([]*entities.NetworkPruneReport, error) { +func Prune(ctx context.Context, options *PruneOptions) ([]*entitiesTypes.NetworkPruneReport, error) { if options == nil { options = new(PruneOptions) } @@ -221,7 +221,7 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*entities.NetworkPrune return nil, err } var ( - prunedNetworks []*entities.NetworkPruneReport + prunedNetworks []*entitiesTypes.NetworkPruneReport ) conn, err := bindings.GetClient(ctx) if err != nil { diff --git a/pkg/bindings/play/play.go b/pkg/bindings/play/play.go index 803349b88408..7e8f9ee40f45 100644 --- a/pkg/bindings/play/play.go +++ b/pkg/bindings/play/play.go @@ -5,23 +5,23 @@ import ( "io" "github.com/containers/podman/v4/pkg/bindings/kube" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) type KubeOptions = kube.PlayOptions -func Kube(ctx context.Context, path string, options *KubeOptions) (*entities.PlayKubeReport, error) { +func Kube(ctx context.Context, path string, options *KubeOptions) (*types.PlayKubeReport, error) { return kube.Play(ctx, path, options) } -func KubeWithBody(ctx context.Context, body io.Reader, options *KubeOptions) (*entities.PlayKubeReport, error) { +func KubeWithBody(ctx context.Context, body io.Reader, options *KubeOptions) (*types.PlayKubeReport, error) { return kube.PlayWithBody(ctx, body, options) } -func Down(ctx context.Context, path string, options kube.DownOptions) (*entities.PlayKubeReport, error) { +func Down(ctx context.Context, path string, options kube.DownOptions) (*types.PlayKubeReport, error) { return kube.Down(ctx, path, options) } -func DownWithBody(ctx context.Context, body io.Reader, options kube.DownOptions) (*entities.PlayKubeReport, error) { +func DownWithBody(ctx context.Context, body io.Reader, options kube.DownOptions) (*types.PlayKubeReport, error) { return kube.DownWithBody(ctx, body, options) } diff --git a/pkg/bindings/pods/pods.go b/pkg/bindings/pods/pods.go index 47befb093524..615f2b6dbe9b 100644 --- a/pkg/bindings/pods/pods.go +++ b/pkg/bindings/pods/pods.go @@ -8,17 +8,17 @@ import ( "github.com/containers/podman/v4/pkg/api/handlers" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/errorhandling" jsoniter "github.com/json-iterator/go" ) -func CreatePodFromSpec(ctx context.Context, spec *entities.PodSpec) (*entities.PodCreateReport, error) { +func CreatePodFromSpec(ctx context.Context, spec *entitiesTypes.PodSpec) (*entitiesTypes.PodCreateReport, error) { var ( - pcr entities.PodCreateReport + pcr entitiesTypes.PodCreateReport ) if spec == nil { - spec = new(entities.PodSpec) + spec = new(entitiesTypes.PodSpec) } conn, err := bindings.GetClient(ctx) if err != nil { @@ -54,9 +54,9 @@ func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool, } // Inspect returns low-level information about the given pod. -func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entities.PodInspectReport, error) { +func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entitiesTypes.PodInspectReport, error) { var ( - report entities.PodInspectReport + report entitiesTypes.PodInspectReport ) if options == nil { options = new(InspectOptions) @@ -77,9 +77,9 @@ func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*en // Kill sends a SIGTERM to all the containers in a pod. The optional signal parameter // can be used to override SIGTERM. -func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entities.PodKillReport, error) { +func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entitiesTypes.PodKillReport, error) { var ( - report entities.PodKillReport + report entitiesTypes.PodKillReport ) if options == nil { options = new(KillOptions) @@ -102,8 +102,8 @@ func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entities } // Pause pauses all running containers in a given pod. -func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entities.PodPauseReport, error) { - var report entities.PodPauseReport +func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entitiesTypes.PodPauseReport, error) { + var report entitiesTypes.PodPauseReport if options == nil { options = new(PauseOptions) } @@ -123,8 +123,8 @@ func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entiti // Prune by default removes all non-running pods in local storage. // And with force set true removes all pods. -func Prune(ctx context.Context, options *PruneOptions) ([]*entities.PodPruneReport, error) { - var reports []*entities.PodPruneReport +func Prune(ctx context.Context, options *PruneOptions) ([]*entitiesTypes.PodPruneReport, error) { + var reports []*entitiesTypes.PodPruneReport if options == nil { options = new(PruneOptions) } @@ -144,9 +144,9 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*entities.PodPruneRepo // List returns all pods in local storage. The optional filters parameter can // be used to refine which pods should be listed. -func List(ctx context.Context, options *ListOptions) ([]*entities.ListPodsReport, error) { +func List(ctx context.Context, options *ListOptions) ([]*entitiesTypes.ListPodsReport, error) { var ( - podsReports []*entities.ListPodsReport + podsReports []*entitiesTypes.ListPodsReport ) if options == nil { options = new(ListOptions) @@ -169,8 +169,8 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.ListPodsReport } // Restart restarts all containers in a pod. -func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entities.PodRestartReport, error) { - var report entities.PodRestartReport +func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entitiesTypes.PodRestartReport, error) { + var report entitiesTypes.PodRestartReport if options == nil { options = new(RestartOptions) } @@ -190,8 +190,8 @@ func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*en // Remove deletes a Pod from local storage. The optional force parameter denotes // that the Pod can be removed even if in a running state. -func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entities.PodRmReport, error) { - var report entities.PodRmReport +func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entitiesTypes.PodRmReport, error) { + var report entitiesTypes.PodRmReport if options == nil { options = new(RemoveOptions) } @@ -213,8 +213,8 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*enti } // Start starts all containers in a pod. -func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entities.PodStartReport, error) { - var report entities.PodStartReport +func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entitiesTypes.PodStartReport, error) { + var report entitiesTypes.PodStartReport if options == nil { options = new(StartOptions) } @@ -239,8 +239,8 @@ func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entiti // Stop stops all containers in a Pod. The optional timeout parameter can be // used to override the timeout before the container is killed. -func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entities.PodStopReport, error) { - var report entities.PodStopReport +func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entitiesTypes.PodStopReport, error) { + var report entitiesTypes.PodStopReport if options == nil { options = new(StopOptions) } @@ -302,12 +302,12 @@ func Top(ctx context.Context, nameOrID string, options *TopOptions) ([]string, e } // Unpause unpauses all paused containers in a Pod. -func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*entities.PodUnpauseReport, error) { +func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*entitiesTypes.PodUnpauseReport, error) { if options == nil { options = new(UnpauseOptions) } _ = options - var report entities.PodUnpauseReport + var report entitiesTypes.PodUnpauseReport conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -322,7 +322,7 @@ func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*en } // Stats display resource-usage statistics of one or more pods. -func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*entities.PodStatsReport, error) { +func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*entitiesTypes.PodStatsReport, error) { if options == nil { options = new(StatsOptions) } @@ -338,7 +338,7 @@ func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]* params.Add("namesOrIDs", i) } - var reports []*entities.PodStatsReport + var reports []*entitiesTypes.PodStatsReport response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/pods/stats", params, nil) if err != nil { return nil, err diff --git a/pkg/bindings/secrets/secrets.go b/pkg/bindings/secrets/secrets.go index 2cd392a14473..0413fbab2fec 100644 --- a/pkg/bindings/secrets/secrets.go +++ b/pkg/bindings/secrets/secrets.go @@ -6,13 +6,13 @@ import ( "net/http" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" ) // List returns information about existing secrets in the form of a slice. -func List(ctx context.Context, options *ListOptions) ([]*entities.SecretInfoReport, error) { +func List(ctx context.Context, options *ListOptions) ([]*entitiesTypes.SecretInfoReport, error) { var ( - secrs []*entities.SecretInfoReport + secrs []*entitiesTypes.SecretInfoReport ) conn, err := bindings.GetClient(ctx) if err != nil { @@ -32,12 +32,12 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.SecretInfoRepo } // Inspect returns low-level information about a secret. -func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entities.SecretInfoReport, error) { +func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entitiesTypes.SecretInfoReport, error) { if options == nil { options = new(InspectOptions) } var ( - inspect *entities.SecretInfoReport + inspect *entitiesTypes.SecretInfoReport ) conn, err := bindings.GetClient(ctx) if err != nil { @@ -72,9 +72,9 @@ func Remove(ctx context.Context, nameOrID string) error { } // Create creates a secret given some data -func Create(ctx context.Context, reader io.Reader, options *CreateOptions) (*entities.SecretCreateReport, error) { +func Create(ctx context.Context, reader io.Reader, options *CreateOptions) (*entitiesTypes.SecretCreateReport, error) { var ( - create *entities.SecretCreateReport + create *entitiesTypes.SecretCreateReport ) conn, err := bindings.GetClient(ctx) if err != nil { diff --git a/pkg/bindings/system/system.go b/pkg/bindings/system/system.go index 733b2cb5c3f1..9dc3736a58df 100644 --- a/pkg/bindings/system/system.go +++ b/pkg/bindings/system/system.go @@ -11,14 +11,14 @@ import ( "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/sirupsen/logrus" ) // Events allows you to monitor libdpod related events like container creation and // removal. The events are then passed to the eventChan provided. The optional cancelChan // can be used to cancel the read of events and close down the HTTP connection. -func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan bool, options *EventsOptions) error { +func Events(ctx context.Context, eventChan chan types.Event, cancelChan chan bool, options *EventsOptions) error { conn, err := bindings.GetClient(ctx) if err != nil { return err @@ -44,7 +44,7 @@ func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan dec := json.NewDecoder(response.Body) for err = (error)(nil); err == nil; { - var e = entities.Event{} + var e = types.Event{} err = dec.Decode(&e) if err == nil { eventChan <- e @@ -62,9 +62,9 @@ func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan } // Prune removes all unused system data. -func Prune(ctx context.Context, options *PruneOptions) (*entities.SystemPruneReport, error) { +func Prune(ctx context.Context, options *PruneOptions) (*types.SystemPruneReport, error) { var ( - report entities.SystemPruneReport + report types.SystemPruneReport ) conn, err := bindings.GetClient(ctx) if err != nil { @@ -83,10 +83,10 @@ func Prune(ctx context.Context, options *PruneOptions) (*entities.SystemPruneRep return &report, response.Process(&report) } -func Version(ctx context.Context, options *VersionOptions) (*entities.SystemVersionReport, error) { +func Version(ctx context.Context, options *VersionOptions) (*types.SystemVersionReport, error) { var ( - component entities.ComponentVersion - report entities.SystemVersionReport + component types.SystemComponentVersion + report types.SystemVersionReport ) if options == nil { options = new(VersionOptions) @@ -134,8 +134,8 @@ func Version(ctx context.Context, options *VersionOptions) (*entities.SystemVers // DiskUsage returns information about image, container, and volume disk // consumption -func DiskUsage(ctx context.Context, options *DiskOptions) (*entities.SystemDfReport, error) { - var report entities.SystemDfReport +func DiskUsage(ctx context.Context, options *DiskOptions) (*types.SystemDfReport, error) { + var report types.SystemDfReport if options == nil { options = new(DiskOptions) } diff --git a/pkg/bindings/volumes/volumes.go b/pkg/bindings/volumes/volumes.go index 290eab219aa9..f52ac46405a3 100644 --- a/pkg/bindings/volumes/volumes.go +++ b/pkg/bindings/volumes/volumes.go @@ -6,15 +6,15 @@ import ( "strings" "github.com/containers/podman/v4/pkg/bindings" - "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities/reports" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" jsoniter "github.com/json-iterator/go" ) // Create creates a volume given its configuration. -func Create(ctx context.Context, config entities.VolumeCreateOptions, options *CreateOptions) (*entities.VolumeConfigResponse, error) { +func Create(ctx context.Context, config entitiesTypes.VolumeCreateOptions, options *CreateOptions) (*entitiesTypes.VolumeConfigResponse, error) { var ( - v entities.VolumeConfigResponse + v entitiesTypes.VolumeConfigResponse ) if options == nil { options = new(CreateOptions) @@ -39,9 +39,9 @@ func Create(ctx context.Context, config entities.VolumeCreateOptions, options *C } // Inspect returns low-level information about a volume. -func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entities.VolumeConfigResponse, error) { +func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entitiesTypes.VolumeConfigResponse, error) { var ( - inspect entities.VolumeConfigResponse + inspect entitiesTypes.VolumeConfigResponse ) if options == nil { options = new(InspectOptions) @@ -62,9 +62,9 @@ func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*en // List returns the configurations for existing volumes in the form of a slice. Optionally, filters // can be used to refine the list of volumes. -func List(ctx context.Context, options *ListOptions) ([]*entities.VolumeListReport, error) { +func List(ctx context.Context, options *ListOptions) ([]*entitiesTypes.VolumeListReport, error) { var ( - vols []*entities.VolumeListReport + vols []*entitiesTypes.VolumeListReport ) conn, err := bindings.GetClient(ctx) if err != nil { diff --git a/pkg/domain/entities/container_ps.go b/pkg/domain/entities/container_ps.go index cddea3987ab3..99aa0daa9c8f 100644 --- a/pkg/domain/entities/container_ps.go +++ b/pkg/domain/entities/container_ps.go @@ -4,90 +4,15 @@ import ( "errors" "sort" "strings" - "time" - "github.com/containers/common/libnetwork/types" - "github.com/containers/podman/v4/pkg/ps/define" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) // ListContainer describes a container suitable for listing -type ListContainer struct { - // AutoRemove - AutoRemove bool - // Container command - Command []string - // Container creation time - Created time.Time - // Human-readable container creation time. - CreatedAt string - // CIDFile specified at creation time. - CIDFile string - // If container has exited/stopped - Exited bool - // Time container exited - ExitedAt int64 - // If container has exited, the return code from the command - ExitCode int32 - // The unique identifier for the container - ID string `json:"Id"` - // Container image - Image string - // Container image ID - ImageID string - // If this container is a Pod infra container - IsInfra bool - // Labels for container - Labels map[string]string - // User volume mounts - Mounts []string - // The names assigned to the container - Names []string - // Namespaces the container belongs to. Requires the - // namespace boolean to be true - Namespaces ListContainerNamespaces - // The network names assigned to the container - Networks []string - // The process id of the container - Pid int - // If the container is part of Pod, the Pod ID. Requires the pod - // boolean to be set - Pod string - // If the container is part of Pod, the Pod name. Requires the pod - // boolean to be set - PodName string - // Port mappings - Ports []types.PortMapping - // Restarts is how many times the container was restarted by its - // restart policy. This is NOT incremented by normal container restarts - // (only by restart policy). - Restarts uint - // Size of the container rootfs. Requires the size boolean to be true - Size *define.ContainerSize - // Time when container started - StartedAt int64 - // State of container - State string - // Status is a human-readable approximation of a duration for json output - Status string -} +type ListContainer = types.ListContainer // ListContainerNamespaces contains the identifiers of the container's Linux namespaces -type ListContainerNamespaces struct { - // Mount namespace - MNT string `json:"Mnt,omitempty"` - // Cgroup namespace - Cgroup string `json:"Cgroup,omitempty"` - // IPC namespace - IPC string `json:"Ipc,omitempty"` - // Network namespace - NET string `json:"Net,omitempty"` - // PID namespace - PIDNS string `json:"Pidns,omitempty"` - // UTS namespace - UTS string `json:"Uts,omitempty"` - // User namespace - User string `json:"User,omitempty"` -} +type ListContainerNamespaces = types.ListContainerNamespaces type SortListContainers []ListContainer @@ -176,31 +101,3 @@ func SortPsOutput(sortBy string, psOutput SortListContainers) (SortListContainer } return psOutput, nil } - -func (l ListContainer) CGROUPNS() string { - return l.Namespaces.Cgroup -} - -func (l ListContainer) IPC() string { - return l.Namespaces.IPC -} - -func (l ListContainer) MNT() string { - return l.Namespaces.MNT -} - -func (l ListContainer) NET() string { - return l.Namespaces.NET -} - -func (l ListContainer) PIDNS() string { - return l.Namespaces.PIDNS -} - -func (l ListContainer) USERNS() string { - return l.Namespaces.User -} - -func (l ListContainer) UTS() string { - return l.Namespaces.UTS -} diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go index a1d5c754e7d5..0231c8c9903a 100644 --- a/pkg/domain/entities/containers.go +++ b/pkg/domain/entities/containers.go @@ -7,8 +7,9 @@ import ( "time" nettypes "github.com/containers/common/libnetwork/types" - "github.com/containers/image/v5/types" + imageTypes "github.com/containers/image/v5/types" "github.com/containers/podman/v4/libpod/define" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/specgen" "github.com/containers/storage/pkg/archive" ) @@ -43,7 +44,7 @@ type ContainerRunlabelOptions struct { SignaturePolicy string // SkipTLSVerify - skip HTTPS and certificate verifications when // contacting registries. - SkipTLSVerify types.OptionalBool + SkipTLSVerify imageTypes.OptionalBool } // ContainerRunlabelReport contains the results from executing container-runlabel. @@ -157,9 +158,7 @@ type ContainerInspectReport struct { *define.InspectContainerData } -type ContainerStatReport struct { - define.FileInfo -} +type ContainerStatReport = types.ContainerStatReport type CommitOptions struct { Author string @@ -212,13 +211,7 @@ type CheckpointOptions struct { FileLocks bool } -type CheckpointReport struct { - Err error `json:"-"` - Id string `json:"Id"` //nolint:revive,stylecheck - RawInput string `json:"-"` - RuntimeDuration int64 `json:"runtime_checkpoint_duration"` - CRIUStatistics *define.CRIUCheckpointRestoreStatistics `json:"criu_statistics"` -} +type CheckpointReport = types.CheckpointReport type RestoreOptions struct { All bool @@ -239,13 +232,7 @@ type RestoreOptions struct { FileLocks bool } -type RestoreReport struct { - Err error `json:"-"` - Id string `json:"Id"` //nolint:revive,stylecheck - RawInput string `json:"-"` - RuntimeDuration int64 `json:"runtime_restore_duration"` - CRIUStatistics *define.CRIUCheckpointRestoreStatistics `json:"criu_statistics"` -} +type RestoreReport = types.RestoreReport type ContainerCreateReport struct { Id string //nolint:revive,stylecheck @@ -486,13 +473,7 @@ type ContainerStatsOptions struct { Interval int } -// ContainerStatsReport is used for streaming container stats. -type ContainerStatsReport struct { - // Error from reading stats. - Error error - // Results, set when there is no error. - Stats []define.ContainerStats -} +type ContainerStatsReport = types.ContainerStatsReport // ContainerRenameOptions describes input options for renaming a container. type ContainerRenameOptions struct { @@ -512,7 +493,4 @@ type ContainerCloneOptions struct { } // ContainerUpdateOptions containers options for updating an existing containers cgroup configuration -type ContainerUpdateOptions struct { - NameOrID string - Specgen *specgen.SpecGenerator -} +type ContainerUpdateOptions = types.ContainerUpdateOptions diff --git a/pkg/domain/entities/engine_container.go b/pkg/domain/entities/engine_container.go index e697b6011560..7bb037ff1bc6 100644 --- a/pkg/domain/entities/engine_container.go +++ b/pkg/domain/entities/engine_container.go @@ -4,14 +4,15 @@ import ( "context" "io" - "github.com/containers/common/libnetwork/types" + netTypes "github.com/containers/common/libnetwork/types" "github.com/containers/common/pkg/config" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/domain/entities/reports" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/specgen" ) -type ContainerCopyFunc func() error +type ContainerCopyFunc = types.ContainerCopyFunc type ContainerEngine interface { //nolint:interfacebloat AutoUpdate(ctx context.Context, options AutoUpdateOptions) ([]*AutoUpdateReport, []error) @@ -65,12 +66,12 @@ type ContainerEngine interface { //nolint:interfacebloat Locks(ctx context.Context) (*LocksReport, error) Migrate(ctx context.Context, options SystemMigrateOptions) error NetworkConnect(ctx context.Context, networkname string, options NetworkConnectOptions) error - NetworkCreate(ctx context.Context, network types.Network, createOptions *types.NetworkCreateOptions) (*types.Network, error) + NetworkCreate(ctx context.Context, network netTypes.Network, createOptions *netTypes.NetworkCreateOptions) (*netTypes.Network, error) NetworkUpdate(ctx context.Context, networkname string, options NetworkUpdateOptions) error NetworkDisconnect(ctx context.Context, networkname string, options NetworkDisconnectOptions) error NetworkExists(ctx context.Context, networkname string) (*BoolReport, error) - NetworkInspect(ctx context.Context, namesOrIds []string, options InspectOptions) ([]types.Network, []error, error) - NetworkList(ctx context.Context, options NetworkListOptions) ([]types.Network, error) + NetworkInspect(ctx context.Context, namesOrIds []string, options InspectOptions) ([]netTypes.Network, []error, error) + NetworkList(ctx context.Context, options NetworkListOptions) ([]netTypes.Network, error) NetworkPrune(ctx context.Context, options NetworkPruneOptions) ([]*NetworkPruneReport, error) NetworkReload(ctx context.Context, names []string, options NetworkReloadOptions) ([]*NetworkReloadReport, error) NetworkRm(ctx context.Context, namesOrIds []string, options NetworkRmOptions) ([]*NetworkRmReport, error) diff --git a/pkg/domain/entities/events.go b/pkg/domain/entities/events.go index 6e635d78acd0..f1b4e0c90e49 100644 --- a/pkg/domain/entities/events.go +++ b/pkg/domain/entities/events.go @@ -5,17 +5,11 @@ import ( "time" libpodEvents "github.com/containers/podman/v4/libpod/events" + types "github.com/containers/podman/v4/pkg/domain/entities/types" dockerEvents "github.com/docker/docker/api/types/events" ) -// Event combines various event-related data such as time, event type, status -// and more. -type Event struct { - // TODO: it would be nice to have full control over the types at some - // point and fork such Docker types. - dockerEvents.Message - HealthStatus string `json:",omitempty"` -} +type Event = types.Event // ConvertToLibpodEvent converts an entities event to a libpod one. func ConvertToLibpodEvent(e Event) *libpodEvents.Event { @@ -59,7 +53,7 @@ func ConvertToLibpodEvent(e Event) *libpodEvents.Event { } // ConvertToEntitiesEvent converts a libpod event to an entities one. -func ConvertToEntitiesEvent(e libpodEvents.Event) *Event { +func ConvertToEntitiesEvent(e libpodEvents.Event) *types.Event { attributes := e.Details.Attributes if attributes == nil { attributes = make(map[string]string) @@ -85,8 +79,8 @@ func ConvertToEntitiesEvent(e libpodEvents.Event) *Event { Time: e.Time.Unix(), TimeNano: e.Time.UnixNano(), } - return &Event{ - message, - e.HealthStatus, + return &types.Event{ + Message: message, + HealthStatus: e.HealthStatus, } } diff --git a/pkg/domain/entities/generate.go b/pkg/domain/entities/generate.go index e67c5bb8d991..c123187cede1 100644 --- a/pkg/domain/entities/generate.go +++ b/pkg/domain/entities/generate.go @@ -1,6 +1,8 @@ package entities -import "io" +import ( + "github.com/containers/podman/v4/pkg/domain/entities/types" +) // GenerateSystemdOptions control the generation of systemd unit files. type GenerateSystemdOptions struct { @@ -22,10 +24,7 @@ type GenerateSystemdOptions struct { } // GenerateSystemdReport -type GenerateSystemdReport struct { - // Units of the generate process. key = unit name -> value = unit content - Units map[string]string -} +type GenerateSystemdReport = types.GenerateSystemdReport // GenerateKubeOptions control the generation of Kubernetes YAML files. type GenerateKubeOptions struct { @@ -44,16 +43,9 @@ type GenerateKubeOptions struct { type KubeGenerateOptions = GenerateKubeOptions // GenerateKubeReport -// -// FIXME: Podman4.0 should change io.Reader to io.ReaderCloser -type GenerateKubeReport struct { - // Reader - the io.Reader to reader the generated YAML file. - Reader io.Reader -} +type GenerateKubeReport = types.GenerateKubeReport -type GenerateSpecReport struct { - Data []byte -} +type GenerateSpecReport = types.GenerateSpecReport type GenerateSpecOptions struct { ID string diff --git a/pkg/domain/entities/images.go b/pkg/domain/entities/images.go index 45cebb55fbc5..0a4b2340687f 100644 --- a/pkg/domain/entities/images.go +++ b/pkg/domain/entities/images.go @@ -3,15 +3,13 @@ package entities import ( "io" "net/url" - "time" "github.com/containers/common/pkg/config" "github.com/containers/image/v5/manifest" "github.com/containers/image/v5/signature/signer" "github.com/containers/image/v5/types" encconfig "github.com/containers/ocicrypt/config" - "github.com/containers/podman/v4/pkg/inspect" - "github.com/containers/podman/v4/pkg/trust" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/docker/docker/api/types/container" "github.com/opencontainers/go-digest" v1 "github.com/opencontainers/image-spec/specs-go/v1" @@ -54,37 +52,7 @@ func (i *Image) Id() string { //nolint:revive,stylecheck } // swagger:model LibpodImageSummary -type ImageSummary struct { - ID string `json:"Id"` - ParentId string //nolint:revive,stylecheck - RepoTags []string - RepoDigests []string - Created int64 - Size int64 - SharedSize int - VirtualSize int64 - Labels map[string]string - Containers int - ReadOnly bool `json:",omitempty"` - Dangling bool `json:",omitempty"` - - // Podman extensions - Names []string `json:",omitempty"` - Digest string `json:",omitempty"` - History []string `json:",omitempty"` -} - -func (i *ImageSummary) Id() string { //nolint:revive,stylecheck - return i.ID -} - -func (i *ImageSummary) IsReadOnly() bool { - return i.ReadOnly -} - -func (i *ImageSummary) IsDangling() bool { - return i.Dangling -} +type ImageSummary = entitiesTypes.ImageSummary // ImageRemoveOptions can be used to alter image removal. type ImageRemoveOptions struct { @@ -102,30 +70,12 @@ type ImageRemoveOptions struct { // ImageRemoveReport is the response for removing one or more image(s) from storage // and images what was untagged vs actually removed. -type ImageRemoveReport struct { - // Deleted images. - Deleted []string `json:",omitempty"` - // Untagged images. Can be longer than Deleted. - Untagged []string `json:",omitempty"` - // ExitCode describes the exit codes as described in the `podman rmi` - // man page. - ExitCode int -} +type ImageRemoveReport = entitiesTypes.ImageRemoveReport type ImageHistoryOptions struct{} -type ImageHistoryLayer struct { - ID string `json:"id"` - Created time.Time `json:"created,omitempty"` - CreatedBy string `json:",omitempty"` - Tags []string `json:"tags,omitempty"` - Size int64 `json:"size"` - Comment string `json:"comment,omitempty"` -} - -type ImageHistoryReport struct { - Layers []ImageHistoryLayer -} +type ImageHistoryLayer = entitiesTypes.ImageHistoryLayer +type ImageHistoryReport = entitiesTypes.ImageHistoryReport // ImagePullOptions are the arguments for pulling images. type ImagePullOptions struct { @@ -166,16 +116,7 @@ type ImagePullOptions struct { } // ImagePullReport is the response from pulling one or more images. -type ImagePullReport struct { - // Stream used to provide output from c/image - Stream string `json:"stream,omitempty"` - // Error contains text of errors from c/image - Error string `json:"error,omitempty"` - // Images contains the ID's of the images pulled - Images []string `json:"images,omitempty"` - // ID contains image id (retained for backwards compatibility) - ID string `json:"id,omitempty"` -} +type ImagePullReport = entitiesTypes.ImagePullReport // ImagePushOptions are the arguments for pushing images. type ImagePushOptions struct { @@ -261,14 +202,7 @@ type ImagePushReport struct { // ImagePushStream is the response from pushing an image. Only used in the // remote API. -type ImagePushStream struct { - // ManifestDigest is the digest of the manifest of the pushed image. - ManifestDigest string `json:"manifestdigest,omitempty"` - // Stream used to provide push progress - Stream string `json:"stream,omitempty"` - // Error contains text of errors from pushing - Error string `json:"error,omitempty"` -} +type ImagePushStream = entitiesTypes.ImagePushStream // ImageSearchOptions are the arguments for searching images. type ImageSearchOptions struct { @@ -296,22 +230,7 @@ type ImageSearchOptions struct { } // ImageSearchReport is the response from searching images. -type ImageSearchReport struct { - // Index is the image index (e.g., "docker.io" or "quay.io") - Index string - // Name is the canonical name of the image (e.g., "docker.io/library/alpine"). - Name string - // Description of the image. - Description string - // Stars is the number of stars of the image. - Stars int - // Official indicates if it's an official image. - Official string - // Automated indicates if the image was created by an automated build. - Automated string - // Tag is the repository tag - Tag string -} +type ImageSearchReport = entitiesTypes.ImageSearchReport // Image List Options type ImageListOptions struct { @@ -329,9 +248,7 @@ type ImageTagOptions struct{} type ImageUntagOptions struct{} // ImageInspectReport is the data when inspecting an image. -type ImageInspectReport struct { - *inspect.ImageData -} +type ImageInspectReport = entitiesTypes.ImageInspectReport type ImageLoadOptions struct { Input string @@ -339,9 +256,7 @@ type ImageLoadOptions struct { SignaturePolicy string } -type ImageLoadReport struct { - Names []string -} +type ImageLoadReport = entitiesTypes.ImageLoadReport type ImageImportOptions struct { Architecture string @@ -356,9 +271,7 @@ type ImageImportOptions struct { SourceIsURL bool } -type ImageImportReport struct { - Id string //nolint:revive,stylecheck -} +type ImageImportReport = entitiesTypes.ImageImportReport // ImageSaveOptions provide options for saving images. type ImageSaveOptions struct { @@ -413,9 +326,7 @@ type ImageTreeOptions struct { } // ImageTreeReport provides results from ImageEngine.Tree() -type ImageTreeReport struct { - Tree string // TODO: Refactor move presentation work out of server -} +type ImageTreeReport = entitiesTypes.ImageTreeReport // ShowTrustOptions are the cli options for showing trust type ShowTrustOptions struct { @@ -426,12 +337,7 @@ type ShowTrustOptions struct { } // ShowTrustReport describes the results of show trust -type ShowTrustReport struct { - Raw []byte - SystemRegistriesDirPath string - JSONOutput []byte - Policies []*trust.Policy -} +type ShowTrustReport = entitiesTypes.ShowTrustReport // SetTrustOptions describes the CLI options for setting trust type SetTrustOptions struct { @@ -466,18 +372,10 @@ type ImageUnmountOptions struct { } // ImageMountReport describes the response from image mount -type ImageMountReport struct { - Id string //nolint:revive,stylecheck - Name string - Repositories []string - Path string -} +type ImageMountReport = entitiesTypes.ImageMountReport // ImageUnmountReport describes the response from umounting an image -type ImageUnmountReport struct { - Err error - Id string //nolint:revive,stylecheck -} +type ImageUnmountReport = entitiesTypes.ImageUnmountReport const ( LocalFarmImageBuilderName = "(local)" @@ -485,10 +383,4 @@ const ( ) // FarmInspectReport describes the response from farm inspect -type FarmInspectReport struct { - NativePlatforms []string - EmulatedPlatforms []string - OS string - Arch string - Variant string -} +type FarmInspectReport = entitiesTypes.FarmInspectReport diff --git a/pkg/domain/entities/manifest.go b/pkg/domain/entities/manifest.go index 819266980a22..22d83a80c00d 100644 --- a/pkg/domain/entities/manifest.go +++ b/pkg/domain/entities/manifest.go @@ -1,6 +1,9 @@ package entities -import "github.com/containers/image/v5/types" +import ( + "github.com/containers/image/v5/types" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" +) // ManifestCreateOptions provides model for creating manifest type ManifestCreateOptions struct { @@ -79,14 +82,7 @@ type ManifestModifyOptions struct { // ManifestPushReport provides the model for the pushed manifest // // swagger:model -type ManifestPushReport struct { - // ID of the pushed manifest - ID string `json:"Id"` - // Stream used to provide push progress - Stream string `json:"stream,omitempty"` - // Error contains text of errors from pushing - Error string `json:"error,omitempty"` -} +type ManifestPushReport = entitiesTypes.ManifestPushReport // ManifestRemoveOptions provides the model for removing digests from a manifest // @@ -97,26 +93,9 @@ type ManifestRemoveOptions struct { // ManifestRemoveReport provides the model for the removed manifest // // swagger:model -type ManifestRemoveReport struct { - // Deleted manifest list. - Deleted []string `json:",omitempty"` - // Untagged images. Can be longer than Deleted. - Untagged []string `json:",omitempty"` - // Errors associated with operation - Errors []string `json:",omitempty"` - // ExitCode describes the exit codes as described in the `podman rmi` - // man page. - ExitCode int -} +type ManifestRemoveReport = entitiesTypes.ManifestRemoveReport // ManifestModifyReport provides the model for removed digests and changed manifest // // swagger:model -type ManifestModifyReport struct { - // Manifest List ID - ID string `json:"Id"` - // Images to removed from manifest list, otherwise not provided. - Images []string `json:"images,omitempty" schema:"images"` - // Errors associated with operation - Errors []error `json:"errors,omitempty"` -} +type ManifestModifyReport = entitiesTypes.ManifestModifyReport diff --git a/pkg/domain/entities/network.go b/pkg/domain/entities/network.go index 66420b25e9ee..d5774ba972aa 100644 --- a/pkg/domain/entities/network.go +++ b/pkg/domain/entities/network.go @@ -3,7 +3,7 @@ package entities import ( "net" - "github.com/containers/common/libnetwork/types" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" ) // NetworkListOptions describes options for listing networks in cli @@ -21,11 +21,7 @@ type NetworkReloadOptions struct { } // NetworkReloadReport describes the results of reloading a container network. -type NetworkReloadReport struct { - //nolint:stylecheck,revive - Id string - Err error -} +type NetworkReloadReport = entitiesTypes.NetworkReloadReport // NetworkRmOptions describes options for removing networks type NetworkRmOptions struct { @@ -34,10 +30,7 @@ type NetworkRmOptions struct { } // NetworkRmReport describes the results of network removal -type NetworkRmReport struct { - Name string - Err error -} +type NetworkRmReport = entitiesTypes.NetworkRmReport // NetworkCreateOptions describes options to create a network type NetworkCreateOptions struct { @@ -67,9 +60,7 @@ type NetworkUpdateOptions struct { } // NetworkCreateReport describes a created network for the cli -type NetworkCreateReport struct { - Name string -} +type NetworkCreateReport = entitiesTypes.NetworkCreateReport // NetworkDisconnectOptions describes options for disconnecting // containers from networks @@ -80,18 +71,12 @@ type NetworkDisconnectOptions struct { // NetworkConnectOptions describes options for connecting // a container to a network -type NetworkConnectOptions struct { - Container string `json:"container"` - types.PerNetworkOptions -} +type NetworkConnectOptions = entitiesTypes.NetworkConnectOptions // NetworkPruneReport containers the name of network and an error // associated in its pruning (removal) // swagger:model NetworkPruneReport -type NetworkPruneReport struct { - Name string - Error error -} +type NetworkPruneReport = entitiesTypes.NetworkPruneReport // NetworkPruneOptions describes options for pruning unused networks type NetworkPruneOptions struct { diff --git a/pkg/domain/entities/play.go b/pkg/domain/entities/play.go index 94d4247d89cf..e837608c7a09 100644 --- a/pkg/domain/entities/play.go +++ b/pkg/domain/entities/play.go @@ -4,6 +4,7 @@ import ( "net" "github.com/containers/image/v5/types" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" ) // PlayKubeOptions controls playing kube YAML files. @@ -80,42 +81,14 @@ type PlayKubeOptions struct { } // PlayKubePod represents a single pod and associated containers created by play kube -type PlayKubePod struct { - // ID - ID of the pod created as a result of play kube. - ID string - // Containers - the IDs of the containers running in the created pod. - Containers []string - // InitContainers - the IDs of the init containers to be run in the created pod. - InitContainers []string - // Logs - non-fatal errors and log messages while processing. - Logs []string - // ContainerErrors - any errors that occurred while starting containers - // in the pod. - ContainerErrors []string -} +type PlayKubePod = entitiesTypes.PlayKubePod // PlayKubeVolume represents a single volume created by play kube. -type PlayKubeVolume struct { - // Name - Name of the volume created by play kube. - Name string -} +type PlayKubeVolume entitiesTypes.PlayKubeVolume // PlayKubeReport contains the results of running play kube. -type PlayKubeReport struct { - // Pods - pods created by play kube. - Pods []PlayKubePod - // Volumes - volumes created by play kube. - Volumes []PlayKubeVolume - PlayKubeTeardown - // Secrets - secrets created by play kube - Secrets []PlaySecret - // ServiceContainerID - ID of the service container if one is created - ServiceContainerID string - // If set, exit with the specified exit code. - ExitCode *int32 -} - -type KubePlayReport = PlayKubeReport +type PlayKubeReport = entitiesTypes.PlayKubeReport +type KubePlayReport = entitiesTypes.KubePlayReport // PlayKubeDownOptions are options for tearing down pods type PlayKubeDownOptions struct { @@ -124,13 +97,6 @@ type PlayKubeDownOptions struct { } // PlayKubeDownReport contains the results of tearing down play kube -type PlayKubeTeardown struct { - StopReport []*PodStopReport - RmReport []*PodRmReport - VolumeRmReport []*VolumeRmReport - SecretRmReport []*SecretRmReport -} +type PlayKubeTeardown = entitiesTypes.PlayKubeTeardown -type PlaySecret struct { - CreateReport *SecretCreateReport -} +type PlaySecret = entitiesTypes.PlaySecret diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go index d57dedee40b3..2d26b082607c 100644 --- a/pkg/domain/entities/pods.go +++ b/pkg/domain/entities/pods.go @@ -3,10 +3,10 @@ package entities import ( "errors" "strings" - "time" commonFlag "github.com/containers/common/pkg/flag" "github.com/containers/podman/v4/libpod/define" + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/specgen" "github.com/containers/podman/v4/pkg/util" "github.com/opencontainers/runtime-spec/specs-go" @@ -18,51 +18,25 @@ type PodKillOptions struct { Signal string } -type PodKillReport struct { - Errs []error - Id string //nolint:revive,stylecheck -} +type PodKillReport = types.PodKillReport -type ListPodsReport struct { - Cgroup string - Containers []*ListPodContainer - Created time.Time - Id string //nolint:revive,stylecheck - InfraId string //nolint:revive,stylecheck - Name string - Namespace string - // Network names connected to infra container - Networks []string - Status string - Labels map[string]string -} +type ListPodsReport = types.ListPodsReport -type ListPodContainer struct { - Id string //nolint:revive,stylecheck - Names string - Status string - RestartCount uint -} +type ListPodContainer = types.ListPodContainer type PodPauseOptions struct { All bool Latest bool } -type PodPauseReport struct { - Errs []error - Id string //nolint:revive,stylecheck -} +type PodPauseReport = types.PodPauseReport type PodunpauseOptions struct { All bool Latest bool } -type PodUnpauseReport struct { - Errs []error - Id string //nolint:revive,stylecheck -} +type PodUnpauseReport = types.PodUnpauseReport type PodStopOptions struct { All bool @@ -71,30 +45,20 @@ type PodStopOptions struct { Timeout int } -type PodStopReport struct { - Errs []error - Id string //nolint:revive,stylecheck -} +type PodStopReport = types.PodStopReport type PodRestartOptions struct { All bool Latest bool } -type PodRestartReport struct { - Errs []error - Id string //nolint:revive,stylecheck -} - +type PodRestartReport = types.PodRestartReport type PodStartOptions struct { All bool Latest bool } -type PodStartReport struct { - Errs []error - Id string //nolint:revive,stylecheck -} +type PodStartReport = types.PodStartReport type PodRmOptions struct { All bool @@ -104,17 +68,9 @@ type PodRmOptions struct { Timeout *uint } -type PodRmReport struct { - RemovedCtrs map[string]error - Err error - Id string //nolint:revive,stylecheck -} +type PodRmReport = types.PodRmReport -// PddSpec is an abstracted version of PodSpecGen designed to eventually accept options -// not meant to be in a specgen -type PodSpec struct { - PodSpecGen specgen.PodSpecGenerator -} +type PodSpec = types.PodSpec // PodCreateOptions provides all possible options for creating a pod and its infra container. // The JSON tags below are made to match the respective field in ContainerCreateOptions for the purpose of mapping. @@ -321,13 +277,9 @@ func NewInfraContainerCreateOptions() ContainerCreateOptions { return options } -type PodCreateReport struct { - Id string //nolint:revive,stylecheck -} +type PodCreateReport = types.PodCreateReport -type PodCloneReport struct { - Id string //nolint:revive,stylecheck -} +type PodCloneReport = types.PodCloneReport func (p *PodCreateOptions) CPULimits() *specs.LinuxCPU { cpu := &specs.LinuxCPU{} @@ -446,10 +398,7 @@ type PodPruneOptions struct { Force bool `json:"force" schema:"force"` } -type PodPruneReport struct { - Err error - Id string //nolint:revive,stylecheck -} +type PodPruneReport = types.PodPruneReport type PodTopOptions struct { // CLI flags. @@ -473,9 +422,7 @@ type PodPSOptions struct { Sort string } -type PodInspectReport struct { - *define.InspectPodData -} +type PodInspectReport = types.PodInspectReport // PodStatsOptions are options for the pod stats command. type PodStatsOptions struct { @@ -486,35 +433,7 @@ type PodStatsOptions struct { } // PodStatsReport includes pod-resource statistics data. -type PodStatsReport struct { - // Percentage of CPU utilized by pod - // example: 75.5% - CPU string - // Humanized Memory usage and maximum - // example: 12mb / 24mb - MemUsage string - // Memory usage and maximum in bytes - // example: 1,000,000 / 4,000,000 - MemUsageBytes string - // Percentage of Memory utilized by pod - // example: 50.5% - Mem string - // Network usage inbound + outbound - NetIO string - // Humanized disk usage read + write - BlockIO string - // Container PID - PIDS string - // Pod ID - // example: 62310217a19e - Pod string - // Container ID - // example: e43534f89a7d - CID string - // Pod Name - // example: elastic_pascal - Name string -} +type PodStatsReport = types.PodStatsReport // ValidatePodStatsOptions validates the specified slice and options. Allows // for sharing code in the front- and the back-end. diff --git a/pkg/domain/entities/secrets.go b/pkg/domain/entities/secrets.go index ce3fac8d8e9b..45936ded9f2d 100644 --- a/pkg/domain/entities/secrets.go +++ b/pkg/domain/entities/secrets.go @@ -1,14 +1,11 @@ package entities import ( - "time" - + "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/errorhandling" ) -type SecretCreateReport struct { - ID string -} +type SecretCreateReport = types.SecretCreateReport type SecretCreateOptions struct { Driver string @@ -25,51 +22,24 @@ type SecretListRequest struct { Filters map[string][]string } -type SecretListReport struct { - ID string - Name string - Driver string - CreatedAt string - UpdatedAt string -} +type SecretListReport = types.SecretListReport type SecretRmOptions struct { All bool Ignore bool } -type SecretRmReport struct { - ID string - Err error -} +type SecretRmReport = types.SecretRmReport -type SecretInfoReport struct { - ID string - CreatedAt time.Time - UpdatedAt time.Time - Spec SecretSpec - SecretData string `json:"SecretData,omitempty"` -} +type SecretInfoReport = types.SecretInfoReport -type SecretInfoReportCompat struct { - SecretInfoReport - Version SecretVersion -} +type SecretInfoReportCompat = types.SecretInfoReportCompat -type SecretVersion struct { - Index int -} +type SecretVersion = types.SecretVersion -type SecretSpec struct { - Name string - Driver SecretDriverSpec - Labels map[string]string -} +type SecretSpec = types.SecretSpec -type SecretDriverSpec struct { - Name string - Options map[string]string -} +type SecretDriverSpec = types.SecretDriverSpec // swagger:model SecretCreate type SecretCreateRequest struct { diff --git a/pkg/domain/entities/system.go b/pkg/domain/entities/system.go index 473db3530633..685b3125d4c3 100644 --- a/pkg/domain/entities/system.go +++ b/pkg/domain/entities/system.go @@ -1,129 +1,25 @@ package entities import ( - "time" - - "github.com/containers/podman/v4/libpod/define" - "github.com/containers/podman/v4/pkg/domain/entities/reports" "github.com/containers/podman/v4/pkg/domain/entities/types" ) // ServiceOptions provides the input for starting an API and sidecar pprof services -type ServiceOptions struct { - CorsHeaders string // Cross-Origin Resource Sharing (CORS) headers - PProfAddr string // Network address to bind pprof profiles service - Timeout time.Duration // Duration of inactivity the service should wait before shutting down - URI string // Path to unix domain socket service should listen on -} - -// SystemPruneOptions provides options to prune system. -type SystemPruneOptions struct { - All bool - Volume bool - Filters map[string][]string `json:"filters" schema:"filters"` - External bool -} - -// SystemPruneReport provides report after system prune is executed. -type SystemPruneReport struct { - PodPruneReport []*PodPruneReport - ContainerPruneReports []*reports.PruneReport - ImagePruneReports []*reports.PruneReport - NetworkPruneReports []*NetworkPruneReport - VolumePruneReports []*reports.PruneReport - ReclaimedSpace uint64 -} - -// SystemMigrateOptions describes the options needed for the -// cli to migrate runtimes of containers -type SystemMigrateOptions struct { - NewRuntime string -} - -// SystemDfOptions describes the options for getting df information -type SystemDfOptions struct { - Format string - Verbose bool -} - -// SystemDfReport describes the response for df information -type SystemDfReport struct { - ImagesSize int64 - Images []*SystemDfImageReport - Containers []*SystemDfContainerReport - Volumes []*SystemDfVolumeReport -} - -// SystemDfImageReport describes an image for use with df -type SystemDfImageReport struct { - Repository string - Tag string - ImageID string - Created time.Time - Size int64 - SharedSize int64 - UniqueSize int64 - Containers int -} - -// SystemDfContainerReport describes a container for use with df -type SystemDfContainerReport struct { - ContainerID string - Image string - Command []string - LocalVolumes int - Size int64 - RWSize int64 - Created time.Time - Status string - Names string -} - -// SystemDfVolumeReport describes a volume and its size -type SystemDfVolumeReport struct { - VolumeName string - Links int - Size int64 - ReclaimableSize int64 -} - -// SystemVersionReport describes version information about the running Podman service -type SystemVersionReport struct { - // Always populated - Client *define.Version `json:",omitempty"` - // May be populated, when in tunnel mode - Server *define.Version `json:",omitempty"` -} - -// SystemUnshareOptions describes the options for the unshare command -type SystemUnshareOptions struct { - RootlessNetNS bool -} - -type ComponentVersion struct { - types.Version -} - -// ListRegistriesReport is the report when querying for a sorted list of -// registries which may be contacted during certain operations. -type ListRegistriesReport struct { - Registries []string -} +type ServiceOptions = types.ServiceOptions +type SystemPruneOptions = types.SystemPruneOptions +type SystemPruneReport = types.SystemPruneReport +type SystemMigrateOptions = types.SystemMigrateOptions +type SystemDfOptions = types.SystemDfOptions +type SystemDfReport = types.SystemDfReport +type SystemDfImageReport = types.SystemDfImageReport +type SystemDfContainerReport = types.SystemDfContainerReport +type SystemDfVolumeReport = types.SystemDfVolumeReport +type SystemVersionReport = types.SystemVersionReport +type SystemUnshareOptions = types.SystemUnshareOptions +type ComponentVersion = types.SystemComponentVersion +type ListRegistriesReport = types.ListRegistriesReport // swagger:model AuthConfig -type AuthConfig struct { - types.AuthConfig -} - -// AuthReport describes the response for authentication check -type AuthReport struct { - IdentityToken string - Status string -} - -// LocksReport describes any conflicts in Libpod's lock allocations that could -// lead to deadlocks. -type LocksReport struct { - LockConflicts map[uint32][]string - LocksHeld []uint32 -} +type AuthConfig = types.AuthConfig +type AuthReport = types.AuthReport +type LocksReport = types.LocksReport diff --git a/pkg/domain/entities/types.go b/pkg/domain/entities/types.go index 6cf354a831e2..99cd33a9c0ac 100644 --- a/pkg/domain/entities/types.go +++ b/pkg/domain/entities/types.go @@ -2,12 +2,11 @@ package entities import ( "net" - "os" - buildahDefine "github.com/containers/buildah/define" "github.com/containers/common/libnetwork/types" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/libpod/events" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" "github.com/containers/podman/v4/pkg/specgen" "github.com/containers/storage/pkg/archive" dockerAPI "github.com/docker/docker/api/types" @@ -99,43 +98,16 @@ type EventsOptions struct { } // ContainerCreateResponse is the response struct for creating a container -type ContainerCreateResponse struct { - // ID of the container created - // required: true - ID string `json:"Id"` - // Warnings during container creation - // required: true - Warnings []string `json:"Warnings"` -} +type ContainerCreateResponse = entitiesTypes.ContainerCreateResponse // BuildOptions describe the options for building container images. -type BuildOptions struct { - buildahDefine.BuildOptions - ContainerFiles []string - FarmBuildOptions - // Files that need to be closed after the build - // so need to pass this to the main build functions - LogFileToClose *os.File - TmpDirToClose string -} +type BuildOptions = entitiesTypes.BuildOptions // BuildReport is the image-build report. -type BuildReport struct { - // ID of the image. - ID string - // Format to save the image in - SaveFormat string -} +type BuildReport = entitiesTypes.BuildReport // FarmBuildOptions describes the options for building container images on farm nodes -type FarmBuildOptions struct { - // Cleanup removes built images from farm nodes on success - Cleanup bool - // Authfile is the path to the file holding registry credentials - Authfile string - // SkipTLSVerify skips tls verification when set to true - SkipTLSVerify bool -} +type FarmBuildOptions = entitiesTypes.FarmBuildOptions type IDOrNameResponse struct { // The Id or Name of an object diff --git a/pkg/domain/entities/types/container_ps.go b/pkg/domain/entities/types/container_ps.go new file mode 100644 index 000000000000..f1430b1c5144 --- /dev/null +++ b/pkg/domain/entities/types/container_ps.go @@ -0,0 +1,115 @@ +package types + +import ( + "time" + + netTypes "github.com/containers/common/libnetwork/types" + define "github.com/containers/podman/v4/pkg/ps/define" +) + +// ListContainer describes a container suitable for listing +type ListContainer struct { + // AutoRemove + AutoRemove bool + // Container command + Command []string + // Container creation time + Created time.Time + // Human-readable container creation time. + CreatedAt string + // CIDFile specified at creation time. + CIDFile string + // If container has exited/stopped + Exited bool + // Time container exited + ExitedAt int64 + // If container has exited, the return code from the command + ExitCode int32 + // The unique identifier for the container + ID string `json:"Id"` + // Container image + Image string + // Container image ID + ImageID string + // If this container is a Pod infra container + IsInfra bool + // Labels for container + Labels map[string]string + // User volume mounts + Mounts []string + // The names assigned to the container + Names []string + // Namespaces the container belongs to. Requires the + // namespace boolean to be true + Namespaces ListContainerNamespaces + // The network names assigned to the container + Networks []string + // The process id of the container + Pid int + // If the container is part of Pod, the Pod ID. Requires the pod + // boolean to be set + Pod string + // If the container is part of Pod, the Pod name. Requires the pod + // boolean to be set + PodName string + // Port mappings + Ports []netTypes.PortMapping + // Restarts is how many times the container was restarted by its + // restart policy. This is NOT incremented by normal container restarts + // (only by restart policy). + Restarts uint + // Size of the container rootfs. Requires the size boolean to be true + Size *define.ContainerSize + // Time when container started + StartedAt int64 + // State of container + State string + // Status is a human-readable approximation of a duration for json output + Status string +} + +// ListContainerNamespaces contains the identifiers of the container's Linux namespaces +type ListContainerNamespaces struct { + // Mount namespace + MNT string `json:"Mnt,omitempty"` + // Cgroup namespace + Cgroup string `json:"Cgroup,omitempty"` + // IPC namespace + IPC string `json:"Ipc,omitempty"` + // Network namespace + NET string `json:"Net,omitempty"` + // PID namespace + PIDNS string `json:"Pidns,omitempty"` + // UTS namespace + UTS string `json:"Uts,omitempty"` + // User namespace + User string `json:"User,omitempty"` +} + +func (l ListContainer) CGROUPNS() string { + return l.Namespaces.Cgroup +} + +func (l ListContainer) IPC() string { + return l.Namespaces.IPC +} + +func (l ListContainer) MNT() string { + return l.Namespaces.MNT +} + +func (l ListContainer) NET() string { + return l.Namespaces.NET +} + +func (l ListContainer) PIDNS() string { + return l.Namespaces.PIDNS +} + +func (l ListContainer) USERNS() string { + return l.Namespaces.User +} + +func (l ListContainer) UTS() string { + return l.Namespaces.UTS +} diff --git a/pkg/domain/entities/types/containers.go b/pkg/domain/entities/types/containers.go new file mode 100644 index 000000000000..fa4c042920e6 --- /dev/null +++ b/pkg/domain/entities/types/containers.go @@ -0,0 +1,41 @@ +package types + +import ( + "github.com/containers/podman/v4/libpod/define" + "github.com/containers/podman/v4/pkg/specgen" +) + +type ContainerCopyFunc func() error + +type ContainerStatReport struct { + define.FileInfo +} + +type CheckpointReport struct { + Err error `json:"-"` + Id string `json:"Id"` //nolint:revive,stylecheck + RawInput string `json:"-"` + RuntimeDuration int64 `json:"runtime_checkpoint_duration"` + CRIUStatistics *define.CRIUCheckpointRestoreStatistics `json:"criu_statistics"` +} + +type RestoreReport struct { + Err error `json:"-"` + Id string `json:"Id"` //nolint:revive,stylecheck + RawInput string `json:"-"` + RuntimeDuration int64 `json:"runtime_restore_duration"` + CRIUStatistics *define.CRIUCheckpointRestoreStatistics `json:"criu_statistics"` +} + +// ContainerStatsReport is used for streaming container stats. +type ContainerStatsReport struct { + // Error from reading stats. + Error error + // Results, set when there is no error. + Stats []define.ContainerStats +} + +type ContainerUpdateOptions struct { + NameOrID string + Specgen *specgen.SpecGenerator +} diff --git a/pkg/domain/entities/types/events.go b/pkg/domain/entities/types/events.go new file mode 100644 index 000000000000..a9e9dd6a1be4 --- /dev/null +++ b/pkg/domain/entities/types/events.go @@ -0,0 +1,14 @@ +package types + +import ( + dockerEvents "github.com/docker/docker/api/types/events" +) + +// Event combines various event-related data such as time, event type, status +// and more. +type Event struct { + // TODO: it would be nice to have full control over the types at some + // point and fork such Docker types. + dockerEvents.Message + HealthStatus string `json:",omitempty"` +} diff --git a/pkg/domain/entities/types/generate.go b/pkg/domain/entities/types/generate.go new file mode 100644 index 000000000000..45d4241a63fa --- /dev/null +++ b/pkg/domain/entities/types/generate.go @@ -0,0 +1,20 @@ +package types + +import ( + "io" +) + +type GenerateSystemdReport struct { + // Units of the generate process. key = unit name -> value = unit content + Units map[string]string +} + +type GenerateKubeReport struct { + // FIXME: Podman4.0 should change io.Reader to io.ReaderCloser + // Reader - the io.Reader to reader the generated YAML file. + Reader io.Reader +} + +type GenerateSpecReport struct { + Data []byte +} diff --git a/pkg/domain/entities/types/images.go b/pkg/domain/entities/types/images.go new file mode 100644 index 000000000000..1c012f70075f --- /dev/null +++ b/pkg/domain/entities/types/images.go @@ -0,0 +1,151 @@ +package types + +import ( + "time" + + "github.com/containers/podman/v4/pkg/inspect" + "github.com/containers/podman/v4/pkg/trust" +) + +// swagger:model LibpodImageSummary +type ImageSummary struct { + ID string `json:"Id"` + ParentId string //nolint:revive,stylecheck + RepoTags []string + RepoDigests []string + Created int64 + Size int64 + SharedSize int + VirtualSize int64 + Labels map[string]string + Containers int + ReadOnly bool `json:",omitempty"` + Dangling bool `json:",omitempty"` + + // Podman extensions + Names []string `json:",omitempty"` + Digest string `json:",omitempty"` + History []string `json:",omitempty"` +} + +func (i *ImageSummary) Id() string { //nolint:revive,stylecheck + return i.ID +} + +func (i *ImageSummary) IsReadOnly() bool { + return i.ReadOnly +} + +func (i *ImageSummary) IsDangling() bool { + return i.Dangling +} + +type ImageInspectReport struct { + *inspect.ImageData +} + +type ImageTreeReport struct { + Tree string // TODO: Refactor move presentation work out of server +} + +type ImageLoadReport struct { + Names []string +} + +type ImageImportReport struct { + Id string //nolint:revive,stylecheck +} + +// ImageSearchReport is the response from searching images. +type ImageSearchReport struct { + // Index is the image index (e.g., "docker.io" or "quay.io") + Index string + // Name is the canonical name of the image (e.g., "docker.io/library/alpine"). + Name string + // Description of the image. + Description string + // Stars is the number of stars of the image. + Stars int + // Official indicates if it's an official image. + Official string + // Automated indicates if the image was created by an automated build. + Automated string + // Tag is the repository tag + Tag string +} + +// ShowTrustReport describes the results of show trust +type ShowTrustReport struct { + Raw []byte + SystemRegistriesDirPath string + JSONOutput []byte + Policies []*trust.Policy +} + +// ImageMountReport describes the response from image mount +type ImageMountReport struct { + Id string //nolint:revive,stylecheck + Name string + Repositories []string + Path string +} + +// ImageUnmountReport describes the response from umounting an image +type ImageUnmountReport struct { + Err error + Id string //nolint:revive,stylecheck +} + +// FarmInspectReport describes the response from farm inspect +type FarmInspectReport struct { + NativePlatforms []string + EmulatedPlatforms []string + OS string + Arch string + Variant string +} + +// ImageRemoveReport is the response for removing one or more image(s) from storage +// and images what was untagged vs actually removed. +type ImageRemoveReport struct { + // Deleted images. + Deleted []string `json:",omitempty"` + // Untagged images. Can be longer than Deleted. + Untagged []string `json:",omitempty"` + // ExitCode describes the exit codes as described in the `podman rmi` + // man page. + ExitCode int +} + +type ImageHistoryLayer struct { + ID string `json:"id"` + Created time.Time `json:"created,omitempty"` + CreatedBy string `json:",omitempty"` + Tags []string `json:"tags,omitempty"` + Size int64 `json:"size"` + Comment string `json:"comment,omitempty"` +} + +type ImageHistoryReport struct { + Layers []ImageHistoryLayer +} + +type ImagePullReport struct { + // Stream used to provide output from c/image + Stream string `json:"stream,omitempty"` + // Error contains text of errors from c/image + Error string `json:"error,omitempty"` + // Images contains the ID's of the images pulled + Images []string `json:"images,omitempty"` + // ID contains image id (retained for backwards compatibility) + ID string `json:"id,omitempty"` +} + +type ImagePushStream struct { + // ManifestDigest is the digest of the manifest of the pushed image. + ManifestDigest string `json:"manifestdigest,omitempty"` + // Stream used to provide push progress + Stream string `json:"stream,omitempty"` + // Error contains text of errors from pushing + Error string `json:"error,omitempty"` +} diff --git a/pkg/domain/entities/types/manifest.go b/pkg/domain/entities/types/manifest.go new file mode 100644 index 000000000000..941c3265ef3a --- /dev/null +++ b/pkg/domain/entities/types/manifest.go @@ -0,0 +1,34 @@ +package types + +// swagger:model +type ManifestPushReport struct { + // ID of the pushed manifest + ID string `json:"Id"` + // Stream used to provide push progress + Stream string `json:"stream,omitempty"` + // Error contains text of errors from pushing + Error string `json:"error,omitempty"` +} + +// swagger:model +type ManifestModifyReport struct { + // Manifest List ID + ID string `json:"Id"` + // Images to removed from manifest list, otherwise not provided. + Images []string `json:"images,omitempty" schema:"images"` + // Errors associated with operation + Errors []error `json:"errors,omitempty"` +} + +// swagger:model +type ManifestRemoveReport struct { + // Deleted manifest list. + Deleted []string `json:",omitempty"` + // Untagged images. Can be longer than Deleted. + Untagged []string `json:",omitempty"` + // Errors associated with operation + Errors []string `json:",omitempty"` + // ExitCode describes the exit codes as described in the `podman rmi` + // man page. + ExitCode int +} diff --git a/pkg/domain/entities/types/network.go b/pkg/domain/entities/types/network.go new file mode 100644 index 000000000000..8c547ee94da4 --- /dev/null +++ b/pkg/domain/entities/types/network.go @@ -0,0 +1,37 @@ +package types + +import ( + commonTypes "github.com/containers/common/libnetwork/types" +) + +// NetworkPruneReport containers the name of network and an error +// associated in its pruning (removal) +// swagger:model NetworkPruneReport +type NetworkPruneReport struct { + Name string + Error error +} + +// NetworkReloadReport describes the results of reloading a container network. +type NetworkReloadReport struct { + //nolint:stylecheck,revive + Id string + Err error +} + +// NetworkConnectOptions describes options for connecting +// a container to a network +type NetworkConnectOptions struct { + Container string `json:"container"` + commonTypes.PerNetworkOptions +} + +// NetworkRmReport describes the results of network removal +type NetworkRmReport struct { + Name string + Err error +} + +type NetworkCreateReport struct { + Name string +} diff --git a/pkg/domain/entities/types/play.go b/pkg/domain/entities/types/play.go new file mode 100644 index 000000000000..7f744106c346 --- /dev/null +++ b/pkg/domain/entities/types/play.go @@ -0,0 +1,48 @@ +package types + +type PlayKubePod struct { + // ID - ID of the pod created as a result of play kube. + ID string + // Containers - the IDs of the containers running in the created pod. + Containers []string + // InitContainers - the IDs of the init containers to be run in the created pod. + InitContainers []string + // Logs - non-fatal errors and log messages while processing. + Logs []string + // ContainerErrors - any errors that occurred while starting containers + // in the pod. + ContainerErrors []string +} + +type PlayKubeVolume struct { + // Name - Name of the volume created by play kube. + Name string +} + +type PlayKubeReport struct { + // Pods - pods created by play kube. + Pods []PlayKubePod + // Volumes - volumes created by play kube. + Volumes []PlayKubeVolume + PlayKubeTeardown + // Secrets - secrets created by play kube + Secrets []PlaySecret + // ServiceContainerID - ID of the service container if one is created + ServiceContainerID string + // If set, exit with the specified exit code. + ExitCode *int32 +} + +type KubePlayReport = PlayKubeReport + +// PlayKubeDownReport contains the results of tearing down play kube +type PlayKubeTeardown struct { + StopReport []*PodStopReport + RmReport []*PodRmReport + VolumeRmReport []*VolumeRmReport + SecretRmReport []*SecretRmReport +} + +type PlaySecret struct { + CreateReport *SecretCreateReport +} diff --git a/pkg/domain/entities/types/pods.go b/pkg/domain/entities/types/pods.go new file mode 100644 index 000000000000..c4d6cb91b16b --- /dev/null +++ b/pkg/domain/entities/types/pods.go @@ -0,0 +1,118 @@ +package types + +import ( + "time" + + "github.com/containers/podman/v4/libpod/define" + "github.com/containers/podman/v4/pkg/specgen" +) + +type PodPruneReport struct { + Err error + Id string //nolint:revive,stylecheck +} + +type PodPauseReport struct { + Errs []error + Id string //nolint:revive,stylecheck +} +type PodUnpauseReport struct { + Errs []error + Id string //nolint:revive,stylecheck +} + +type PodStopReport struct { + Errs []error + Id string //nolint:revive,stylecheck +} + +type PodRestartReport struct { + Errs []error + Id string //nolint:revive,stylecheck +} + +type PodStartReport struct { + Errs []error + Id string //nolint:revive,stylecheck +} + +type PodRmReport struct { + RemovedCtrs map[string]error + Err error + Id string //nolint:revive,stylecheck +} + +type PodCreateReport struct { + Id string //nolint:revive,stylecheck +} + +type PodCloneReport struct { + Id string //nolint:revive,stylecheck +} + +// PodStatsReport includes pod-resource statistics data. +type PodStatsReport struct { + // Percentage of CPU utilized by pod + // example: 75.5% + CPU string + // Humanized Memory usage and maximum + // example: 12mb / 24mb + MemUsage string + // Memory usage and maximum in bytes + // example: 1,000,000 / 4,000,000 + MemUsageBytes string + // Percentage of Memory utilized by pod + // example: 50.5% + Mem string + // Network usage inbound + outbound + NetIO string + // Humanized disk usage read + write + BlockIO string + // Container PID + PIDS string + // Pod ID + // example: 62310217a19e + Pod string + // Container ID + // example: e43534f89a7d + CID string + // Pod Name + // example: elastic_pascal + Name string +} + +// PodSpec is an abstracted version of PodSpecGen designed to eventually accept options +// not meant to be in a specgen +type PodSpec struct { + PodSpecGen specgen.PodSpecGenerator +} + +type PodInspectReport struct { + *define.InspectPodData +} + +type PodKillReport struct { + Errs []error + Id string //nolint:revive,stylecheck +} + +type ListPodsReport struct { + Cgroup string + Containers []*ListPodContainer + Created time.Time + Id string //nolint:revive,stylecheck + InfraId string //nolint:revive,stylecheck + Name string + Namespace string + // Network names connected to infra container + Networks []string + Status string + Labels map[string]string +} + +type ListPodContainer struct { + Id string //nolint:revive,stylecheck + Names string + Status string + RestartCount uint +} diff --git a/pkg/domain/entities/types/secrets.go b/pkg/domain/entities/types/secrets.go new file mode 100644 index 000000000000..0ba544db7281 --- /dev/null +++ b/pkg/domain/entities/types/secrets.go @@ -0,0 +1,50 @@ +package types + +import ( + "time" +) + +type SecretSpec struct { + Name string + Driver SecretDriverSpec + Labels map[string]string +} + +type SecretVersion struct { + Index int +} + +type SecretDriverSpec struct { + Name string + Options map[string]string +} + +type SecretCreateReport struct { + ID string +} + +type SecretListReport struct { + ID string + Name string + Driver string + CreatedAt string + UpdatedAt string +} + +type SecretRmReport struct { + ID string + Err error +} + +type SecretInfoReport struct { + ID string + CreatedAt time.Time + UpdatedAt time.Time + Spec SecretSpec + SecretData string `json:"SecretData,omitempty"` +} + +type SecretInfoReportCompat struct { + SecretInfoReport + Version SecretVersion +} diff --git a/pkg/domain/entities/types/system.go b/pkg/domain/entities/types/system.go new file mode 100644 index 000000000000..3100370052a5 --- /dev/null +++ b/pkg/domain/entities/types/system.go @@ -0,0 +1,119 @@ +package types + +import ( + "time" + + "github.com/containers/podman/v4/libpod/define" + "github.com/containers/podman/v4/pkg/domain/entities/reports" +) + +// ServiceOptions provides the input for starting an API and sidecar pprof services +type ServiceOptions struct { + CorsHeaders string // Cross-Origin Resource Sharing (CORS) headers + PProfAddr string // Network address to bind pprof profiles service + Timeout time.Duration // Duration of inactivity the service should wait before shutting down + URI string // Path to unix domain socket service should listen on +} + +// SystemPruneOptions provides options to prune system. +type SystemPruneOptions struct { + All bool + Volume bool + Filters map[string][]string `json:"filters" schema:"filters"` + External bool +} + +// SystemPruneReport provides report after system prune is executed. +type SystemPruneReport struct { + PodPruneReport []*PodPruneReport + ContainerPruneReports []*reports.PruneReport + ImagePruneReports []*reports.PruneReport + NetworkPruneReports []*NetworkPruneReport + VolumePruneReports []*reports.PruneReport + ReclaimedSpace uint64 +} + +// SystemMigrateOptions describes the options needed for the +// cli to migrate runtimes of containers +type SystemMigrateOptions struct { + NewRuntime string +} + +// SystemDfOptions describes the options for getting df information +type SystemDfOptions struct { + Format string + Verbose bool +} + +// SystemDfReport describes the response for df information +type SystemDfReport struct { + ImagesSize int64 + Images []*SystemDfImageReport + Containers []*SystemDfContainerReport + Volumes []*SystemDfVolumeReport +} + +// SystemDfImageReport describes an image for use with df +type SystemDfImageReport struct { + Repository string + Tag string + ImageID string + Created time.Time + Size int64 + SharedSize int64 + UniqueSize int64 + Containers int +} + +// SystemDfContainerReport describes a container for use with df +type SystemDfContainerReport struct { + ContainerID string + Image string + Command []string + LocalVolumes int + Size int64 + RWSize int64 + Created time.Time + Status string + Names string +} + +// SystemDfVolumeReport describes a volume and its size +type SystemDfVolumeReport struct { + VolumeName string + Links int + Size int64 + ReclaimableSize int64 +} + +// SystemVersionReport describes version information about the running Podman service +type SystemVersionReport struct { + // Always populated + Client *define.Version `json:",omitempty"` + // May be populated, when in tunnel mode + Server *define.Version `json:",omitempty"` +} + +// SystemUnshareOptions describes the options for the unshare command +type SystemUnshareOptions struct { + RootlessNetNS bool +} + +// ListRegistriesReport is the report when querying for a sorted list of +// registries which may be contacted during certain operations. +type ListRegistriesReport struct { + Registries []string +} + +// AuthReport describes the response for authentication check +type AuthReport struct { + IdentityToken string + Status string +} + +// LocksReport describes any conflicts in Libpod's lock allocations that could +// lead to deadlocks. +type LocksReport struct { + LockConflicts map[uint32][]string + LocksHeld []uint32 +} diff --git a/pkg/domain/entities/types/types.go b/pkg/domain/entities/types/types.go index 7dc785078bc0..a2f0cf11c523 100644 --- a/pkg/domain/entities/types/types.go +++ b/pkg/domain/entities/types/types.go @@ -1,6 +1,12 @@ // copied from github.com/docker/docker/api/types package types +import ( + "os" + + buildahDefine "github.com/containers/buildah/define" +) + // ComponentVersion describes the version information for a specific component. type ComponentVersion struct { Name string @@ -27,3 +33,47 @@ type Version struct { Experimental bool `json:",omitempty"` BuildTime string `json:",omitempty"` } + +// SystemComponentVersion is the type used by pkg/domain/entities +type SystemComponentVersion struct { + Version +} + +// ContainerCreateResponse is the response struct for creating a container +type ContainerCreateResponse struct { + // ID of the container created + // required: true + ID string `json:"Id"` + // Warnings during container creation + // required: true + Warnings []string `json:"Warnings"` +} + +// FarmBuildOptions describes the options for building container images on farm nodes +type FarmBuildOptions struct { + // Cleanup removes built images from farm nodes on success + Cleanup bool + // Authfile is the path to the file holding registry credentials + Authfile string + // SkipTLSVerify skips tls verification when set to true + SkipTLSVerify bool +} + +// BuildOptions describe the options for building container images. +type BuildOptions struct { + buildahDefine.BuildOptions + ContainerFiles []string + FarmBuildOptions + // Files that need to be closed after the build + // so need to pass this to the main build functions + LogFileToClose *os.File + TmpDirToClose string +} + +// BuildReport is the image-build report. +type BuildReport struct { + // ID of the image. + ID string + // Format to save the image in + SaveFormat string +} diff --git a/pkg/domain/entities/types/volumes.go b/pkg/domain/entities/types/volumes.go new file mode 100644 index 000000000000..e5c89edef1f0 --- /dev/null +++ b/pkg/domain/entities/types/volumes.go @@ -0,0 +1,53 @@ +package types + +import ( + "github.com/containers/podman/v4/libpod/define" +) + +// swagger:model +type VolumeCreateOptions struct { + // New volume's name. Can be left blank + Name string `schema:"name"` + // Volume driver to use + Driver string `schema:"driver"` + // User-defined key/value metadata. Provided for compatibility + Label map[string]string `schema:"label"` + // User-defined key/value metadata. Preferred field, will override Label + Labels map[string]string `schema:"labels"` + // Mapping of driver options and values. + Options map[string]string `schema:"opts"` + // Ignore existing volumes + IgnoreIfExists bool `schema:"ignoreIfExist"` +} + +type VolumeRmReport struct { + Err error + Id string //nolint:revive,stylecheck +} +type VolumeInspectReport struct { + *VolumeConfigResponse +} + +type VolumeListReport struct { + VolumeConfigResponse +} + +type VolumeReloadReport struct { + define.VolumeReload +} + +type VolumeMountReport struct { + Err error + Id string //nolint:revive,stylecheck + Name string + Path string +} + +type VolumeUnmountReport struct { + Err error + Id string //nolint:revive,stylecheck +} + +type VolumeConfigResponse struct { + define.InspectVolumeData +} diff --git a/pkg/domain/entities/volumes.go b/pkg/domain/entities/volumes.go index 4acb7fc77dc4..ab68fcf97e38 100644 --- a/pkg/domain/entities/volumes.go +++ b/pkg/domain/entities/volumes.go @@ -3,29 +3,14 @@ package entities import ( "net/url" - "github.com/containers/podman/v4/libpod/define" + "github.com/containers/podman/v4/pkg/domain/entities/types" ) // VolumeCreateOptions provides details for creating volumes // swagger:model -type VolumeCreateOptions struct { - // New volume's name. Can be left blank - Name string `schema:"name"` - // Volume driver to use - Driver string `schema:"driver"` - // User-defined key/value metadata. Provided for compatibility - Label map[string]string `schema:"label"` - // User-defined key/value metadata. Preferred field, will override Label - Labels map[string]string `schema:"labels"` - // Mapping of driver options and values. - Options map[string]string `schema:"opts"` - // Ignore existing volumes - IgnoreIfExists bool `schema:"ignoreIfExist"` -} +type VolumeCreateOptions = types.VolumeCreateOptions -type VolumeConfigResponse struct { - define.InspectVolumeData -} +type VolumeConfigResponse = types.VolumeConfigResponse type VolumeRmOptions struct { All bool @@ -34,14 +19,9 @@ type VolumeRmOptions struct { Timeout *uint } -type VolumeRmReport struct { - Err error - Id string //nolint:revive,stylecheck -} +type VolumeRmReport = types.VolumeRmReport -type VolumeInspectReport struct { - *VolumeConfigResponse -} +type VolumeInspectReport = types.VolumeInspectReport // VolumePruneOptions describes the options needed // to prune a volume from the CLI @@ -53,29 +33,17 @@ type VolumeListOptions struct { Filter map[string][]string } -type VolumeListReport struct { - VolumeConfigResponse -} +type VolumeListReport = types.VolumeListReport // VolumeReloadReport describes the response from reload volume plugins -type VolumeReloadReport struct { - define.VolumeReload -} +type VolumeReloadReport = types.VolumeReloadReport /* * Docker API compatibility types */ // VolumeMountReport describes the response from volume mount -type VolumeMountReport struct { - Err error - Id string //nolint:revive,stylecheck - Name string - Path string -} +type VolumeMountReport = types.VolumeMountReport // VolumeUnmountReport describes the response from umounting a volume -type VolumeUnmountReport struct { - Err error - Id string //nolint:revive,stylecheck -} +type VolumeUnmountReport = types.VolumeUnmountReport diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 610648d892d8..f8a4e233f549 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -24,6 +24,7 @@ import ( "github.com/containers/podman/v4/libpod" "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/domain/entities" + entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types" v1apps "github.com/containers/podman/v4/pkg/k8s.io/api/apps/v1" v1 "github.com/containers/podman/v4/pkg/k8s.io/api/core/v1" metav1 "github.com/containers/podman/v4/pkg/k8s.io/apimachinery/pkg/apis/meta/v1" @@ -1184,7 +1185,7 @@ func (ic *ContainerEngine) playKubePVC(ctx context.Context, mountLabel string, p } } - report.Volumes = append(report.Volumes, entities.PlayKubeVolume{ + report.Volumes = append(report.Volumes, entitiesTypes.PlayKubeVolume{ Name: vol.Name(), }) diff --git a/pkg/specgen/namespaces.go b/pkg/specgen/namespaces.go index 4b8a6bee41c0..52a3763fbcc5 100644 --- a/pkg/specgen/namespaces.go +++ b/pkg/specgen/namespaces.go @@ -13,7 +13,7 @@ import ( "github.com/containers/podman/v4/pkg/namespaces" "github.com/containers/podman/v4/pkg/rootless" "github.com/containers/podman/v4/pkg/util" - "github.com/containers/storage" + storageTypes "github.com/containers/storage/types" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-tools/generate" "golang.org/x/exp/slices" @@ -488,7 +488,7 @@ func parseBridgeNetworkOptions(opts string) (types.PerNetworkOptions, error) { return netOpts, nil } -func SetupUserNS(idmappings *storage.IDMappingOptions, userns Namespace, g *generate.Generator) (string, error) { +func SetupUserNS(idmappings *storageTypes.IDMappingOptions, userns Namespace, g *generate.Generator) (string, error) { // User var user string switch userns.NSMode { @@ -544,7 +544,7 @@ func SetupUserNS(idmappings *storage.IDMappingOptions, userns Namespace, g *gene return user, nil } -func privateUserNamespace(idmappings *storage.IDMappingOptions, g *generate.Generator) error { +func privateUserNamespace(idmappings *storageTypes.IDMappingOptions, g *generate.Generator) error { if err := g.AddOrReplaceLinuxNamespace(string(spec.UserNamespace), ""); err != nil { return err }