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 (
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...)
}

View File

@ -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...)
}

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 {
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) {

View File

@ -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
}

View File

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

View File

@ -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}

View File

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

View File

@ -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"))
})
})

View File

@ -29,7 +29,7 @@ if [ -z "${RANDOM_STRING_1}" ]; then
fi
# Version string of the podman we're actually testing, e.g. '3.0.0-dev-d1a26013'
PODMAN_VERSION=$($PODMAN version |awk '/^Version:/ { V=$2 } /^Git Commit:/ { G=$3 } END { print V "-" substr(G,0,8) }')
PODMAN_VERSION=$($PODMAN version | awk '/^Version:/ { V=$2 } /^Git Commit:/ { G=$3 } END { print V "-" substr(G,0,8) }')
setup() {
skip_if_rootless
@ -40,7 +40,7 @@ setup() {
false
fi
if [ "$(< $PODMAN_UPGRADE_WORKDIR/status)" = "failed" ]; then
if [ "$(<$PODMAN_UPGRADE_WORKDIR/status)" = "failed" ]; then
skip "*** setup failed - no point in running tests"
fi
@ -54,7 +54,7 @@ setup() {
# BEGIN setup
@test "initial setup: start $PODMAN_UPGRADE_FROM containers" {
echo failed >| $PODMAN_UPGRADE_WORKDIR/status
echo failed >|$PODMAN_UPGRADE_WORKDIR/status
OLD_PODMAN=quay.io/podman/stable:$PODMAN_UPGRADE_FROM
$PODMAN pull $OLD_PODMAN
@ -91,7 +91,7 @@ setup() {
# command in this script will be the desired old-podman version.
#
pmscript=$pmroot/setup
cat >| $pmscript <<EOF
cat >|$pmscript <<EOF
#!/bin/bash
#
@ -192,7 +192,7 @@ EOF
_PODMAN_TEST_OPTS= wait_for_ready podman_parent
echo OK >| $PODMAN_UPGRADE_WORKDIR/status
echo OK >|$PODMAN_UPGRADE_WORKDIR/status
}
# END setup
@ -254,7 +254,6 @@ EOF
fi
}
@test "inspect - all container status" {
tests="
running | running | 0
@ -291,7 +290,6 @@ failed | exited | 17
is "$output" "$RANDOM_STRING_1" "curl on restarted container"
}
@test "logs" {
run_podman logs mydonecontainer
is "$output" "++$RANDOM_STRING_1++" "podman logs on stopped container"
@ -316,7 +314,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 +326,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"
@ -336,7 +334,6 @@ failed | exited | 17
# FIXME: commit? kill? network? pause? restart? top? volumes? What else?
@test "start" {
run_podman start -a mydonecontainer
is "$output" "++$RANDOM_STRING_1++" "start on already-run container"
@ -350,7 +347,6 @@ failed | exited | 17
is "$output" "mydonecontainer" "podman rm mydonecontainer"
}
@test "stop and rm" {
run_podman stop -t0 myrunningcontainer
run_podman rm myrunningcontainer