@@ -259,14 +259,35 @@ function add_ami_id_annotation_to_peer_pods_cm() {
259
259
return
260
260
fi
261
261
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 \
264
265
" LATEST_AMI_ID=${AMI_ID} " ||
265
266
error_exit " Failed to add the ami id as annotation to peer-pods-cm configmap"
266
267
267
268
echo " AMI id added as annotation to peer-pods-cm configmap successfully"
268
269
}
269
270
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
+
270
291
# Function to create the ami in AWS
271
292
272
293
function create_ami() {
@@ -324,6 +345,9 @@ function delete_ami_using_id() {
324
345
aws ec2 deregister-image --region " ${AWS_REGION} " --image-id " ${AMI_ID} " ||
325
346
error_exit " Failed to delete the ami"
326
347
348
+ # Remove the ami id annotation from peer-pods-cm configmap
349
+ delete_ami_id_annotation_from_peer_pods_cm
350
+
327
351
}
328
352
329
353
# display help message
0 commit comments