Bug 2039589 - The toolbox command always ignores [command] the first time
Summary: The toolbox command always ignores [command] the first time
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: RHCOS
Version: 4.8
Hardware: Unspecified
OS: Unspecified
low
low
Target Milestone: ---
: 4.11.0
Assignee: Aashish Radhakrishnan
QA Contact: Michael Nguyen
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-01-12 01:35 UTC by Kazuhisa Hara
Modified: 2022-08-26 19:08 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Cause: The toolbox command with argument was ignored the first time as the argument was never passed to the container Consequence: The toolbox command with argument always skipped the first time Fix: container_runlabel and container_run functions modified to initiate 'podman container create' which is followed by 'podman start' and 'podman exec'. -container_exec function modified to keep the arguments as an array for avoiding the issue of commands with multiple arguments or spaces. Result: Toolbox command with arguments executed on the first attempt too.
Clone Of:
Environment:
Last Closed: 2022-08-10 10:42:08 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github coreos toolbox pull 75 0 None open Fix for the toolbox command that is ignored on first execution 2022-03-11 18:40:24 UTC
Red Hat Product Errata RHSA-2022:5069 0 None None None 2022-08-10 10:42:38 UTC

Description Kazuhisa Hara 2022-01-12 01:35:21 UTC
Description of problem:

    The toolbox command always ignores [command] the first time.


Version-Release number of selected component (if applicable):

    toolbox-0.0.8-3.rhaos4.8.el8.noarch

How reproducible:


The first time:
```
sh-4.4# toolbox ls                 # <== add `ls`
Trying to pull registry.redhat.io/rhel8/support-tools:latest...
Getting image source signatures
Checking if image destination supports signatures
Copying blob adffa6963146 done  
Copying blob 29bfe07dbe66 done  
Copying blob 26f1167feaf7 done  
Copying config e0a3910607 done  
Writing manifest to image destination
Storing signatures
e0a3910607766bb10a9d84a0223db78d9856407e34af50a4f8fc0587c6c041a9
Spawning a container 'toolbox-root' with image 'registry.redhat.io/rhel8/support-tools'
Detected RUN label in the container image. Using that as the default...
[root@master-1 /]#                 # <== ls will not run
[root@master-1 /]# 
[root@master-1 /]# exit
```


From the second time onwards:
```
sh-4.4# 
sh-4.4# toolbox ls
Container 'toolbox-root' already exists. Trying to start...
(To remove the container and start with a fresh toolbox, run: sudo podman rm 'toolbox-root')
toolbox-root
Container started successfully. To exit, type 'exit'.
bin  boot  dev    etc  home  host  lib  lib64  lost+found  media    mnt  opt  proc    root  run  sbin  srv  sys  tmp    usr  var
sh-4.4# 
```


Steps to Reproduce:
    1. Execute it with the [command] option on the node that has never started toolbox.

Actual results:

    The toolbox command always ignores [command] the first time.


Expected results:

    The [command] is executed even at the first time.


Additional info:

There are no notes in the --help:

```
sh-4.4# toolbox --help
USAGE: toolbox [-h/--help] [command]
toolbox is a small script that launches a container to let you bring in your favorite debugging or admin tools.
The toolbox container is a pet container and will be restarted on following runs.
To remove the container and start fresh, do sudo podman rm toolbox-root.
```

The case where [command] is executed is the pattern that through container_exec(), but it is not executed because it through only container_runlabel() at the first time.

https://github.com/coreos/toolbox/blob/0.0.8/rhcos-toolbox

```
run() {
    if ! image_exists; then
        image_pull
    fi

    local runlabel=$(image_runlabel)
    if ! container_exists; then
        echo "Spawning a container '$TOOLBOX_NAME' with image '$TOOLBOX_IMAGE'"
        if [[ -z "$runlabel" ]] || [[ "$runlabel" == "<no value>" ]]; then
            container_run
            return
        else
            echo "Detected RUN label in the container image. Using that as the default..."
            container_runlabel                   <== here
            return
        fi
    else
        echo "Container '$TOOLBOX_NAME' already exists. Trying to start..."
        echo "(To remove the container and start with a fresh toolbox, run: sudo podman rm '$TOOLBOX_NAME')"
    fi

    local state=$(container_state)
    if [[ "$state" == configured ]] || [[ "$state" == exited ]] || [[ "$state" == stopped ]]; then
        container_start
    elif [[ "$state" != running ]]; then
        echo "Container '$TOOLBOX_NAME' in unknown state: '$state'"
        return 1
    fi

    echo "Container started successfully. To exit, type 'exit'."
    container_exec "$@"
}
```

```
container_runlabel() {
    if ! sudo podman container runlabel --name "$TOOLBOX_NAME" RUN "$TOOLBOX_IMAGE" 2>&1; then
        echo "$0: failed to runlabel on image '$TOOLBOX_IMAGE'"
        exit 1
    fi
}
```

```
container_exec() {
    local cmd=$@
    if [ ! -n "$cmd" ]; then
        cmd=$(sudo podman inspect "$TOOLBOX_IMAGE" | jq -re ".[].Config.Cmd[0]") || cmd="/bin/sh"
    fi

    sudo podman exec \
        --env LANG="$LANG" \
        --env TERM="$TERM" \
        --tty \
        --interactive \
        "$TOOLBOX_NAME" \
        "$cmd"                   <== here
}
```

Comment 5 Aashish Radhakrishnan 2022-03-25 18:46:58 UTC
The toolbox command issue has been fixed and merged
PR - https://github.com/coreos/toolbox/pull/75

Comment 6 Timothée Ravier 2022-06-03 17:10:25 UTC
@aaradhak As you've made a new toolbox release with this PR merged and backported this change to 4.9 and up, this should have been updated to MODIFIED.

Comment 8 HuijingHei 2022-06-06 05:38:35 UTC
Get fixed toolbox-0.0.9-1.rhaos4.11.el8.noarch.rpm from:
https://brewweb.engineering.redhat.com/brew/buildinfo?buildID=2020320


Verify passed with rhcos-411.85.202206032330-0-qemu.x86_64.qcow2 (include fixed toolbox), can reproduce the problem with toolbox-0.0.8-4.rhaos4.11.el8.noarch

[core@cosa-devsh ~]$ rpm -q toolbox
toolbox-0.0.9-1.rhaos4.11.el8.noarch

[core@cosa-devsh ~]$ toolbox ls
Trying to pull registry.redhat.io/rhel8/support-tools:latest...
Getting image source signatures
Checking if image destination supports signatures
Copying blob cae7320018ab done  
Copying blob 545277d80005 done  
Copying blob f70d60810c69 done  
Copying config a8419564b7 done  
Writing manifest to image destination
Storing signatures
a8419564b7cc1417d26300d4560ce5812dccaee0c5ec88e22956ad5e67b32037
Spawning a container 'toolbox-core' with image 'registry.redhat.io/rhel8/support-tools'
Detected RUN label in the container image. Using that as the default...
93fed46f36ad58e5bb9cb52ccbf397a1b7105cdd0a22f4dc54be37c565e0388e
toolbox-core
bin  boot  dev	etc  home  host  lib  lib64  lost+found  media	mnt  opt  proc	root  run  sbin  srv  sys  tmp	usr  var

Comment 10 errata-xmlrpc 2022-08-10 10:42:08 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: OpenShift Container Platform 4.11.0 bug fix and security update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2022:5069


Note You need to log in before you can comment on or make changes to this bug.