Blame SOURCES/bz1788889-podman-improve-image-exist-check.patch

b4b3ce
From d763318c0a5353bd352609090efc83d6ea4cc203 Mon Sep 17 00:00:00 2001
b4b3ce
From: Michele Baldessari <michele@acksyn.org>
b4b3ce
Date: Tue, 7 Jan 2020 19:16:51 +0100
b4b3ce
Subject: [PATCH] [podman] Simplify the code for checking if an image exists
b4b3ce
b4b3ce
Let's switch to the existing 'podman image exists' to determine if
b4b3ce
an image is local to the machine or if it needs pulling.
b4b3ce
b4b3ce
Let's change this for a number of reasons:
b4b3ce
- It simplifies the code greatly
b4b3ce
- It makes everything work even when the image is prefixed with 'localhost/'
b4b3ce
  names which are not detected as local images
b4b3ce
- It makes the code faster as we do not need to list all the images as
b4b3ce
  that is more expensive
b4b3ce
b4b3ce
Tested by running a couple of full containerized OpenStack deployments,
b4b3ce
one with images tagged as 'localhost/foo/mysql:pcmklatest' and one
b4b3ce
with a normal registry host prefix.
b4b3ce
b4b3ce
Co-Authored-By: Damien Ciabrini <dciabrin@redhat.com>
b4b3ce
---
b4b3ce
 heartbeat/podman | 26 +-------------------------
b4b3ce
 1 file changed, 1 insertion(+), 25 deletions(-)
b4b3ce
b4b3ce
diff --git a/heartbeat/podman b/heartbeat/podman
b4b3ce
index 8a916eb8c..f77d988fc 100755
b4b3ce
--- a/heartbeat/podman
b4b3ce
+++ b/heartbeat/podman
b4b3ce
@@ -441,31 +441,7 @@ podman_stop()
b4b3ce
 
b4b3ce
 image_exists()
b4b3ce
 {
b4b3ce
-	# if no tag was specified, use default "latest"
b4b3ce
-	local COLON_FOUND=0
b4b3ce
-	local SLASH_FOUND=0
b4b3ce
-	local SERVER_NAME=""
b4b3ce
-	local IMAGE_NAME="${OCF_RESKEY_image}"
b4b3ce
-	local IMAGE_TAG="latest"
b4b3ce
-
b4b3ce
-	SLASH_FOUND="$(echo "${OCF_RESKEY_image}" | grep -o '/' | grep -c .)"
b4b3ce
-
b4b3ce
-	if [ ${SLASH_FOUND} -ge 1 ]; then
b4b3ce
-		SERVER_NAME="$(echo ${IMAGE_NAME} | cut -d / -f 1-${SLASH_FOUND})"
b4b3ce
-		IMAGE_NAME="$(echo ${IMAGE_NAME} | awk -F'/' '{print $NF}')"
b4b3ce
-	fi
b4b3ce
-
b4b3ce
-	COLON_FOUND="$(echo "${IMAGE_NAME}" | grep -o ':' | grep -c .)"
b4b3ce
-	if [ ${COLON_FOUND} -ge 1 ]; then
b4b3ce
-		IMAGE_TAG="$(echo ${IMAGE_NAME} | awk -F':' '{print $NF}')"
b4b3ce
-		IMAGE_NAME="$(echo ${IMAGE_NAME} | cut -d : -f 1-${COLON_FOUND})"
b4b3ce
-	fi
b4b3ce
-
b4b3ce
-	# IMAGE_NAME might be following formats:
b4b3ce
-	# - image
b4b3ce
-	# - repository:port/image
b4b3ce
-	# - docker.io/image (some distro will display "docker.io/" as prefix)
b4b3ce
-	podman images | awk '{print $1 ":" $2}' | egrep -q -s "^(docker.io\/|${SERVER_NAME}\/)?${IMAGE_NAME}:${IMAGE_TAG}\$"
b4b3ce
+	podman image exists "${OCF_RESKEY_image}"
b4b3ce
 	if [ $? -eq 0 ]; then
b4b3ce
 		# image found
b4b3ce
 		return 0