bindings: play uses entities/types

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2024-01-25 15:20:12 +01:00
parent 5284149708
commit 34cc557411
11 changed files with 252 additions and 182 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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

View File

@ -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.

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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(),
})