working name of pod on start and stop

Signed-off-by: jkwiatko <jkwiatkoski@protonmail.com>
This commit is contained in:
jkwiatko 2024-05-24 12:39:32 -04:00
parent e53b96cb25
commit b45364254f
9 changed files with 242 additions and 237 deletions

View File

@ -39,9 +39,7 @@ var (
} }
) )
var ( var startOptions = podStartOptionsWrapper{}
startOptions = podStartOptionsWrapper{}
)
func init() { func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{ registry.Commands = append(registry.Commands, registry.CliCommand{
@ -60,9 +58,7 @@ func init() {
} }
func start(cmd *cobra.Command, args []string) error { func start(cmd *cobra.Command, args []string) error {
var ( var errs utils.OutputErrors
errs utils.OutputErrors
)
ids, err := specgenutil.ReadPodIDFiles(startOptions.PodIDFiles) ids, err := specgenutil.ReadPodIDFiles(startOptions.PodIDFiles)
if err != nil { 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 // in the cli, first we print out all the successful attempts
for _, r := range responses { for _, r := range responses {
if len(r.Errs) == 0 { if len(r.Errs) == 0 {
fmt.Println(r.Id) fmt.Println(r.RawInput)
} else { } else {
errs = append(errs, r.Errs...) errs = append(errs, r.Errs...)
} }

View File

@ -71,9 +71,7 @@ func init() {
} }
func stop(cmd *cobra.Command, args []string) error { func stop(cmd *cobra.Command, args []string) error {
var ( var errs utils.OutputErrors
errs utils.OutputErrors
)
if cmd.Flag("time").Changed { if cmd.Flag("time").Changed {
stopOptions.Timeout = stopOptions.timeoutCLI 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 // in the cli, first we print out all the successful attempts
for _, r := range responses { for _, r := range responses {
if len(r.Errs) == 0 { if len(r.Errs) == 0 {
fmt.Println(r.Id) fmt.Println(r.RawInput)
} else { } else {
errs = append(errs, r.Errs...) errs = append(errs, r.Errs...)
} }

View File

@ -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 { for id, err := range responses {
report.Errs = append(report.Errs, fmt.Errorf("stopping container %s: %w", id, err)) 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 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 { for id, err := range responses {
report.Errs = append(report.Errs, fmt.Errorf("%v: %w", "starting container "+id, err)) 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 return
} }
var flush = func() {} flush := func() {}
if flusher, ok := w.(http.Flusher); ok { if flusher, ok := w.(http.Flusher); ok {
flush = flusher.Flush flush = flusher.Flush
} }
// Collect the stats and send them over the wire. // Collect the stats and send them over the wire.
containerEngine := abi.ContainerEngine{Libpod: runtime} containerEngine := abi.ContainerEngine{Libpod: runtime}
reports, err := containerEngine.PodStats(r.Context(), query.NamesOrIDs, options) reports, err := containerEngine.PodStats(r.Context(), query.NamesOrIDs, options)
// Error checks as documented in swagger. // Error checks as documented in swagger.
if err != nil { if err != nil {
if errors.Is(err, define.ErrNoSuchPod) { if errors.Is(err, define.ErrNoSuchPod) {

View File

@ -14,9 +14,7 @@ import (
) )
func CreatePodFromSpec(ctx context.Context, spec *entitiesTypes.PodSpec) (*entitiesTypes.PodCreateReport, error) { func CreatePodFromSpec(ctx context.Context, spec *entitiesTypes.PodSpec) (*entitiesTypes.PodCreateReport, error) {
var ( var pcr entitiesTypes.PodCreateReport
pcr entitiesTypes.PodCreateReport
)
if spec == nil { if spec == nil {
spec = new(entitiesTypes.PodSpec) 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. // Inspect returns low-level information about the given pod.
func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entitiesTypes.PodInspectReport, error) { func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entitiesTypes.PodInspectReport, error) {
var ( var report entitiesTypes.PodInspectReport
report entitiesTypes.PodInspectReport
)
if options == nil { if options == nil {
options = new(InspectOptions) 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 // Kill sends a SIGTERM to all the containers in a pod. The optional signal parameter
// can be used to override SIGTERM. // can be used to override SIGTERM.
func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entitiesTypes.PodKillReport, error) { func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entitiesTypes.PodKillReport, error) {
var ( var report entitiesTypes.PodKillReport
report entitiesTypes.PodKillReport
)
if options == nil { if options == nil {
options = new(KillOptions) 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 // List returns all pods in local storage. The optional filters parameter can
// be used to refine which pods should be listed. // be used to refine which pods should be listed.
func List(ctx context.Context, options *ListOptions) ([]*entitiesTypes.ListPodsReport, error) { func List(ctx context.Context, options *ListOptions) ([]*entitiesTypes.ListPodsReport, error) {
var ( var podsReports []*entitiesTypes.ListPodsReport
podsReports []*entitiesTypes.ListPodsReport
)
if options == nil { if options == nil {
options = new(ListOptions) options = new(ListOptions)
} }
@ -231,6 +223,7 @@ func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entiti
if response.StatusCode == http.StatusNotModified { if response.StatusCode == http.StatusNotModified {
report.Id = nameOrID report.Id = nameOrID
report.RawInput = nameOrID
return &report, nil return &report, nil
} }

View File

@ -24,6 +24,7 @@ type PodUnpauseReport struct {
type PodStopReport struct { type PodStopReport struct {
Errs []error Errs []error
Id string //nolint:revive,stylecheck Id string //nolint:revive,stylecheck
RawInput string
} }
type PodRestartReport struct { type PodRestartReport struct {
@ -34,6 +35,7 @@ type PodRestartReport struct {
type PodStartReport struct { type PodStartReport struct {
Errs []error Errs []error
Id string //nolint:revive,stylecheck Id string //nolint:revive,stylecheck
RawInput string
} }
type PodRmReport struct { type PodRmReport struct {

View File

@ -194,7 +194,10 @@ func (ic *ContainerEngine) PodStop(ctx context.Context, namesOrIds []string, opt
return nil, err return nil, err
} }
for _, p := range pods { 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) errs, err := p.StopWithTimeout(ctx, true, options.Timeout)
if err != nil && !errors.Is(err, define.ErrPodPartialFail) { if err != nil && !errors.Is(err, define.ErrPodPartialFail) {
report.Errs = []error{err} report.Errs = []error{err}
@ -247,7 +250,10 @@ func (ic *ContainerEngine) PodStart(ctx context.Context, namesOrIds []string, op
} }
for _, p := range pods { for _, p := range pods {
report := entities.PodStartReport{Id: p.ID()} report := entities.PodStartReport{
Id: p.ID(),
RawInput: p.Name(),
}
errs, err := p.Start(ctx) errs, err := p.Start(ctx)
if err != nil && !errors.Is(err, define.ErrPodPartialFail) { if err != nil && !errors.Is(err, define.ErrPodPartialFail) {
report.Errs = []error{err} report.Errs = []error{err}

View File

@ -117,6 +117,7 @@ func (ic *ContainerEngine) PodStop(ctx context.Context, namesOrIds []string, opt
report := entities.PodStopReport{ report := entities.PodStopReport{
Errs: []error{err}, Errs: []error{err},
Id: p.Id, Id: p.Id,
RawInput: p.Name,
} }
reports = append(reports, &report) reports = append(reports, &report)
continue continue
@ -159,6 +160,7 @@ func (ic *ContainerEngine) PodStart(ctx context.Context, namesOrIds []string, op
report := entities.PodStartReport{ report := entities.PodStartReport{
Errs: []error{err}, Errs: []error{err},
Id: p.Id, Id: p.Id,
RawInput: p.Name,
} }
reports = append(reports, &report) reports = append(reports, &report)
continue continue

View File

@ -14,7 +14,6 @@ import (
) )
var _ = Describe("Podman pod start", func() { var _ = Describe("Podman pod start", func() {
It("podman pod start bogus pod", func() { It("podman pod start bogus pod", func() {
session := podmanTest.Podman([]string{"pod", "start", "123"}) session := podmanTest.Podman([]string{"pod", "start", "123"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
@ -31,16 +30,18 @@ var _ = Describe("Podman pod start", func() {
}) })
It("podman pod start single pod by name", 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)) 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() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
session = podmanTest.Podman([]string{"pod", "start", "foobar99"}) session = podmanTest.Podman([]string{"pod", "start", name})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).Should(ContainSubstring(name))
}) })
It("podman pod start multiple pods", func() { It("podman pod start multiple pods", func() {
@ -62,6 +63,8 @@ var _ = Describe("Podman pod start", func() {
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
Expect(session.OutputToString()).Should(ContainSubstring("foobar99"))
Expect(session.OutputToString()).Should(ContainSubstring("foobar100"))
}) })
It("multiple pods in conflict", func() { It("multiple pods in conflict", func() {
@ -231,5 +234,4 @@ var _ = Describe("Podman pod start", func() {
cmdline := readFirstLine(fmt.Sprintf("/proc/%s/cmdline", infraConmonPID)) cmdline := readFirstLine(fmt.Sprintf("/proc/%s/cmdline", infraConmonPID))
Expect(cmdline).To(ContainSubstring("/conmon")) Expect(cmdline).To(ContainSubstring("/conmon"))
}) })
}) })

View File

@ -254,7 +254,6 @@ EOF
fi fi
} }
@test "inspect - all container status" { @test "inspect - all container status" {
tests=" tests="
running | running | 0 running | running | 0
@ -291,7 +290,6 @@ failed | exited | 17
is "$output" "$RANDOM_STRING_1" "curl on restarted container" is "$output" "$RANDOM_STRING_1" "curl on restarted container"
} }
@test "logs" { @test "logs" {
run_podman logs mydonecontainer run_podman logs mydonecontainer
is "$output" "++$RANDOM_STRING_1++" "podman logs on stopped container" is "$output" "++$RANDOM_STRING_1++" "podman logs on stopped container"
@ -316,7 +314,7 @@ failed | exited | 17
is "$output" ".*mypod.*" is "$output" ".*mypod.*"
run_podman pod start 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 # run a container in an existing pod
# FIXME: 2024-02-07 fails: pod X cgroup is not set: internal libpod error # FIXME: 2024-02-07 fails: pod X cgroup is not set: internal libpod error
@ -328,7 +326,7 @@ failed | exited | 17
is "$output" ".*Running.*" "podman pod ps shows running state" is "$output" ".*Running.*" "podman pod ps shows running state"
run_podman pod stop mypod 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 run_podman pod rm mypod
is "$output" "[0-9a-f]\\{64\\}" "podman pod rm" is "$output" "[0-9a-f]\\{64\\}" "podman pod rm"
@ -336,7 +334,6 @@ failed | exited | 17
# FIXME: commit? kill? network? pause? restart? top? volumes? What else? # FIXME: commit? kill? network? pause? restart? top? volumes? What else?
@test "start" { @test "start" {
run_podman start -a mydonecontainer run_podman start -a mydonecontainer
is "$output" "++$RANDOM_STRING_1++" "start on already-run container" is "$output" "++$RANDOM_STRING_1++" "start on already-run container"
@ -350,7 +347,6 @@ failed | exited | 17
is "$output" "mydonecontainer" "podman rm mydonecontainer" is "$output" "mydonecontainer" "podman rm mydonecontainer"
} }
@test "stop and rm" { @test "stop and rm" {
run_podman stop -t0 myrunningcontainer run_podman stop -t0 myrunningcontainer
run_podman rm myrunningcontainer run_podman rm myrunningcontainer