Skip to content

Commit f4c4eb9

Browse files
committed
Fix annotation handling for AWS
There are scenarios where an annotation may exist and adding a new annotation will fail if we don't use overwrite. Additionally delete the annotation on image deletion Fixes: #KATA-3117 Signed-off-by: Pradipta Banerjee <[email protected]>
1 parent a3ffed7 commit f4c4eb9

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Diff for: config/peerpods/podvm/aws-podvm-image-handler.sh

+26-2
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,35 @@ function add_ami_id_annotation_to_peer_pods_cm() {
259259
return
260260
fi
261261

262-
# Add the image id as annotation to peer-pods-cm configmap
263-
kubectl annotate configmap peer-pods-cm -n openshift-sandboxed-containers-operator \
262+
# Add the ami id as annotation to peer-pods-cm configmap
263+
# Overwrite any existing values
264+
kubectl annotate --overwrite configmap peer-pods-cm -n openshift-sandboxed-containers-operator \
264265
"LATEST_AMI_ID=${AMI_ID}" ||
265266
error_exit "Failed to add the ami id as annotation to peer-pods-cm configmap"
266267

267268
echo "AMI id added as annotation to peer-pods-cm configmap successfully"
268269
}
269270

271+
# Function to delete the LATEST_AMI_ID annotation from the peer-pods-cm configmap
272+
273+
function delete_ami_id_annotation_from_peer_pods_cm() {
274+
echo "Deleting ami id annotation from peer-pods-cm configmap"
275+
276+
# Check if the peer-pods-cm configmap exists
277+
if ! kubectl get configmap peer-pods-cm -n openshift-sandboxed-containers-operator >/dev/null 2>&1; then
278+
echo "peer-pods-cm configmap does not exist. Skipping deleting the ami id"
279+
return
280+
fi
281+
282+
# Delete the ami id annotation from peer-pods-cm configmap
283+
kubectl annotate configmap peer-pods-cm -n openshift-sandboxed-containers-operator \
284+
"LATEST_AMI_ID-" ||
285+
error_exit "Failed to delete the ami id annotation from peer-pods-cm configmap"
286+
287+
echo "Ami id annotation deleted from peer-pods-cm configmap successfully"
288+
}
289+
290+
270291
# Function to create the ami in AWS
271292

272293
function create_ami() {
@@ -324,6 +345,9 @@ function delete_ami_using_id() {
324345
aws ec2 deregister-image --region "${AWS_REGION}" --image-id "${AMI_ID}" ||
325346
error_exit "Failed to delete the ami"
326347

348+
# Remove the ami id annotation from peer-pods-cm configmap
349+
delete_ami_id_annotation_from_peer_pods_cm
350+
327351
}
328352

329353
# display help message

0 commit comments

Comments
 (0)