-
Notifications
You must be signed in to change notification settings - Fork 34
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
image-generator: fix image creation edge cases #369
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,10 +44,10 @@ spec: | |
value: aws | ||
- name: PODVM_DISTRO | ||
value: rhel | ||
- name: IMAGE_NAME | ||
value: "peer-pod-ami" | ||
# - name: INSTANCE_TYPE | ||
# value: "t3.small" # default is t3.small, uncomment and modify if not available in your region | ||
# - name: IMAGE_NAME | ||
# value: "aws-podvm-image-name" # set custom image name for custom image if you wish to avoid its deletion | ||
envFrom: | ||
- secretRef: | ||
name: peer-pods-secret | ||
|
@@ -59,6 +59,7 @@ spec: | |
- -c | ||
- | | ||
set -e | ||
[[ ! "${IMAGE_NAME}" ]] && UUID=$(uuidgen) && export IMAGE_NAME="peer-pod-ami-${UUID::6}" && echo "IMAGE_NAME:${IMAGE_NAME}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @snir911 I don't understand the motivation behind the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To preserve previous behavior mostly I think, for example if users wants to specify a name that would be easy for him to track later using AWS cli. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so IMAGE_NAME is a kind of hidden API that we don't want to document for users but we still want to be usable, correct ? It would be very nice to document this in some document for developers at least, or even comments in the yaml files, because the questions in this PR clearly show that it isn't obvious. |
||
dnf install -y make git unzip | ||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
unzip awscliv2.zip | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,13 @@ spec: | |
env: | ||
- name: PODVM_DISTRO | ||
value: rhel | ||
- name: IMAGE_NAME | ||
value: "peer-pod-ami" | ||
command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
set -e | ||
[[ ! "${PODVM_AMI_ID}" ]] && echo "PODVM_AMI_ID is missing, it's unknown which image to delete" && exit 1 | ||
[[ "${IMAGE_NAME}" ]] && echo "IMAGE_NAME:${IMAGE_NAME} is set, it implies image was not automatically created, delete it manually" && exit 0 | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to make sure it is clear in docs as to what happens with manually created images and that user is responsible for deleting them as the message states. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is custom images supported ATM? AFAIK the reason it's supported is for tech/dev-preview features only |
||
dnf install -y unzip | ||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
unzip awscliv2.zip | ||
|
@@ -41,8 +41,8 @@ spec: | |
export MAC=$(curl -m 3 -s http://169.254.169.254/latest/meta-data/mac) | ||
[[ ! "${AWS_REGION}" ]] && export AWS_REGION=$(curl -m 30 -s --show-error http://169.254.169.254/latest/meta-data/placement/region) | ||
[[ ! "${AWS_REGION}" ]] && echo "AWS_REGION is missing" && exit 1 | ||
export IMAGE_NAME=${IMAGE_NAME:-peer-pod-ami} | ||
PODVM_AMI_ID=$(aws ec2 describe-images --query "Images[*].[ImageId]" --filters "Name=name,Values=${IMAGE_NAME}" --region ${AWS_REGION} --output text) && \ | ||
echo "Deleting AMI: ${PODVM_AMI_ID}" | ||
aws ec2 deregister-image --image-id ${PODVM_AMI_ID} --region ${AWS_REGION} | ||
echo "Deleting AMI: ${PODVM_AMI_ID} - DONE" | ||
RES=$(aws ec2 deregister-image --image-id "${PODVM_AMI_ID}" --region "${AWS_REGION}" 2>&1) || ERR=true | ||
echo ${RES} | ||
[[ ${ERR} ]] && [[ "$RES" =~ InvalidAMIID\.(Unavailable|NotFound) ]] # if deregister returned error and image is already deleted, continue | ||
echo "Deleted AMI: ${PODVM_AMI_ID} - DONE" | ||
Comment on lines
+45
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are users supposed to see the error message in the output of the job? Is that captured in a log anywhere? Also a little weird that we say the AMI is deleted when it didn't exist. I feel like there is an "if" statement missing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible to see the error in the job logs, however, in this case the error means image is already deleted and there's nothing else to do which is fine, would it make more sense to change the wording to something like: "image deletion job completed"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Users can see these logs with
This should probably be captured by the OSC must-gather if it isn't the case already.
IIUC the only case where we get the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are not requiring IMAGE_NAME to be explicitly unset we probably need to add that to the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
User shouldn't even know it's possible to set it, this variable is not mentioned in the docs