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

Fix the failed to mv error on python s2i #10

Merged
merged 6 commits into from Jan 21, 2019

Conversation

anmolbabu
Copy link
Contributor

@anmolbabu anmolbabu commented Dec 12, 2018

The error happens when the local component source contains
a directory by name s2i. This fix clears the $APP_ROOT of
all files and folders before the assemble script copies
over sources from $destination dir to $app-root so that
mv from assemble script does not compile that the folder
already exists

fixes redhat-developer/odo#1054
Signed-off-by: anmolbabu anmolbudugutta@gmail.com

@anmolbabu
Copy link
Contributor Author

This breaks watch :(

@cdrage
Copy link
Member

cdrage commented Dec 13, 2018

Hey @anmolbabu can you please rebase to master? Tests had broken before.. See #11

@anmolbabu
Copy link
Contributor Author

anmolbabu commented Dec 14, 2018

Working approach for source deployments :

  1. Use backup-dir(/opt/app-root-src-backup) to backup source in $ODO_S2I_SRC_BIN_PATH..
  2. rm -fr contents of $APP_ROOT/src so that assemble does not complain error in Python component push consistently fails to update source after the first successful push odo#1054
  3. Trigger assemble script
  4. Copy back source from /opt/app-root-src-backup to $APP_ROOT

This way, the sources from $ODO_S2I_SRC_BIN_PATH are backed up before being moved to $APP_ROOT from which the sources will be deleted to void error in redhat-developer/odo#1054 before the same being movede over from $ODO_S2I_SRC_BIN_PATH(which empties it for the next iteration of watch)

ToDo: Verification of the method being fool proof for every runtime and different combinations of watch and push triggered for binary and local source

@cdrage
Copy link
Member

cdrage commented Dec 14, 2018

@anmolbabu

It looks like the tests are working as intended (I see that it failed in two sections..)

Make sure you look at @kadel 's PR too as he restores from backup so it may conflict with regards to your PR.

assemble-and-restart Outdated Show resolved Hide resolved
assemble-and-restart Outdated Show resolved Hide resolved
@anmolbabu anmolbabu force-pushed the fixes#1054 branch 3 times, most recently from 4f49cc6 to 643371e Compare December 21, 2018 16:35
@anmolbabu anmolbabu requested review from cdrage, kadel, surajnarwade and mik-dass and removed request for cdrage December 22, 2018 13:23
@anmolbabu anmolbabu force-pushed the fixes#1054 branch 3 times, most recently from d317677 to c6cd563 Compare December 23, 2018 06:57
@anmolbabu
Copy link
Contributor Author

@anmolbabu

It looks like the tests are working as intended (I see that it failed in two sections..)

Make sure you look at @kadel 's PR too as he restores from backup so it may conflict with regards to your PR.

@cdrage Ack
Fortunately those lines remained untouched in my PR ;) So hopefully they shouldn't conflict

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Tested and works!

fi
done
# In case of java clear off the target directory
rm -fr ${ODO_S2I_SRC_BIN_PATH}/src/target
Copy link
Contributor

Choose a reason for hiding this comment

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

This is needed because java s2i does not delete the previous compilation output. If this weren't added, then deleted source files would not be reflected in the compilation output

Copy link
Member

Choose a reason for hiding this comment

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

This is java specific, I would like to avoid working with paths that are just for valid just for one type of builder images for now. We need a better way to handle that.

What if my project source that is in a different language contains src/target path for some reason?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, if we don't delete this directory, watch + delete is totally broken for Java.
Perhaps we should wrap the delete call in an if statement that checks if the image is a Java image (by testing for the existence of the mvn binary)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I added the conditional check now
@kadel @geoand can you have a look now if it is ok?

Copy link
Contributor

@geoand geoand Jan 14, 2019

Choose a reason for hiding this comment

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

@anmolbabu I don't think that using "$ODO_S2I_BUILDER_IMG" == "redhat-openjdk-18/openjdk18-openshift" is correct, because the image builder could have a different name, right?
I personally think that testing for the image capabilities (meaning testing if it has the mvn binary) is the correct approach.
An alternative could be perhaps to check for the existence of pom.xml in the pushed source code

Copy link
Contributor

Choose a reason for hiding this comment

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

The only other Java builder we use at the moment is the widlfly one and I haven't checked to see if it uses mvn clean.
My issue is basically with the name - are you sure the builder image name that is injected as an env var will always be the same no matter how I name it in my cluster?

