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

Match output of Compat Top API to Docker #23986

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Comment on lines +148 to +153
Copy link
Member

Choose a reason for hiding this comment

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

I guess you could add the output check to the top call above? Any reason to run another container for this?
I mean speed is not that big of a deal in API tests so I can live with that and not block over this.

Copy link
Member Author

Choose a reason for hiding this comment

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

We want a multi-part command - top doesn't actually test the combining code as it doesn't have a space in it.

Copy link
Member

Choose a reason for hiding this comment

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

ah yes of course


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