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

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