Skip to content

Commit f18ebad

Browse files
committed
bindings: pods uses entities/types
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent 668d517 commit f18ebad

3 files changed

Lines changed: 74 additions & 58 deletions

File tree

pkg/bindings/pods/pods.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import (
88

99
"github.com/containers/podman/v4/pkg/api/handlers"
1010
"github.com/containers/podman/v4/pkg/bindings"
11-
"github.com/containers/podman/v4/pkg/domain/entities"
11+
entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types"
1212
"github.com/containers/podman/v4/pkg/errorhandling"
1313
jsoniter "github.com/json-iterator/go"
1414
)
1515

16-
func CreatePodFromSpec(ctx context.Context, spec *entities.PodSpec) (*entities.PodCreateReport, error) {
16+
func CreatePodFromSpec(ctx context.Context, spec *entitiesTypes.PodSpec) (*entitiesTypes.PodCreateReport, error) {
1717
var (
18-
pcr entities.PodCreateReport
18+
pcr entitiesTypes.PodCreateReport
1919
)
2020
if spec == nil {
21-
spec = new(entities.PodSpec)
21+
spec = new(entitiesTypes.PodSpec)
2222
}
2323
conn, err := bindings.GetClient(ctx)
2424
if err != nil {
@@ -54,9 +54,9 @@ func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool,
5454
}
5555

5656
// Inspect returns low-level information about the given pod.
57-
func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entities.PodInspectReport, error) {
57+
func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entitiesTypes.PodInspectReport, error) {
5858
var (
59-
report entities.PodInspectReport
59+
report entitiesTypes.PodInspectReport
6060
)
6161
if options == nil {
6262
options = new(InspectOptions)
@@ -77,9 +77,9 @@ func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*en
7777

7878
// Kill sends a SIGTERM to all the containers in a pod. The optional signal parameter
7979
// can be used to override SIGTERM.
80-
func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entities.PodKillReport, error) {
80+
func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entitiesTypes.PodKillReport, error) {
8181
var (
82-
report entities.PodKillReport
82+
report entitiesTypes.PodKillReport
8383
)
8484
if options == nil {
8585
options = new(KillOptions)
@@ -102,8 +102,8 @@ func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entities
102102
}
103103

104104
// Pause pauses all running containers in a given pod.
105-
func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entities.PodPauseReport, error) {
106-
var report entities.PodPauseReport
105+
func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entitiesTypes.PodPauseReport, error) {
106+
var report entitiesTypes.PodPauseReport
107107
if options == nil {
108108
options = new(PauseOptions)
109109
}
@@ -123,8 +123,8 @@ func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entiti
123123

124124
// Prune by default removes all non-running pods in local storage.
125125
// And with force set true removes all pods.
126-
func Prune(ctx context.Context, options *PruneOptions) ([]*entities.PodPruneReport, error) {
127-
var reports []*entities.PodPruneReport
126+
func Prune(ctx context.Context, options *PruneOptions) ([]*entitiesTypes.PodPruneReport, error) {
127+
var reports []*entitiesTypes.PodPruneReport
128128
if options == nil {
129129
options = new(PruneOptions)
130130
}
@@ -144,9 +144,9 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*entities.PodPruneRepo
144144

145145
// List returns all pods in local storage. The optional filters parameter can
146146
// be used to refine which pods should be listed.
147-
func List(ctx context.Context, options *ListOptions) ([]*entities.ListPodsReport, error) {
147+
func List(ctx context.Context, options *ListOptions) ([]*entitiesTypes.ListPodsReport, error) {
148148
var (
149-
podsReports []*entities.ListPodsReport
149+
podsReports []*entitiesTypes.ListPodsReport
150150
)
151151
if options == nil {
152152
options = new(ListOptions)
@@ -169,8 +169,8 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.ListPodsReport
169169
}
170170

171171
// Restart restarts all containers in a pod.
172-
func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entities.PodRestartReport, error) {
173-
var report entities.PodRestartReport
172+
func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entitiesTypes.PodRestartReport, error) {
173+
var report entitiesTypes.PodRestartReport
174174
if options == nil {
175175
options = new(RestartOptions)
176176
}
@@ -190,8 +190,8 @@ func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*en
190190

191191
// Remove deletes a Pod from local storage. The optional force parameter denotes
192192
// that the Pod can be removed even if in a running state.
193-
func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entities.PodRmReport, error) {
194-
var report entities.PodRmReport
193+
func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entitiesTypes.PodRmReport, error) {
194+
var report entitiesTypes.PodRmReport
195195
if options == nil {
196196
options = new(RemoveOptions)
197197
}
@@ -213,8 +213,8 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*enti
213213
}
214214

215215
// Start starts all containers in a pod.
216-
func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entities.PodStartReport, error) {
217-
var report entities.PodStartReport
216+
func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entitiesTypes.PodStartReport, error) {
217+
var report entitiesTypes.PodStartReport
218218
if options == nil {
219219
options = new(StartOptions)
220220
}
@@ -239,8 +239,8 @@ func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entiti
239239

240240
// Stop stops all containers in a Pod. The optional timeout parameter can be
241241
// used to override the timeout before the container is killed.
242-
func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entities.PodStopReport, error) {
243-
var report entities.PodStopReport
242+
func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entitiesTypes.PodStopReport, error) {
243+
var report entitiesTypes.PodStopReport
244244
if options == nil {
245245
options = new(StopOptions)
246246
}
@@ -302,12 +302,12 @@ func Top(ctx context.Context, nameOrID string, options *TopOptions) ([]string, e
302302
}
303303

304304
// Unpause unpauses all paused containers in a Pod.
305-
func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*entities.PodUnpauseReport, error) {
305+
func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*entitiesTypes.PodUnpauseReport, error) {
306306
if options == nil {
307307
options = new(UnpauseOptions)
308308
}
309309
_ = options
310-
var report entities.PodUnpauseReport
310+
var report entitiesTypes.PodUnpauseReport
311311
conn, err := bindings.GetClient(ctx)
312312
if err != nil {
313313
return nil, err
@@ -322,7 +322,7 @@ func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*en
322322
}
323323

324324
// Stats display resource-usage statistics of one or more pods.
325-
func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*entities.PodStatsReport, error) {
325+
func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*entitiesTypes.PodStatsReport, error) {
326326
if options == nil {
327327
options = new(StatsOptions)
328328
}
@@ -338,7 +338,7 @@ func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*
338338
params.Add("namesOrIDs", i)
339339
}
340340

341-
var reports []*entities.PodStatsReport
341+
var reports []*entitiesTypes.PodStatsReport
342342
response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/pods/stats", params, nil)
343343
if err != nil {
344344
return nil, err

pkg/domain/entities/pods.go

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package entities
33
import (
44
"errors"
55
"strings"
6-
"time"
76

87
commonFlag "github.com/containers/common/pkg/flag"
98
"github.com/containers/podman/v4/libpod/define"
@@ -19,31 +18,11 @@ type PodKillOptions struct {
1918
Signal string
2019
}
2120

22-
type PodKillReport struct {
23-
Errs []error
24-
Id string //nolint:revive,stylecheck
25-
}
21+
type PodKillReport = types.PodKillReport
2622

27-
type ListPodsReport struct {
28-
Cgroup string
29-
Containers []*ListPodContainer
30-
Created time.Time
31-
Id string //nolint:revive,stylecheck
32-
InfraId string //nolint:revive,stylecheck
33-
Name string
34-
Namespace string
35-
// Network names connected to infra container
36-
Networks []string
37-
Status string
38-
Labels map[string]string
39-
}
23+
type ListPodsReport = types.ListPodsReport
4024

41-
type ListPodContainer struct {
42-
Id string //nolint:revive,stylecheck
43-
Names string
44-
Status string
45-
RestartCount uint
46-
}
25+
type ListPodContainer = types.ListPodContainer
4726

4827
type PodPauseOptions struct {
4928
All bool
@@ -91,11 +70,7 @@ type PodRmOptions struct {
9170

9271
type PodRmReport = types.PodRmReport
9372

94-
// PddSpec is an abstracted version of PodSpecGen designed to eventually accept options
95-
// not meant to be in a specgen
96-
type PodSpec struct {
97-
PodSpecGen specgen.PodSpecGenerator
98-
}
73+
type PodSpec = types.PodSpec
9974

10075
// PodCreateOptions provides all possible options for creating a pod and its infra container.
10176
// The JSON tags below are made to match the respective field in ContainerCreateOptions for the purpose of mapping.
@@ -447,9 +422,7 @@ type PodPSOptions struct {
447422
Sort string
448423
}
449424

450-
type PodInspectReport struct {
451-
*define.InspectPodData
452-
}
425+
type PodInspectReport = types.PodInspectReport
453426

454427
// PodStatsOptions are options for the pod stats command.
455428
type PodStatsOptions struct {

pkg/domain/entities/types/pods.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package types
22

3+
import (
4+
"time"
5+
6+
"github.com/containers/podman/v4/libpod/define"
7+
"github.com/containers/podman/v4/pkg/specgen"
8+
)
9+
310
type PodPruneReport struct {
411
Err error
512
Id string //nolint:revive,stylecheck
@@ -73,3 +80,39 @@ type PodStatsReport struct {
7380
// example: elastic_pascal
7481
Name string
7582
}
83+
84+
// PodSpec is an abstracted version of PodSpecGen designed to eventually accept options
85+
// not meant to be in a specgen
86+
type PodSpec struct {
87+
PodSpecGen specgen.PodSpecGenerator
88+
}
89+
90+
type PodInspectReport struct {
91+
*define.InspectPodData
92+
}
93+
94+
type PodKillReport struct {
95+
Errs []error
96+
Id string //nolint:revive,stylecheck
97+
}
98+
99+
type ListPodsReport struct {
100+
Cgroup string
101+
Containers []*ListPodContainer
102+
Created time.Time
103+
Id string //nolint:revive,stylecheck
104+
InfraId string //nolint:revive,stylecheck
105+
Name string
106+
Namespace string
107+
// Network names connected to infra container
108+
Networks []string
109+
Status string
110+
Labels map[string]string
111+
}
112+
113+
type ListPodContainer struct {
114+
Id string //nolint:revive,stylecheck
115+
Names string
116+
Status string
117+
RestartCount uint
118+
}

0 commit comments

Comments
 (0)