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 5 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

@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
Copy link

This issue is stale because it has been open for 1 month with no activity. Remove stale label or comment or this will be closed in 1 month.

@github-actions github-actions bot added the Stale label Dec 10, 2024
@jamengual jamengual removed the Stale label Dec 10, 2024
@nitrocode nitrocode requested a review from a team as a code owner December 10, 2024 22:13
server/server.go Outdated Show resolved Hide resolved
@jamengual
Copy link
Contributor

@terakoya76, could you sign the commits to give this another review?

@jamengual jamengual added the api-endpoints Adding API endpoints to Atlantis label Dec 31, 2024
@terakoya76
Copy link
Author

Thanks for all the coordination.
I will add the signoff message to past commits.

@terakoya76
Copy link
Author

terakoya76 commented Dec 31, 2024

I failed to leave recent merge commits in place and only sign off messages on past commits.
As a result, the merge commits disappeared. Sorry about that.
But the contents should be the same.

@jamengual
Copy link
Contributor

@terakoya76 could you check the status checks? some of them are failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-endpoints Adding API endpoints to Atlantis blog build Relating to how we build Atlantis dependencies PRs that update a dependency file docs Documentation github-actions go Pull requests that update Go code needs discussion Large change that needs review from community/maintainers provider/azuredevops provider/bitbucket provider/github provider/gitlab waiting-on-response Waiting for a response from the user website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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