Skip to content

Commit

Permalink
Merge pull request #15134 from sstosh/improve-output
Browse files Browse the repository at this point in the history
Output messages display rawInput
  • Loading branch information
openshift-merge-robot authored Aug 9, 2022
2 parents 28607a9 + 2685c8d commit 7992d86
Show file tree
Hide file tree
Showing 19 changed files with 366 additions and 110 deletions.
15 changes: 8 additions & 7 deletions cmd/podman/containers/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ func checkpoint(cmd *cobra.Command, args []string) error {
var statistics checkpointStatistics

for _, r := range responses {
if r.Err == nil {
if checkpointOptions.PrintStats {
statistics.ContainerStatistics = append(statistics.ContainerStatistics, r)
} else {
fmt.Println(r.Id)
}
} else {
switch {
case r.Err != nil:
errs = append(errs, r.Err)
case checkpointOptions.PrintStats:
statistics.ContainerStatistics = append(statistics.ContainerStatistics, r)
case r.RawInput != "":
fmt.Println(r.RawInput)
default:
fmt.Println(r.Id)
}
}

Expand Down
17 changes: 8 additions & 9 deletions cmd/podman/containers/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,20 @@ func cleanup(cmd *cobra.Command, args []string) error {
return err
}
for _, r := range responses {
if r.CleanErr == nil && r.RmErr == nil && r.RmiErr == nil {
fmt.Println(r.Id)
continue
}
if r.RmErr != nil {
switch {
case r.RmErr != nil:
logrus.Errorf("Removing container: %v", r.RmErr)
errs = append(errs, r.RmErr)
}
if r.RmiErr != nil {
case r.RmiErr != nil:
logrus.Errorf("Removing image: %v", r.RmiErr)
errs = append(errs, r.RmiErr)
}
if r.CleanErr != nil {
case r.CleanErr != nil:
logrus.Errorf("Cleaning up container: %v", r.CleanErr)
errs = append(errs, r.CleanErr)
case r.RawInput != "":
fmt.Println(r.RawInput)
default:
fmt.Println(r.Id)
}
}
return errs.PrintErrors()
Expand Down
9 changes: 6 additions & 3 deletions cmd/podman/containers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ func initContainer(cmd *cobra.Command, args []string) error {
return err
}
for _, r := range report {
if r.Err == nil {
fmt.Println(r.Id)
} else {
switch {
case r.Err != nil:
errs = append(errs, r.Err)
case r.RawInput != "":
fmt.Println(r.RawInput)
default:
fmt.Println(r.Id)
}
}
return errs.PrintErrors()
Expand Down
9 changes: 6 additions & 3 deletions cmd/podman/containers/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ func pause(cmd *cobra.Command, args []string) error {
return err
}
for _, r := range responses {
if r.Err == nil {
fmt.Println(r.RawInput)
} else {
switch {
case r.Err != nil:
errs = append(errs, r.Err)
case r.RawInput != "":
fmt.Println(r.RawInput)
default:
fmt.Println(r.Id)
}
}
return errs.PrintErrors()
Expand Down
15 changes: 8 additions & 7 deletions cmd/podman/containers/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,15 @@ func restore(cmd *cobra.Command, args []string) error {
var statistics restoreStatistics

for _, r := range responses {
if r.Err == nil {
if restoreOptions.PrintStats {
statistics.ContainerStatistics = append(statistics.ContainerStatistics, r)
} else {
fmt.Println(r.Id)
}
} else {
switch {
case r.Err != nil:
errs = append(errs, r.Err)
case restoreOptions.PrintStats:
statistics.ContainerStatistics = append(statistics.ContainerStatistics, r)
case r.RawInput != "":
fmt.Println(r.RawInput)
default:
fmt.Println(r.Id)
}
}

Expand Down
19 changes: 9 additions & 10 deletions cmd/podman/containers/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,18 @@ func start(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

for _, r := range responses {
if r.Err == nil {
if startOptions.Attach {
// Implement the exitcode when the only one container is enabled attach
registry.SetExitCode(r.ExitCode)
} else {
fmt.Println(r.RawInput)
}
} else {
switch {
case r.Err != nil:
errs = append(errs, r.Err)
case startOptions.Attach:
// Implement the exitcode when the only one container is enabled attach
registry.SetExitCode(r.ExitCode)
case r.RawInput != "":
fmt.Println(r.RawInput)
default:
fmt.Println(r.Id)
}
}

return errs.PrintErrors()
}
9 changes: 6 additions & 3 deletions cmd/podman/containers/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ func stop(cmd *cobra.Command, args []string) error {
return err
}
for _, r := range responses {
if r.Err == nil {
fmt.Println(r.RawInput)
} else {
switch {
case r.Err != nil:
errs = append(errs, r.Err)
case r.RawInput != "":
fmt.Println(r.RawInput)
default:
fmt.Println(r.Id)
}
}
return errs.PrintErrors()
Expand Down
9 changes: 6 additions & 3 deletions cmd/podman/containers/unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ func unpause(cmd *cobra.Command, args []string) error {
}

for _, r := range responses {
if r.Err == nil {
fmt.Println(r.RawInput)
} else {
switch {
case r.Err != nil:
errs = append(errs, r.Err)
case r.RawInput != "":
fmt.Println(r.RawInput)
default:
fmt.Println(r.Id)
}
}
return errs.PrintErrors()
Expand Down
8 changes: 6 additions & 2 deletions pkg/domain/entities/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ type CheckpointOptions struct {
type CheckpointReport struct {
Err error `json:"-"`
Id string `json:"Id"` //nolint:revive,stylecheck
RawInput string `json:"RawInput"`
RuntimeDuration int64 `json:"runtime_checkpoint_duration"`
CRIUStatistics *define.CRIUCheckpointRestoreStatistics `json:"criu_statistics"`
}
Expand All @@ -228,6 +229,7 @@ type RestoreOptions struct {
type RestoreReport struct {
Err error `json:"-"`
Id string `json:"Id"` //nolint:revive,stylecheck
RawInput string `json:"RawInput"`
RuntimeDuration int64 `json:"runtime_restore_duration"`
CRIUStatistics *define.CRIUCheckpointRestoreStatistics `json:"criu_statistics"`
}
Expand Down Expand Up @@ -374,6 +376,7 @@ type ContainerCleanupOptions struct {
type ContainerCleanupReport struct {
CleanErr error
Id string //nolint:revive,stylecheck
RawInput string
RmErr error
RmiErr error
}
Expand All @@ -388,8 +391,9 @@ type ContainerInitOptions struct {
// ContainerInitReport describes the results of a
// container init
type ContainerInitReport struct {
Err error
Id string //nolint:revive,stylecheck
Err error
Id string //nolint:revive,stylecheck
RawInput string
}

// ContainerMountOptions describes the input values for mounting containers
Expand Down
82 changes: 54 additions & 28 deletions pkg/domain/infra/abi/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,9 @@ func (ic *ContainerEngine) ContainerExport(ctx context.Context, nameOrID string,

func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds []string, options entities.CheckpointOptions) ([]*entities.CheckpointReport, error) {
var (
err error
cons []*libpod.Container
ctrs []*libpod.Container
rawInputs []string
err error
)
checkOpts := libpod.ContainerCheckpointOptions{
Keep: options.Keep,
Expand All @@ -640,24 +641,34 @@ func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds [
CreateImage: options.CreateImage,
}

idToRawInput := map[string]string{}
if options.All {
running := func(c *libpod.Container) bool {
state, _ := c.State()
return state == define.ContainerStateRunning
}
cons, err = ic.Libpod.GetContainers(running)
ctrs, err = ic.Libpod.GetContainers(running)
if err != nil {
return nil, err
}
} else {
cons, err = getContainersByContext(false, options.Latest, namesOrIds, ic.Libpod)
}
if err != nil {
return nil, err
ctrs, rawInputs, err = getContainersAndInputByContext(false, options.Latest, namesOrIds, nil, ic.Libpod)
if err != nil {
return nil, err
}
if len(rawInputs) == len(ctrs) {
for i := range ctrs {
idToRawInput[ctrs[i].ID()] = rawInputs[i]
}
}
}
reports := make([]*entities.CheckpointReport, 0, len(cons))
for _, con := range cons {
criuStatistics, runtimeCheckpointDuration, err := con.Checkpoint(ctx, checkOpts)
reports := make([]*entities.CheckpointReport, 0, len(ctrs))
for _, c := range ctrs {
criuStatistics, runtimeCheckpointDuration, err := c.Checkpoint(ctx, checkOpts)
reports = append(reports, &entities.CheckpointReport{
Err: err,
Id: con.ID(),
Id: c.ID(),
RawInput: idToRawInput[c.ID()],
RuntimeDuration: runtimeCheckpointDuration,
CRIUStatistics: criuStatistics,
})
Expand All @@ -667,7 +678,7 @@ func (ic *ContainerEngine) ContainerCheckpoint(ctx context.Context, namesOrIds [

func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []string, options entities.RestoreOptions) ([]*entities.RestoreReport, error) {
var (
containers []*libpod.Container
ctrs []*libpod.Container
checkpointImageImportErrors []error
err error
)
Expand All @@ -694,19 +705,21 @@ func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []st
},
}

idToRawInput := map[string]string{}
switch {
case options.Import != "":
containers, err = checkpoint.CRImportCheckpointTar(ctx, ic.Libpod, options)
ctrs, err = checkpoint.CRImportCheckpointTar(ctx, ic.Libpod, options)
case options.All:
containers, err = ic.Libpod.GetContainers(filterFuncs...)
ctrs, err = ic.Libpod.GetContainers(filterFuncs...)
case options.Latest:
containers, err = getContainersByContext(false, options.Latest, namesOrIds, ic.Libpod)
ctrs, err = getContainersByContext(false, options.Latest, namesOrIds, ic.Libpod)
default:
for _, nameOrID := range namesOrIds {
logrus.Debugf("look up container: %q", nameOrID)
ctr, err := ic.Libpod.LookupContainer(nameOrID)
c, err := ic.Libpod.LookupContainer(nameOrID)
if err == nil {
containers = append(containers, ctr)
ctrs = append(ctrs, c)
idToRawInput[c.ID()] = nameOrID
} else {
// If container was not found, check if this is a checkpoint image
logrus.Debugf("look up image: %q", nameOrID)
Expand All @@ -724,15 +737,15 @@ func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []st
if err != nil {
return nil, err
}
importedContainers, err := checkpoint.CRImportCheckpoint(ctx, ic.Libpod, options, mountPoint)
importedCtrs, err := checkpoint.CRImportCheckpoint(ctx, ic.Libpod, options, mountPoint)
if err != nil {
// CRImportCheckpoint is expected to import exactly one container from checkpoint image
checkpointImageImportErrors = append(
checkpointImageImportErrors,
fmt.Errorf("unable to import checkpoint from image: %q: %v", nameOrID, err),
)
} else {
containers = append(containers, importedContainers[0])
ctrs = append(ctrs, importedCtrs[0])
}
}
}
Expand All @@ -741,12 +754,13 @@ func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []st
return nil, err
}

reports := make([]*entities.RestoreReport, 0, len(containers))
for _, con := range containers {
criuStatistics, runtimeRestoreDuration, err := con.Restore(ctx, restoreOptions)
reports := make([]*entities.RestoreReport, 0, len(ctrs))
for _, c := range ctrs {
criuStatistics, runtimeRestoreDuration, err := c.Restore(ctx, restoreOptions)
reports = append(reports, &entities.RestoreReport{
Err: err,
Id: con.ID(),
Id: c.ID(),
RawInput: idToRawInput[c.ID()],
RuntimeDuration: runtimeRestoreDuration,
CRIUStatistics: criuStatistics,
})
Expand Down Expand Up @@ -1204,14 +1218,20 @@ func (ic *ContainerEngine) ContainerLogs(ctx context.Context, containers []strin
}

func (ic *ContainerEngine) ContainerCleanup(ctx context.Context, namesOrIds []string, options entities.ContainerCleanupOptions) ([]*entities.ContainerCleanupReport, error) {
reports := []*entities.ContainerCleanupReport{}
ctrs, err := getContainersByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, namesOrIds, nil, ic.Libpod)
if err != nil {
return nil, err
}
idToRawInput := map[string]string{}
if len(rawInputs) == len(ctrs) {
for i := range ctrs {
idToRawInput[ctrs[i].ID()] = rawInputs[i]
}
}
reports := []*entities.ContainerCleanupReport{}
for _, ctr := range ctrs {
var err error
report := entities.ContainerCleanupReport{Id: ctr.ID()}
report := entities.ContainerCleanupReport{Id: ctr.ID(), RawInput: idToRawInput[ctr.ID()]}

if options.Exec != "" {
if options.Remove {
Expand Down Expand Up @@ -1252,13 +1272,19 @@ func (ic *ContainerEngine) ContainerCleanup(ctx context.Context, namesOrIds []st
}

func (ic *ContainerEngine) ContainerInit(ctx context.Context, namesOrIds []string, options entities.ContainerInitOptions) ([]*entities.ContainerInitReport, error) {
ctrs, err := getContainersByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, namesOrIds, nil, ic.Libpod)
if err != nil {
return nil, err
}
idToRawInput := map[string]string{}
if len(rawInputs) == len(ctrs) {
for i := range ctrs {
idToRawInput[ctrs[i].ID()] = rawInputs[i]
}
}
reports := make([]*entities.ContainerInitReport, 0, len(ctrs))
for _, ctr := range ctrs {
report := entities.ContainerInitReport{Id: ctr.ID()}
report := entities.ContainerInitReport{Id: ctr.ID(), RawInput: idToRawInput[ctr.ID()]}
err := ctr.Init(ctx, ctr.PodID() != "")

// If we're initializing all containers, ignore invalid state errors
Expand Down
Loading

0 comments on commit 7992d86

Please sign in to comment.