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: ensure cloning workingdir before calling plan api #3584

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

terakoya76
Copy link

@terakoya76 terakoya76 commented Jul 7, 2023

what

Fix #2949 by cloning the working dir before processing plan/apply api call.

why

As reported in #2949, when calling plan/apply from api, if the target workingdir has not been cloned by atlantis, an error occurs and plan/apply cannot be performed.

Specifically, if an error is returned when executing the buildProjectPlanCommand method GetWorkingDir, the event reported in Issue.

defaultRepoDir, err := p.WorkingDir.GetWorkingDir(ctx.Pull.BaseRepo, ctx.Pull, DefaultWorkspace)

This makes it particularly difficult to execute plan/api from a lifecycle outside of a pull request. This patch allows developers to use the api to build drift detection mechanisms, etc.

tests

Added unit tests.

And locally tested with the payload like this.

curl -X POST -H 'X-Atlantis-Token: mysecret' -H 'Content-Type: application/json' 'http://localhost:4141/api/plan' -d '{
  "Type": "Github",
  "Repository": "myorg/myrepo",
  "Ref": "main",
  "Projects": ["test"],
  "Paths": [{
    "Workspace": "test",
    "Directory": "./"
  }]
}'

references

closes #2949

@terakoya76 terakoya76 requested a review from a team as a code owner July 7, 2023 12:40
@github-actions github-actions bot added the go Pull requests that update Go code label Jul 7, 2023
result, err := a.apiPlan(request, ctx)
if err != nil {
a.apiReportError(w, http.StatusInternalServerError, err)
return
}
defer a.Locker.UnlockByPull(ctx.HeadRepo.FullName, 0) // nolint: errcheck
defer a.Locker.UnlockByPull(ctx.HeadRepo.FullName, ctx.Pull.Num) // nolint: errcheck
Copy link
Author

Choose a reason for hiding this comment

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

#2465 introduced a lock for each PR, but the release of the lock appears to have been omitted.

@terakoya76
Copy link
Author

Ready to be reviewed.

@terakoya76
Copy link
Author

Although the failing check seems irrelevant to my change, should I take some actions?

@jamengual
Copy link
Contributor

@GenPage

@MichaelKora
Copy link

@terakoya76 any updates here?

@GenPage
Copy link
Member

GenPage commented Aug 1, 2023

I will be reviewing this week

@GenPage
Copy link
Member

GenPage commented Aug 14, 2023

I did review this, but I have some reservations about introducing another "Clone" while we are still trying to figure out clones and project locks in #3345.

We will internally discuss further within the maintainer team.

@jamengual jamengual added the needs discussion Large change that needs review from community/maintainers label Sep 27, 2023
@rgs1
Copy link

rgs1 commented Nov 17, 2023

FWIW, testing this internally along with #3985 plus atlantis-drift-detection seems to working for us. We'll put some load on it and see if it's reliable.

@rgs1
Copy link

rgs1 commented May 15, 2024

We've been using for more than a few months now, still looking good.

@GenPage
Copy link
Member

GenPage commented Jun 26, 2024

@runatlantis/core-contributors please review

@GenPage GenPage requested review from a team, lukemassa and nitrocode and removed request for a team June 26, 2024 05:04
@GenPage GenPage added the waiting-on-review Waiting for a review from a maintainer label Jun 26, 2024
@X-Guardian
Copy link
Contributor

@terakoya76, can you resolve the conflicts on this?

@X-Guardian X-Guardian added waiting-on-response Waiting for a response from the user and removed waiting-on-review Waiting for a review from a maintainer labels Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code needs discussion Large change that needs review from community/maintainers waiting-on-response Waiting for a response from the user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/api/plan does not create workspace if it does not exist
6 participants