From 34cc5574111d3051dd275e817a20cf0cdb204b7b Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Thu, 25 Jan 2024 15:20:12 +0100
Subject: [PATCH] bindings: play uses entities/types

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
---
 pkg/bindings/kube/kube.go            | 16 +++----
 pkg/bindings/play/play.go            | 10 ++--
 pkg/domain/entities/play.go          | 48 +++----------------
 pkg/domain/entities/pods.go          | 70 ++++------------------------
 pkg/domain/entities/secrets.go       | 48 ++++---------------
 pkg/domain/entities/types/play.go    | 48 +++++++++++++++++++
 pkg/domain/entities/types/pods.go    | 69 +++++++++++++++++++++++++++
 pkg/domain/entities/types/secrets.go | 50 ++++++++++++++++++++
 pkg/domain/entities/types/volumes.go | 37 +++++++++++++++
 pkg/domain/entities/volumes.go       | 35 ++++----------
 pkg/domain/infra/abi/play.go         |  3 +-
 11 files changed, 252 insertions(+), 182 deletions(-)
 create mode 100644 pkg/domain/entities/types/play.go
 create mode 100644 pkg/domain/entities/types/secrets.go
 create mode 100644 pkg/domain/entities/types/volumes.go

diff --git a/pkg/bindings/kube/kube.go b/pkg/bindings/kube/kube.go
index fefbe1a2f5..c9e2c025f6 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/play/play.go b/pkg/bindings/play/play.go
index 803349b884..7e8f9ee40f 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/domain/entities/play.go b/pkg/domain/entities/play.go
index 94d4247d89..e837608c7a 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 a3283e7f99..ad435a7016 100644
--- a/pkg/domain/entities/pods.go
+++ b/pkg/domain/entities/pods.go
@@ -50,20 +50,14 @@ type PodPauseOptions struct {
 	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
@@ -72,30 +66,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
@@ -105,11 +89,7 @@ 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
@@ -322,13 +302,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{}
@@ -484,35 +460,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 ce3fac8d8e..45936ded9f 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/types/play.go b/pkg/domain/entities/types/play.go
new file mode 100644
index 0000000000..7f744106c3
--- /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
index 0bdc6d5a42..a5555d6c6c 100644
--- a/pkg/domain/entities/types/pods.go
+++ b/pkg/domain/entities/types/pods.go
@@ -4,3 +4,72 @@ 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
+}
diff --git a/pkg/domain/entities/types/secrets.go b/pkg/domain/entities/types/secrets.go
new file mode 100644
index 0000000000..0ba544db72
--- /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/volumes.go b/pkg/domain/entities/types/volumes.go
new file mode 100644
index 0000000000..033121a1a4
--- /dev/null
+++ b/pkg/domain/entities/types/volumes.go
@@ -0,0 +1,37 @@
+package types
+
+import (
+	"github.com/containers/podman/v4/libpod/define"
+)
+
+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 4acb7fc77d..484a24cf57 100644
--- a/pkg/domain/entities/volumes.go
+++ b/pkg/domain/entities/volumes.go
@@ -3,7 +3,7 @@ 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
@@ -23,9 +23,7 @@ type VolumeCreateOptions struct {
 	IgnoreIfExists bool `schema:"ignoreIfExist"`
 }
 
-type VolumeConfigResponse struct {
-	define.InspectVolumeData
-}
+type VolumeConfigResponse = types.VolumeConfigResponse
 
 type VolumeRmOptions struct {
 	All     bool
@@ -34,14 +32,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 +46,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 610648d892..f8a4e233f5 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(),
 	})