From 7b9f7adebcbd426bd6b89c8c585c847cccbf7b32 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/102-list.bats | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 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/102-list.bats b/test/system/102-list.bats index 004e1c39a..cb5a7c478 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 /bin/sh + + num_of_containers=$(list_containers) + assert [ $num_of_containers -eq 2 ] + + run toolbox list + + assert_success + assert_line --index 1 --partial ubi8/ubi + assert_line --index 3 rhel-toolbox + refute_output --partial podman-container +}