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.
This commit is contained in:
parent
54a2ca1ead
commit
e09de9f3e5
4 changed files with 41 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue