Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have pod.Name display instead of pod.ID on start and stop reports #22806

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions cmd/podman/pods/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ var (
}
)

var (
startOptions = podStartOptionsWrapper{}
)
var startOptions = podStartOptionsWrapper{}

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Expand All @@ -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 {
Expand All @@ -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...)
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/podman/pods/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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...)
}
Expand Down
18 changes: 14 additions & 4 deletions pkg/api/handlers/libpod/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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) {
Expand Down
17 changes: 5 additions & 12 deletions pkg/bindings/pods/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/domain/entities/types/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions pkg/domain/infra/abi/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
10 changes: 6 additions & 4 deletions pkg/domain/infra/tunnel/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions test/e2e/pod_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -231,5 +234,4 @@ var _ = Describe("Podman pod start", func() {
cmdline := readFirstLine(fmt.Sprintf("/proc/%s/cmdline", infraConmonPID))
Expect(cmdline).To(ContainSubstring("/conmon"))
})

})
Loading