Copy link
Contributor Author

@anmolbabu anmolbabu Jan 14, 2019

Choose a reason for hiding this comment

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

Yeah this is the name of docker image(not the name it is imported as for ex: I have imported it as openjdk18 like in tests) corresponding to s2i image...
So it is likely not to change

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, I'm fine with the change as long as we check and see if widlfly needs the same kind of handling :)

Copy link
Member

Choose a reason for hiding this comment

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

What is exactly the issue that this fixes? I have tried a few Java examples and with this commented out and haven't any issues. Except hitting redhat-developer/odo#1117 again.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kadel To see the problem this fixes you need to do the following:

Use the updated source example from this PR.

odo create ... 
odo push
odo watch

Then delete one of the Java classes. Once the watch picks up the delete, the build should fail (since of the required sources no longer exists).
If you remove this line, then the build does not fail because it retains the previous compiled file

fi
done
# In case of java clear off the target directory
rm -fr ${ODO_S2I_SRC_BIN_PATH}/src/target
Copy link
Member

Choose a reason for hiding this comment

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

This is java specific, I would like to avoid working with paths that are just for valid just for one type of builder images for now. We need a better way to handle that.

What if my project source that is in a different language contains src/target path for some reason?

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Hey @anmolbabu if you can organize the code a bit that'd be great. Add some newlines between code that's different! 👍

@@ -2,6 +2,34 @@
set -x
set -eo pipefail

# If WorkingDir is injected as an env from odo and destination path is not equal to WorkingDir injected by odo
Copy link
Member

Choose a reason for hiding this comment

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

This sentence is confusing..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack I will fix it

if [ ! -d ${ODO_SRC_BACKUP_DIR} ]; then
mkdir -p ${ODO_SRC_BACKUP_DIR}/src
fi
# Backup the sources in DestinationDir to ODO_SRC_BACKUP_DIR bcoz the assemble script for some s2i images
Copy link
Member

Choose a reason for hiding this comment

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

bcoz = because

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

rm -fr $ODO_S2I_WORKING_DIR/$file
fi
done
# In case of java clear off the target directory
Copy link
Member

Choose a reason for hiding this comment

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

This is oddly specific... is there any way to make this more generic or do we actually have to hard-code in openjdk support?

This will be a future problem when newer versions of openjdk is released in the future of if the image name changes

Copy link
Contributor

Choose a reason for hiding this comment

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

Clearing off the output directory should not cause any problems, even if the builder image does this on it's own

Copy link
Contributor

Choose a reason for hiding this comment

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

@anmolbabu
Copy link
Contributor Author

anmolbabu commented Jan 16, 2019

Don't know how to test, but want to make sure this would work:

When doing odo push and it's building, hit CTRL-C and break the execution of odo push. In current release, somehow backup dir is preserved (or saved, don't remember which) and further builds didn't work.

@jorgemoralespou I would say not in the scope of this PR
Do you mean hot Ctrl+c should break even an already executing assemble script?
odo doesn't intercept SIGINT at the moment I am not sure if there's a way to do it in Go(I have seen it in python though) so may be I can write a new PR for that bcoz I am really not sure how the SIGINT even if caught, can even be communicated to the component pod where the assemble is under execution

Cc: @kadel @cdrage @surajnarwade

IFS=$b_IFS

