mirror of https://github.com/containers/podman.git
Merge pull request #22806 from JayKayy/22590-pod-console-name
Have pod.Name display instead of pod.ID on start and stop reports
This commit is contained in:
commit
6f0737a5c9
|
@ -39,9 +39,7 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
var (
|
||||
startOptions = podStartOptionsWrapper{}
|
||||
)
|
||||
var startOptions = podStartOptionsWrapper{}
|
||||
|
||||
func init() {
|
||||
registry.Commands = append(registry.Commands, registry.CliCommand{
|
||||
|
@ -60,9 +58,7 @@ func init() {
|
|||
}
|
||||
|
||||
func start(cmd *cobra.Command, args []string) error {
|
||||
var (
|
||||
errs utils.OutputErrors
|
||||
)
|
||||
var errs utils.OutputErrors
|
||||
|
||||
ids, err := specgenutil.ReadPodIDFiles(startOptions.PodIDFiles)
|
||||
if err != nil {
|
||||
|
@ -77,7 +73,7 @@ func start(cmd *cobra.Command, args []string) error {
|
|||
// in the cli, first we print out all the successful attempts
|
||||
for _, r := range responses {
|
||||
if len(r.Errs) == 0 {
|
||||
fmt.Println(r.Id)
|
||||
fmt.Println(r.RawInput)
|
||||
} else {
|
||||
errs = append(errs, r.Errs...)
|
||||
}
|
||||
|
|
|
@ -71,9 +71,7 @@ func init() {
|
|||
}
|
||||
|
||||
func stop(cmd *cobra.Command, args []string) error {
|
||||
var (
|
||||
errs utils.OutputErrors
|
||||
)
|
||||
var errs utils.OutputErrors
|
||||
if cmd.Flag("time").Changed {
|
||||
stopOptions.Timeout = stopOptions.timeoutCLI
|
||||
}
|
||||
|
@ -91,7 +89,7 @@ func stop(cmd *cobra.Command, args []string) error {
|
|||
// in the cli, first we print out all the successful attempts
|
||||
for _, r := range responses {
|
||||
if len(r.Errs) == 0 {
|
||||
fmt.Println(r.Id)
|
||||
fmt.Println(r.RawInput)
|
||||
} else {
|
||||
errs = append(errs, r.Errs...)
|
||||
}
|
||||
|
|
|
@ -177,7 +177,10 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
report := entities.PodStopReport{Id: pod.ID()}
|
||||
report := entities.PodStopReport{
|
||||
Id: pod.ID(),
|
||||
RawInput: pod.Name(),
|
||||
}
|
||||
for id, err := range responses {
|
||||
report.Errs = append(report.Errs, fmt.Errorf("stopping container %s: %w", id, err))
|
||||
}
|
||||
|
@ -213,7 +216,15 @@ func PodStart(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
report := entities.PodStartReport{Id: pod.ID()}
|
||||
cfg, err := pod.Config()
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusConflict, err)
|
||||
return
|
||||
}
|
||||
report := entities.PodStartReport{
|
||||
Id: pod.ID(),
|
||||
RawInput: cfg.Name,
|
||||
}
|
||||
for id, err := range responses {
|
||||
report.Errs = append(report.Errs, fmt.Errorf("%v: %w", "starting container "+id, err))
|
||||
}
|
||||
|
@ -559,14 +570,13 @@ func PodStats(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
var flush = func() {}
|
||||
flush := func() {}
|
||||
if flusher, ok := w.(http.Flusher); ok {
|
||||
flush = flusher.Flush
|
||||
}
|
||||
// Collect the stats and send them over the wire.
|
||||
containerEngine := abi.ContainerEngine{Libpod: runtime}
|
||||
reports, err := containerEngine.PodStats(r.Context(), query.NamesOrIDs, options)
|
||||
|
||||
// Error checks as documented in swagger.
|
||||
if err != nil {
|
||||
if errors.Is(err, define.ErrNoSuchPod) {
|
||||
|
|
|
@ -14,9 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func CreatePodFromSpec(ctx context.Context, spec *entitiesTypes.PodSpec) (*entitiesTypes.PodCreateReport, error) {
|
||||
var (
|
||||
pcr entitiesTypes.PodCreateReport
|
||||
)
|
||||
var pcr entitiesTypes.PodCreateReport
|
||||
if spec == nil {
|
||||
spec = new(entitiesTypes.PodSpec)
|
||||
}
|
||||
|
@ -55,9 +53,7 @@ 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) (*entitiesTypes.PodInspectReport, error) {
|
||||
var (
|
||||
report entitiesTypes.PodInspectReport
|
||||
)
|
||||
var report entitiesTypes.PodInspectReport
|
||||
if options == nil {
|
||||
options = new(InspectOptions)
|
||||
}
|
||||
|
@ -78,9 +74,7 @@ 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) (*entitiesTypes.PodKillReport, error) {
|
||||
var (
|
||||
report entitiesTypes.PodKillReport
|
||||
)
|
||||
var report entitiesTypes.PodKillReport
|
||||
if options == nil {
|
||||
options = new(KillOptions)
|
||||
}
|
||||
|
@ -145,9 +139,7 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*entitiesTypes.PodPrun
|
|||
// 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) ([]*entitiesTypes.ListPodsReport, error) {
|
||||
var (
|
||||
podsReports []*entitiesTypes.ListPodsReport
|
||||
)
|
||||
var podsReports []*entitiesTypes.ListPodsReport
|
||||
if options == nil {
|
||||
options = new(ListOptions)
|
||||
}
|
||||
|
@ -231,6 +223,7 @@ func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entiti
|
|||
|
||||
if response.StatusCode == http.StatusNotModified {
|
||||
report.Id = nameOrID
|
||||
report.RawInput = nameOrID
|
||||
return &report, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,9 @@ type PodUnpauseReport struct {
|
|||
}
|
||||
|
||||
type PodStopReport struct {
|
||||
Errs []error
|
||||
Id string //nolint:revive,stylecheck
|
||||
Errs []error
|
||||
Id string //nolint:revive,stylecheck
|
||||
RawInput string
|
||||
}
|
||||
|
||||
type PodRestartReport struct {
|
||||
|
@ -32,8 +33,9 @@ type PodRestartReport struct {
|
|||
}
|
||||
|
||||
type PodStartReport struct {
|
||||
Errs []error
|
||||
Id string //nolint:revive,stylecheck
|
||||
Errs []error
|
||||
Id string //nolint:revive,stylecheck
|
||||
RawInput string
|
||||
}
|
||||
|
||||
type PodRmReport struct {
|
||||
|
|
|
@ -194,7 +194,10 @@ func (ic *ContainerEngine) PodStop(ctx context.Context, namesOrIds []string, opt
|
|||
return nil, err
|
||||
}
|
||||
for _, p := range pods {
|
||||
report := entities.PodStopReport{Id: p.ID()}
|
||||
report := entities.PodStopReport{
|
||||
Id: p.ID(),
|
||||
RawInput: p.Name(),
|
||||
}
|
||||
errs, err := p.StopWithTimeout(ctx, true, options.Timeout)
|
||||
if err != nil && !errors.Is(err, define.ErrPodPartialFail) {
|
||||
report.Errs = []error{err}
|
||||
|
@ -247,7 +250,10 @@ func (ic *ContainerEngine) PodStart(ctx context.Context, namesOrIds []string, op
|
|||
}
|
||||
|
||||
for _, p := range pods {
|
||||
report := entities.PodStartReport{Id: p.ID()}
|
||||
report := entities.PodStartReport{
|
||||
Id: p.ID(),
|
||||
RawInput: p.Name(),
|
||||
}
|
||||
errs, err := p.Start(ctx)
|
||||
if err != nil && !errors.Is(err, define.ErrPodPartialFail) {
|
||||
report.Errs = []error{err}
|
||||
|
|
|
@ -115,8 +115,9 @@ func (ic *ContainerEngine) PodStop(ctx context.Context, namesOrIds []string, opt
|
|||
response, err := pods.Stop(ic.ClientCtx, p.Id, options)
|
||||
if err != nil {
|
||||
report := entities.PodStopReport{
|
||||
Errs: []error{err},
|
||||
Id: p.Id,
|
||||
Errs: []error{err},
|
||||
Id: p.Id,
|
||||
RawInput: p.Name,
|
||||
}
|
||||
reports = append(reports, &report)
|
||||
continue
|
||||
|
@ -157,8 +158,9 @@ func (ic *ContainerEngine) PodStart(ctx context.Context, namesOrIds []string, op
|
|||
response, err := pods.Start(ic.ClientCtx, p.Id, nil)
|
||||
if err != nil {
|
||||
report := entities.PodStartReport{
|
||||
Errs: []error{err},
|
||||
Id: p.Id,
|
||||
Errs: []error{err},
|
||||
Id: p.Id,
|
||||
RawInput: p.Name,
|
||||
}
|
||||
reports = append(reports, &report)
|
||||
continue
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
)
|
||||
|
||||
var _ = Describe("Podman pod start", func() {
|
||||
|
||||
It("podman pod start bogus pod", func() {
|
||||
session := podmanTest.Podman([]string{"pod", "start", "123"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
@ -31,16 +30,18 @@ var _ = Describe("Podman pod start", func() {
|
|||
})
|
||||
|
||||
It("podman pod start single pod by name", func() {
|
||||
_, ec, _ := podmanTest.CreatePod(map[string][]string{"--name": {"foobar99"}})
|
||||
name := "foobar99"
|
||||
_, ec, _ := podmanTest.CreatePod(map[string][]string{"--name": {name}})
|
||||
Expect(ec).To(Equal(0))
|
||||
|
||||
session := podmanTest.Podman([]string{"create", "--pod", "foobar99", ALPINE, "ls"})
|
||||
session := podmanTest.Podman([]string{"create", "--pod", name, ALPINE, "ls"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
|
||||
session = podmanTest.Podman([]string{"pod", "start", "foobar99"})
|
||||
session = podmanTest.Podman([]string{"pod", "start", name})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.OutputToString()).Should(ContainSubstring(name))
|
||||
})
|
||||
|
||||
It("podman pod start multiple pods", func() {
|
||||
|
@ -62,6 +63,8 @@ var _ = Describe("Podman pod start", func() {
|
|||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
|
||||
Expect(session.OutputToString()).Should(ContainSubstring("foobar99"))
|
||||
Expect(session.OutputToString()).Should(ContainSubstring("foobar100"))
|
||||
})
|
||||
|
||||
It("multiple pods in conflict", func() {
|
||||
|
@ -231,5 +234,4 @@ var _ = Describe("Podman pod start", func() {
|
|||
cmdline := readFirstLine(fmt.Sprintf("/proc/%s/cmdline", infraConmonPID))
|
||||
Expect(cmdline).To(ContainSubstring("/conmon"))
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -316,7 +316,7 @@ failed | exited | 17
|
|||
is "$output" ".*mypod.*"
|
||||
|
||||
run_podman pod start mypod
|
||||
is "$output" "[0-9a-f]\\{64\\}" "podman pod start"
|
||||
is "$output" "mypod" "podman pod start"
|
||||
|
||||
# run a container in an existing pod
|
||||
# FIXME: 2024-02-07 fails: pod X cgroup is not set: internal libpod error
|
||||
|
@ -328,7 +328,7 @@ failed | exited | 17
|
|||
is "$output" ".*Running.*" "podman pod ps shows running state"
|
||||
|
||||
run_podman pod stop mypod
|
||||
is "$output" "[0-9a-f]\\{64\\}" "podman pod stop"
|
||||
is "$output" "mypod" "podman pod stop"
|
||||
|
||||
run_podman pod rm mypod
|
||||
is "$output" "[0-9a-f]\\{64\\}" "podman pod rm"
|
||||
|
|
Loading…
Reference in New Issue