Skip to content

Cherry-pick annotation fixes for 1.6 #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions config/peerpods/podvm/aws-podvm-image-handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function create_ami_using_packer() {
# Function to get the ami id of the newly created image

function get_ami_id() {
echo "Getting the image id"
echo "Getting the ami id"

# Get the ami id of the newly created image
# If any error occurs, exit the script with an error message
Expand All @@ -162,7 +162,7 @@ function get_ami_id() {
AMI_ID=$(aws ec2 describe-images --region "${AWS_REGION}" --filters "Name=name,Values=${AMI_NAME}" --query 'Images[*].ImageId' --output text) ||
error_exit "Failed to get the ami id"

# Set the image id as an environment variable
# Set the ami id as an environment variable
export AMI_ID

echo "ID of the newly created ami: ${AMI_ID}"
Expand All @@ -181,7 +181,7 @@ function get_all_ami_ids() {
AMI_ID_LIST=$(aws ec2 describe-images --region "${AWS_REGION}" --filters "Name=name,Values=${AMI_BASE_NAME}-*" --query 'Images[*].ImageId' --output text) ||
error_exit "Failed to get the ami id list"

# Set the image id list as an environment variable
# Set the ami id list as an environment variable
export AMI_ID_LIST

# Display the list of amis
Expand All @@ -190,7 +190,7 @@ function get_all_ami_ids() {
}

# Function to create or update podvm-images configmap with all the amis
# Input AMI_ID_LIST is a list of image ids
# Input AMI_ID_LIST is a list of ami ids

function create_or_update_image_configmap() {
echo "Creating or updating podvm-images configmap"
Expand Down Expand Up @@ -259,14 +259,35 @@ function add_ami_id_annotation_to_peer_pods_cm() {
return
fi

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

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

# Function to delete the LATEST_AMI_ID annotation from the peer-pods-cm configmap

function delete_ami_id_annotation_from_peer_pods_cm() {
echo "Deleting ami id annotation from peer-pods-cm configmap"

# Check if the peer-pods-cm configmap exists
if ! kubectl get configmap peer-pods-cm -n openshift-sandboxed-containers-operator >/dev/null 2>&1; then
echo "peer-pods-cm configmap does not exist. Skipping deleting the ami id"
return
fi

# Delete the ami id annotation from peer-pods-cm configmap
kubectl annotate configmap peer-pods-cm -n openshift-sandboxed-containers-operator \
"LATEST_AMI_ID-" ||
error_exit "Failed to delete the ami id annotation from peer-pods-cm configmap"

echo "Ami id annotation deleted from peer-pods-cm configmap successfully"
}


# Function to create the ami in AWS

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

# Remove the ami id annotation from peer-pods-cm configmap
delete_ami_id_annotation_from_peer_pods_cm

}

# display help message
Expand Down
6 changes: 4 additions & 2 deletions config/peerpods/podvm/azure-podvm-image-handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ function add_image_id_annotation_to_peer_pods_cm() {
fi

# Add the image id as annotation to peer-pods-cm configmap
kubectl annotate configmap peer-pods-cm -n openshift-sandboxed-containers-operator \
# Overwrite any existing values
kubectl annotate --overwrite configmap peer-pods-cm -n openshift-sandboxed-containers-operator \
"LATEST_IMAGE_ID=${IMAGE_ID}" ||
error_exit "Failed to add the image id as annotation to peer-pods-cm configmap"

Expand Down Expand Up @@ -442,7 +443,8 @@ function add_image_gallery_annotation_to_peer_pods_cm() {
fi

# Add IMAGE_GALLERY_NAME annotation to peer-pods-cm configmap
kubectl annotate configmap peer-pods-cm -n openshift-sandboxed-containers-operator \
# Overwrite any existing values
kubectl annotate --overwrite configmap peer-pods-cm -n openshift-sandboxed-containers-operator \
"IMAGE_GALLERY_NAME=${IMAGE_GALLERY_NAME}" ||
error_exit "Failed to add the IMAGE_GALLERY_NAME annotation to peer-pods-cm configmap"

Expand Down