# In case of java clear off the target directory
if [ -n "$ODO_S2I_BUILDER_IMG" ] && [ "$ODO_S2I_BUILDER_IMG" == "redhat-openjdk-18/openjdk18-openshift" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

@anmolbabu please add TODO comment so we don't forget that this is a temporary hack and we need to find a proper solution for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

@kadel
Copy link
Member

kadel commented Jan 17, 2019

@jorgemoralespou I would say not in the scope of this PR

This PR is already a significant change (because it is tight to redhat-developer/odo#1125) Let's fix this right after we are done with this.

Do you mean hot Ctrl+c should break even an already executing assemble script?
odo doesn't intercept SIGINT at the moment I am not sure if there's a way to do it in Go(I have seen it in python though) so may be I can write a new PR for that bcoz I am really not sure how the SIGINT even if caught, can even be communicated to the component pod where the assemble is under execution

We need to fix it, this was not an issue before we started doing all this backup and restore charades.
Odo should never leave component in a broken state where the only way to fix it is to delete the whole component.

@kadel
Copy link
Member

kadel commented Jan 17, 2019

@jorgemoralespou I just compiled odo with redhat-developer/odo#1125 that uses image from this PR to make it easy to test this anywhere.

You can download it here odo.zip ( It is compiled just for MacOS)

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Did some light testing, this LGTM 👍 code + comments + implementation.

@kadel kadel dismissed their stale review January 17, 2019 21:29

good enough, don't block on me, but we need another review

@anmolbabu
Copy link
Contributor Author

@kadel All comments incoporated please review

@metacosm
Copy link

I don't feel qualified to review this PR, sorry.

The error happens when the local component source contains
a directory by name s2i. This fix clears the $APP_ROOT of
all files and folders before the assemble script copies
over sources from $destination dir to $app-root so that
mv from assemble script does not compile that the folder
already exists

fixes redhat-developer/odo#1054
Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
run Outdated
if [ -d /opt/app-root/backup ] && [ -n "$ODO_S2I_DEPLOYMENT_DIR" ]; then
cp -rf /opt/app-root/backup/. ${ODO_S2I_DEPLOYMENT_DIR}/
if [ -d ${ODO_DEPLOYMENT_BACKUP_DIR} ] && [ -n "$ODO_S2I_DEPLOYMENT_DIR" ]; then
cp -rf ${ODO_DEPLOYMENT_BACKUP_DIR}/. ${ODO_S2I_DEPLOYMENT_DIR}/

Choose a reason for hiding this comment

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

Why everywhere in assemble-and-restart this has changed to rsync, but here it has remained as cp? same performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now

Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
@kadel
Copy link
Member

kadel commented Jan 21, 2019

Tests are failing because the new image is not compatible with current odo. (It requires redhat-developer/odo#1125 to work properly)

run Outdated
if [ -d /opt/app-root/backup ] && [ -n "$ODO_S2I_DEPLOYMENT_DIR" ]; then
cp -rf /opt/app-root/backup/. ${ODO_S2I_DEPLOYMENT_DIR}/
if [ -d ${ODO_DEPLOYMENT_BACKUP_DIR} ] && [ -n "$ODO_S2I_DEPLOYMENT_DIR" ]; then
rsync -r ${ODO_DEPLOYMENT_BACKUP_DIR}/. ${ODO_S2I_DEPLOYMENT_DIR}/
Copy link
Member

Choose a reason for hiding this comment

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

it would be better to use rsync -a to make sure that it is really identical copy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

fi
cp -rf ${ODO_S2I_DEPLOYMENT_DIR}/. /opt/app-root/backup/

rsync -r ${ODO_S2I_DEPLOYMENT_DIR}/. ${ODO_DEPLOYMENT_BACKUP_DIR}/
Copy link
Member

Choose a reason for hiding this comment

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

it would be better to use rsync -a to make sure that it is really identical copy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

# After assemble script is run(which delets sources from destination dir by doing mv of them to the WorkingDir) and if only its component created from source,
# copy back the sources from Source backup dir to DestinationDir for subsequent push of only updates by watch
if [ ! -z "${ODO_S2I_WORKING_DIR}" ] && [ -n "$ODO_SRC_BACKUP_DIR" ] && ([ "${ODO_S2I_SRC_BIN_PATH}" != "${ODO_S2I_WORKING_DIR}" ] || [ "${ODO_S2I_DEPLOYMENT_DIR}" != "${ODO_S2I_WORKING_DIR}" ]); then
rsync -r ${ODO_SRC_BACKUP_DIR}/src/. ${ODO_S2I_SRC_BIN_PATH}/src/
Copy link
Member

Choose a reason for hiding this comment

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

it would be better to use rsync -a to make sure that it is really identical copy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

# Backup the sources in DestinationDir to ODO_SRC_BACKUP_DIR because the assemble script for some s2i images
# moves sources from DestinationDir to WorkingDir thereby deleting it there(DestinationDir). So, back it up
# for partial push use cases like watch
rsync -r ${ODO_S2I_SRC_BIN_PATH}/src/. ${ODO_SRC_BACKUP_DIR}/src/
Copy link
Member

Choose a reason for hiding this comment

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

it would be better to use rsync -a to make sure that it is really identical copy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Signed-off-by: anmolbabu <anmolbudugutta@gmail.com>
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.

Python component push consistently fails to update source after the first successful push
6 participants