Skip to content
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

Allow for additional disc_formats #374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stephenmoloney
Copy link
Contributor

@stephenmoloney stephenmoloney commented Apr 18, 2018

Motivation

  • raw images cannot be uploaded to some openstack providers (ones using ceph i think)

Description

  • Adds functionality for
    1. Specifying the format for upload
    2. Converting the image to another format
    3. Uploading the resultant image

Style

  • This MR is a bit of a dramatic change in the code style.. I'm a big fan of functional programming, hence all the functions as it encapsulates logic into smaller parts. I'll rewrite it for just plain script if needed.

@@ -5,6 +5,7 @@ kubeadm_token = "your-kubeadm-token" # Autogenerated kubeadm token (don't change
floating_ip_pool = "your-pool-name"
external_network_uuid = "external-net-uuid" # The uuid of the external network in the OpenStack tenancy
boot_image = "kubenow-v050"
disc_format = "raw"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably change the default format to "qcow2" - for now it's raw while I'm testing.. but I can change this at the end to "qcow2"

  • changed to qcow2

image_size_number=$(echo "${image_size::-1}")

if [[ "${disc_format}" == "raw" ]]; then
min_disc=${image_size_number};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if min_disc needs to be reset or not based on the new image size ?

I'm seeing issues with insufficient ram as the image is very big (20GB) but i'm not 100% sure yet. I'm investigating this further at the moment.

@stephenmoloney stephenmoloney force-pushed the fix/disc_format branch 2 times, most recently from 03b9f28 to ce35d29 Compare April 18, 2018 22:27
@stephenmoloney stephenmoloney changed the title WIP: changes for uploading disc_format WIP: Allow for additional disc_formats Apr 18, 2018
Copy link
Member

@mcapuccini mcapuccini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far! Just some minor comments. I really appreciate the effort you have made in refactorying the script with the helper functions. I suggest @andersla to review in detail, as he has mostly worked to this script.

@@ -35,6 +35,7 @@ RUN apt-get update -y && apt-get install -y \
libffi-dev \
openssl \
python-pip \
qemu-utils \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check how much this affects the Docker image size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure.. this is how it reads from docker image ls

kubenow/provisioners   master              8b17915e9767        2 days ago          1.09GB
kubenow/provisioners   0.3.2               dc845cc33fea        7 days ago          1.02GB

set -e

source ./bin/openstack/functions.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant! We wanted to this a while ago, but we never had time. Maybe we could call the file ./bin/helpers/openstack.sh? In this way we could have similar refactory for the other import scripts in the future (btw, if you feel like refactorying the other providers as well, it would be much appreciated).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I've changed the filename as suggested. I was thinking that it's a bit annoying having one provider use this pattern and the rest do not... but I don't have time to refactor the others for now anyways... thanks for the offer though ! 😃 :

@@ -5,6 +5,7 @@ kubeadm_token = "your-kubeadm-token" # Autogenerated kubeadm token (don't change
floating_ip_pool = "your-pool-name"
external_network_uuid = "external-net-uuid" # The uuid of the external network in the OpenStack tenancy
boot_image = "kubenow-v050"
disc_format = "raw"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be commented, or defaulting to qcow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will default it to "qcow2" .. changing.

@stephenmoloney stephenmoloney force-pushed the fix/disc_format branch 3 times, most recently from 9346e55 to 5311bc6 Compare April 21, 2018 10:42
@stephenmoloney stephenmoloney changed the title WIP: Allow for additional disc_formats Allow for additional disc_formats Apr 21, 2018
@stephenmoloney
Copy link
Contributor Author

Note: I made some final changes this weekend. It's ready for review now.

Copy link
Member

@andersla andersla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for your contribution! Some minor suggestions.


function get_host_uploaded_image_checksum() {
local image_name=$1
local disc_format=$2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion with image format on image downloaded change "disk_format" to "glance_disk_format"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 - i did this for all disc_format - i presume that is what you mean ?


function verify_uploaded_image() {
local image_name=$1
local disc_format=$2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion with image format on image downloaded change "disk_format" to "glance_disk_format"


function upload_image() {
local image_name=$1
local disc_format=$2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion with image format on image downloaded change "disk_format" to "glance_disk_format"


function post_image_upload_checks() {
local image_name=$1
local disc_format=$2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion with image format on image downloaded change "disk_format" to "glance_disk_format"


function maybe_convert_image(){
local image_name=$1
local disc_format=$2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion with image format on image downloaded change "disk_format" to "glance_disk_format"

awk -F "|" '{print $3;}' |
tr -d '[:space:]')"
done
maybe_download_image "${image_name}" "${disc_format}" "${bucket_url}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first check if image is present on openstack - if it is there skip everything (no need to download image to local host if it is on server already)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch - i've made this change as suggested.

echo "Starting the image conversion from qcow2 to ${disc_format}..."
echo -e "\n"

qemu-img convert -q -f qcow2 -O "${disc_format}" "${download_filepath}" "${upload_filepath}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add echo "Image convertion complete"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added something quite similar echo "${image_name}.qcow2 conversion to ${upload_filepath} complete"

qemu-img convert -q -f qcow2 -O "${disc_format}" "${download_filepath}" "${upload_filepath}"
fi
else
echo "${upload_filepath} already exists and so does not require conversion, moving onto upload step"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete ", moving onto upload step
(We don't really know what function will be called after this one)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. very much agree. changed.

tr -d '[:space:]')"
done
maybe_download_image "${image_name}" "${disc_format}" "${bucket_url}"
maybe_convert_image "${image_name}" "${disc_format}" "${bucket_url}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skip call to "maybe_convert_image" in "image-create-openstack" since it will be called in "maybe_upload_image" anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed maybe_upload_image now ... because now the function is wrapped in a conditional is_image_already_uploaded - make sense?

if [[ "${is_image_uploaded}" == "false" ]]; then
maybe_convert_image "${image_name}" "${disc_format}" "${image_url}"
upload_image "${image_name}" "${disc_format}" "${image_url}"
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only call "post_image_upload_checks" from function "upload_image" (don't call if image is uploaded already previously - checksum could be different since same version image can have different checksums due to security updates)
(remove else block)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this function is removed bu the logic for it has moved to image-create-openstack.sh.

  • I've moved post_image_upload_checks into upload image.

  • If we remove the else block then this line
    echo "${image_name}.${glance_disc_format} is already present - no need to upload" also gets removed - perhaps it's better to keep this as it signals to the user that the entire process for uploading the openstack image will be bypassed ?

@stephenmoloney
Copy link
Contributor Author

Hi Anders, thanks for the review, going to read the review soon...

@stephenmoloney stephenmoloney force-pushed the fix/disc_format branch 8 times, most recently from dc33a7e to e7459f0 Compare May 30, 2018 22:36
@stephenmoloney
Copy link
Contributor Author

@andersla can you review again, I made most of.the suggested changes. Thanks

@stephenmoloney stephenmoloney force-pushed the fix/disc_format branch 2 times, most recently from 2d805ee to dc70951 Compare May 31, 2018 10:16
@andersla
Copy link
Member

Hi Stephen, I haven't forgotten you - I am just in a lot of other work right now:-)

@mcapuccini mcapuccini added this to the 0.4.0 milestone Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants