@@ -153,7 +153,7 @@ function create_ami_using_packer() {
153
153
# Function to get the ami id of the newly created image
154
154
155
155
function get_ami_id() {
156
- echo " Getting the image id"
156
+ echo " Getting the ami id"
157
157
158
158
# Get the ami id of the newly created image
159
159
# If any error occurs, exit the script with an error message
@@ -162,7 +162,7 @@ function get_ami_id() {
162
162
AMI_ID=$( aws ec2 describe-images --region " ${AWS_REGION} " --filters " Name=name,Values=${AMI_NAME} " --query ' Images[*].ImageId' --output text) ||
163
163
error_exit " Failed to get the ami id"
164
164
165
- # Set the image id as an environment variable
165
+ # Set the ami id as an environment variable
166
166
export AMI_ID
167
167
168
168
echo " ID of the newly created ami: ${AMI_ID} "
@@ -181,7 +181,7 @@ function get_all_ami_ids() {
181
181
AMI_ID_LIST=$( aws ec2 describe-images --region " ${AWS_REGION} " --filters " Name=name,Values=${AMI_BASE_NAME} -*" --query ' Images[*].ImageId' --output text) ||
182
182
error_exit " Failed to get the ami id list"
183
183
184
- # Set the image id list as an environment variable
184
+ # Set the ami id list as an environment variable
185
185
export AMI_ID_LIST
186
186
187
187
# Display the list of amis
@@ -190,7 +190,7 @@ function get_all_ami_ids() {
190
190
}
191
191
192
192
# Function to create or update podvm-images configmap with all the amis
193
- # Input AMI_ID_LIST is a list of image ids
193
+ # Input AMI_ID_LIST is a list of ami ids
194
194
195
195
function create_or_update_image_configmap() {
196
196
echo " Creating or updating podvm-images configmap"
@@ -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