From e09de9f3e53dee80eec33619b8773a85a1fb863d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20M=C3=ADchal?= Date: Wed, 26 May 2021 15:25:04 +0200 Subject: [PATCH] list: Recognize UBI8 as Toolbox image & split tracked labels 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. --- src/cmd/list.go | 15 +++++++++++---- test/system/000-setup.bats | 1 + test/system/102-list.bats | 28 ++++++++++++++++++++++++++++ test/system/libs/helpers.bash | 2 +- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/cmd/list.go b/src/cmd/list.go index 51c6f9ed8..8e78b82d3 100644 --- a/src/cmd/list.go +++ b/src/cmd/list.go @@ -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{ @@ -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 @@ -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 diff --git a/test/system/000-setup.bats b/test/system/000-setup.bats index 019b03594..67eeae0e1 100644 --- a/test/system/000-setup.bats +++ b/test/system/000-setup.bats @@ -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 } diff --git a/test/system/102-list.bats b/test/system/102-list.bats index eeff00765..e3f20fe6e 100644 --- a/test/system/102-list.bats +++ b/test/system/102-list.bats @@ -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" +} diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index 66e5dfb26..dbfd5cc14 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -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() {