Skip to content

Commit

Permalink
list: Recognize UBI8 as Toolbox image & split tracked labels
Browse files Browse the repository at this point in the history
UBI[0] does not have the recommend Toolbox labels used to track whether
an image/container is truly a toolbox image/container. Thankfully, they
have a number of labels to choose from that we can use to identify the
image. The "com.redhat.component=ubi8-container" seems to be ideal.

The approach of using the UBI8 label introduces one problem though. If
we were to use only one set of labels for both images and containers,
containers created with Podman and not Toolbox from UBI8 would also be
marked as toolbox containers. This is not desired and therefore there
are now two sets of labels. Ones for images where the new label has been
added and other for containers that stays the same.
  • Loading branch information
HarryMichal committed May 31, 2021
1 parent 54a2ca1 commit e09de9f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ var (
onlyImages bool
}

// toolboxLabels holds labels used by containers/images that mark them as compatible with Toolbox
toolboxLabels = map[string]string{
// toolboxImageLabels holds labels used by images that mark them as compatible with Toolbox
toolboxImageLabels = map[string]string{
"com.github.debarshiray.toolbox": "true",
"com.github.containers.toolbox": "true",
"com.redhat.component": "ubi8-container",
}

// toolboxContainerLabels holds labels used by container that mark them as compatible with Toolbox
toolboxContainerLabels = map[string]string{
"com.github.debarshiray.toolbox": "true",
"com.github.containrs.toolbox": "true",
}
)

var listCmd = &cobra.Command{
Expand Down Expand Up @@ -157,7 +164,7 @@ func getContainers() ([]toolboxContainer, error) {
continue
}

for label := range toolboxLabels {
for label := range toolboxContainerLabels {
if _, ok := c.Labels[label]; ok {
isToolboxContainer = true
break
Expand Down Expand Up @@ -222,7 +229,7 @@ func getImages() ([]toolboxImage, error) {
continue
}

for label := range toolboxLabels {
for label := range toolboxImageLabels {
if _, ok := i.Labels[label]; ok {
isToolboxImage = true
break
Expand Down
1 change: 1 addition & 0 deletions test/system/000-setup.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ load 'libs/helpers'
_pull_and_cache_distro_image $(get_system_id) $(get_system_version) || die
# Cache all images that will be needed during the tests
_pull_and_cache_distro_image fedora 32 || die
_pull_and_cache_distro_image rhel 8.4 || die
_pull_and_cache_distro_image busybox || die
}
28 changes: 28 additions & 0 deletions test/system/102-list.bats
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,31 @@ teardown() {
assert_output --partial "non-default-one"
assert_output --partial "non-default-two"
}

@test "list: Run 'list -i' with UBI image (8.4; public) present" {
pull_distro_image rhel 8.4

run toolbox list --images

assert_success
assert_output --partial "registry.access.redhat.com/ubi8/ubi:8.4"
}

@test "list: Run 'list' with UBI image (8.4; public), toolbox container and non-toolbox container" {
local num_of_containers

pull_distro_image rhel 8.4

create_distro_container rhel 8.4 rhel-toolbox
podman create --name podman-container ubi8/ubi:8.4 /bin/sh

num_of_containers=$(list_containers)
assert [ $num_of_containers -eq 2 ]

run toolbox list

assert_success
assert_line --index 1 --partial "registry.access.redhat.com/ubi8/ubi:8.4"
assert_line --index 3 --partial "rhel-toolbox"
refute_output --partial "podman-container"
}
2 changes: 1 addition & 1 deletion test/system/libs/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readonly IMAGE_CACHE_DIR="${PROJECT_DIR}/image-cache"
# Images
declare -Ag IMAGES=([busybox]="docker.io/library/busybox" \
[fedora]="registry.fedoraproject.org/fedora-toolbox" \
[rhel]="registry.access.redhat.com/ubi8")
[rhel]="registry.access.redhat.com/ubi8/ubi")


function cleanup_all() {
Expand Down

0 comments on commit e09de9f

Please sign in to comment.