Skip to content

Commit

Permalink
Merge pull request #23986 from mheon/fix_23981
Browse files Browse the repository at this point in the history
Match output of Compat Top API to Docker
  • Loading branch information
openshift-merge-bot[bot] authored Sep 17, 2024
2 parents f29901e + e04668c commit 75369fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/api/handlers/compat/containers_top.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,22 @@ loop: // break out of for/select infinite` loop
}

for _, line := range output[1:] {
process := strings.Split(line, "\t")
for i := range process {
process[i] = strings.TrimSpace(process[i])
process := strings.FieldsFunc(line, func(r rune) bool {
return r == ' ' || r == '\t'
})
if len(process) > len(body.Titles) {
// Docker assumes the last entry is *always* command
// Which can include spaces.
// All other descriptors are assumed to NOT include extra spaces.
// So combine any extras.
cmd := strings.Join(process[len(body.Titles)-1:], " ")
var finalProc []string
finalProc = append(finalProc, process[:len(body.Titles)-1]...)
finalProc = append(finalProc, cmd)
body.Processes = append(body.Processes, finalProc)
} else {
body.Processes = append(body.Processes, process)
}
body.Processes = append(body.Processes, process)
}

if err := encoder.Encode(body); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions test/apiv2/20-containers.at
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ if root; then
podman rm -f $CTRNAME
fi

# Verify that compat top endpoint combines multi-entry COMMAND lines
CTRNAME=testtopproc
podman run --name $CTRNAME -d $IMAGE sleep 25
t GET containers/$CTRNAME/top?stream=false 200 \
.Processes.[0].[6]="00:00:00" \
.Processes.[0].[7]="sleep 25"
podman rm -f -t0 $CTRNAME

CTRNAME=test123
podman run --name $CTRNAME -d $IMAGE top
t GET libpod/containers/$CTRNAME/top?ps_args=--invalid 500 \
Expand Down

1 comment on commit 75369fd

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.