konveyor / move2kube-api

HTTP REST API for move2kube
https://move2kube.konveyor.io/
Apache License 2.0
6 stars 18 forks source link

No feedback when error occur during planning execution #159

Closed gabriel-farache closed 2 weeks ago

gabriel-farache commented 4 months ago

Describe the bug When the plan command fails, there is no status change nor feedback given to the user; when getting the plan via the API, we still get 204 response code instead of an error

To Reproduce Steps to reproduce the behavior:

  1. Create a workspace and a project
  2. Start a plan via the API with invalid input with remote source, ie: wrong url so the plan will fail Command executed should be similar to plan --name a --plan-progress-port 32881 --log-file m2kcli.log --source git+ssh://bitbucket.com/gfarache31/m2k-test@master --disable-local-execution
  3. Check the logs to see the error, something similar to:
    time="2024-03-12T09:47:17Z" level=info msg="plan cmdArgs: [plan --name a --plan-progress-port 32881 --log-file m2kcli.log --source git+ssh://bitbucket.com/gfarache31/m2k-test@master --disable-local-execution]"
    time="2024-03-12T09:47:17Z" level=info msg="Project: 4a3d44ae-ba55-49b9-ae67-9b0b6d66640e; level=info msg=\"Cloning the repository using git into '/tmp/move2kube3232420242/m2ksources' . This might take some time.\""
    time="2024-03-12T09:47:18Z" level=info msg="Project: 4a3d44ae-ba55-49b9-ae67-9b0b6d66640e; level=fatal msg=\"failed to create the plan. Error: \\\"failed to clone the repo 'git+ssh://bitbucket.com/gfarache31/m2k-test@master'. Error: failed to clone using vcs url 'git+ssh://bitbucket.com/gfarache31/m2k-test@master' and clone options {CommitDepth:1 Overwrite:true MaxSize:-1 CloneDestinationPath:/tmp/move2kube3232420242/m2ksources}. Error: failed to perform clone operation using git. Error: repository already exists\\\"\""
    time="2024-03-12T09:47:18Z" level=error msg="failed to update the database after planning finished. Error: \"failed to copy the plan file from /tmp/plan-4a3d44ae-ba55-49b9-ae67-9b0b6d66640e-4058952779/m2k.plan to /move2kube-api/data/projects/4a3d44ae-ba55-49b9-ae67-9b0b6d66640e/inputs/expanded/m2k.plan after planning finished. Error: \\\"failed to open the source file at path \\\\\\\"/tmp/plan-4a3d44ae-ba55-49b9-ae67-9b0b6d66640e-4058952779/m2k.plan\\\\\\\" Error: \\\\\\\"open /tmp/plan-4a3d44ae-ba55-49b9-ae67-9b0b6d66640e-4058952779/m2k.plan: no such file or directory\\\\\\\"\\\"\""
  4. Send a GET request to the plan and see you have a 204 response code instead of a 5XX one as the planning has failed

Expected behavior I expect that plan status to change to failed or similar and to be able to get the error information via the API (maybe not the full reason but at least that it failed)

Screenshots N/A

Desktop (please complete the following information):

Additional context Related to https://github.com/konveyor/move2kube-ui/issues/169

rgolangh commented 1 month ago

@ashokponkumar any chance this bug will be handled?

ashokponkumar commented 1 month ago

@seshapad @HarikrishnanBalagopal Any thoughts on a fix for this issue?

gabriel-farache commented 3 weeks ago

FYI, it appears that the logs in the log file m2kcli.log are the same as the one in the output So the issue may come from the move2kube CLI itself

gabriel-farache commented 3 weeks ago

The weird error originates from here https://github.com/konveyor/move2kube/blob/main/common/vcs/git.go#L260 Here, m2k is retrying to clone the repo but not on the target branch directly but the directory is not cleaned so it appears the directory that should have host/contained the cloned repository was created so when we try to clone again, it fails because a folder with the same name already exists.

By setting the loc to Warning instead of Debug I see the follwing log:

time="2024-07-05T14:58:48Z" level=info msg="Project: 80cc87ba-5c30-42ac-ac79-e9ad29bf9237; level=info msg=\"failed to clone the given branch 'masters': \\\"couldn't find remote ref \\\\\\\"refs/heads/masters\\\\\\\"\\\" . Will clone the entire repo and try again.\""

which confirm my above assumption.

I'll create a PR to clean the folder and to better log what is happening

ashokponkumar commented 3 weeks ago

Thanks @gabriel-farache . Please let us know when the PR is ready for review

gabriel-farache commented 2 weeks ago

@ashokponkumar My PR is ready for review, please let me know your feedback.

gabriel-farache commented 1 week ago

@ashokponkumar do you know when a new release with the fixes can be released?

ashokponkumar commented 1 week ago

@ashokponkumar do you know when a new release with the fixes can be released?

@HarikrishnanBalagopal @seshapad Can we please trigger a new release?

HarikrishnanBalagopal commented 1 week ago

@ashokponkumar do you know when a new release with the fixes can be released?

@HarikrishnanBalagopal @seshapad Can we please trigger a new release?

Have triggered a new release.

gabriel-farache commented 4 days ago

@HarikrishnanBalagopal Thank you! Now I see a v0.3.14-rc.0 tag in quay, should I use this or should I wait for the v0.3.14?