Skip to content

Commit 310f0a3

Browse files
authored
azure: Delete source image on cleanup (openshift#475)
* azure: Delete source image on cleanup OSC creates the podvm image with packer by default and publishes it in a shared gallery. When the KataConfig CRD is deleted, OSC removes the gallery but the source image created by packer is left behind. This can generate uneeded storage costs to the customer. Fortunately, the path to the source image is available in the output of `az sig image-version show`. Fix the podvm image deletion flow to also delete the source image. Fixes: https://issues.redhat.com/browse/KATA-3462 Signed-off-by: Greg Kurz <[email protected]>
1 parent 6dff955 commit 310f0a3

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

config/peerpods/podvm/azure-podvm-image-handler.sh

+18-2
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,25 @@ function delete_image_using_id() {
774774
# IMAGE_ID shouldn't be empty
775775
[[ -z "${IMAGE_ID}" ]] && error_exit "IMAGE_ID is empty"
776776

777-
# Delete the image
777+
# Rightmost element of the input is <image-version>
778+
IMAGE_VERSION=${IMAGE_ID##*/}
779+
780+
# Get the id of the source image
781+
SOURCE_ID=$(az sig image-version show --resource-group "${AZURE_RESOURCE_GROUP}" \
782+
--gallery-name "${IMAGE_GALLERY_NAME}" \
783+
--gallery-image-definition "${IMAGE_DEFINITION_NAME}" \
784+
--gallery-image-version "${IMAGE_VERSION}" \
785+
--query "storageProfile.source.id" --output tsv) ||
786+
error_exit "Failed to get the source id for image ${IMAGE_GALLERY_NAME} version ${IMAGE_VERSION} with definition ${IMAGE_DEFINITION_NAME}"
787+
788+
# Delete the image version
778789
az sig image-version delete --ids "${IMAGE_ID}" ||
779-
error_exit "Failed to delete the image"
790+
error_exit "Failed to delete image version ${IMAGE_ID}"
791+
792+
# Delete the source image
793+
az image delete --ids "${SOURCE_ID}" ||
794+
error_exit "Failed to delete the source image ${SOURCE_ID}"
795+
780796

781797
# Remove the image id annotation from peer-pods-cm configmap
782798
delete_image_id_annotation_from_peer_pods_cm

0 commit comments

Comments
 (0)