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

Checkout Strategy Merge - Merging before a plan #979

Closed
Charg opened this issue Apr 6, 2020 · 10 comments · Fixed by #3187
Closed

Checkout Strategy Merge - Merging before a plan #979

Charg opened this issue Apr 6, 2020 · 10 comments · Fixed by #3187
Labels
question Further information is requested

Comments

@Charg
Copy link

Charg commented Apr 6, 2020

First, huge thanks to the creators and maintainers of this project. Atlantis is helping us create a more autonomous engineering org.


Our Configuration
We have checkoutStrategy: merge set in our helm definition

The Question
In production we had two PRs (same repo) open against the same project/workspace/directory. The locking worked as expected, and locked the first PR (PR1) project. The second PR (PR2) is created and gets a message notifying it that the project is locked.

Work continued on PR1 and eventually we ran atlantis apply and merged to master. This lifted the lock from PR1.

Since the lock was lifted we were now able to run atlantis plan on PR2. The output from the plan showed deletions from the work that was just merged in PR1.

Is this the expected behavior, even with the checkoutStrategy set to merge?

@lkysow
Copy link
Member

lkysow commented Apr 6, 2020

This sounds like #804 which was somewhat mitigated by #867. Did you see the diverge warning on your plan?

@lkysow lkysow added the question Further information is requested label Apr 6, 2020
@Charg
Copy link
Author

Charg commented Apr 7, 2020

Yes, the comment from atlantis did contain a waning about the branch diverging. That's awesome, I didn't know that warning existed.

What are your thoughts on adding an option to always force clone on divergence? Maybe adding a new checkout strategy called merge-always.

@lkysow
Copy link
Member

lkysow commented Apr 7, 2020

I don't think that will work. There's some concerns I had in the original ticket. Basically we're not guaranteed to have the whole PR locked, maybe only some directories, so when it's unlocked some of the directories might be half way through a plan or apply cycle and we can't reclone for those projects.

@Charg
Copy link
Author

Charg commented Apr 15, 2020

After looking at the code I see what you're talking about. I wonder if each project should be its own branch off of the PR branch. The branch doesn't really have to exist after the plan is generated 🤔 But that's a decent size change and another conversation.

In this case, what are your thoughts on taking the divergence option a step further and having an option to block applies if divergence is detected? This would add an extra safety net preventing users from shooting themselves in the foot if they accidentally don't notice that they are removing objects because they glanced over the warning.

@lkysow
Copy link
Member

lkysow commented Apr 16, 2020

Sure that could work. You could also set "require branches be up to date" in github (or your vcs) and then use the mergeable apply requirement.

@enummela
Copy link

enummela commented May 4, 2021

I ran into this situation as well. For now I'm simply wondering if any method exists such that a user could make Atlantis reclone when the branch diverges? Here are a couple of methods I suspect might cause a reclone:

  • In the PR run unlock and then plan.
  • Close the PR and then open a new one.

If someone could confirm then it would be much appreciated 🙂

@dupuy26
Copy link
Contributor

dupuy26 commented Jul 7, 2021

Closing the PR and opening a new one would definitely solve any divergence, especially if the new PR is based on master (but with merge strategy it should work even if the new PR has the same old branch point as the old PR).

As far as I know, running unlock does not re-clone or re-merge, but that would be a reasonable thing to do, and since a global (not per-project) unlock also discards all plans, it should be safe to re-clone/re-merge from master when that is done (doing the re-clone/re-merge on plan commands can be undesirable, especially for per-project planning).

@bschaeffer
Copy link
Contributor

This feels a bit unresolved to me. If atlantis has a lock on PR for a project, and there are other competing projects, shouldn't merging always be a valid strategy.

I am struggling to think of a situation where always merging against master is an invalid approach. If PR1 has the lock, PR2 makes changes in the same project, atlantis IS guaranteeing that PR2s changes won't be merged and reverted by a PR1 atlantis apply. If that paradigm can't be trusted, if we can't rely on locking to ensure valid plans, then what are the locks even for?

@bschaeffer
Copy link
Contributor

bschaeffer commented Feb 14, 2022

I guess I just want a solution where I merge PR1 and PR2 does not try to revert the changes PR1 just landed. How do we configure atlantis to do the right thing and never revert changes that have landed and been applied in master?

@bschaeffer
Copy link
Contributor

bschaeffer commented Feb 14, 2022

Actually, the more I think about it, PR2 cannot be planned at all until PR1 is merged, so the merging and the files changing are guaranteed and it seems like a bug to not rebase against the latest master when planning.

finnag added a commit to finnag/atlantis that referenced this issue Mar 3, 2023
The current "merge" checkout strategy is unsafe. It merges the PR and the base
branch without holding the directory lock(s), so there is a potentially
very long window where another PR can be applied and be unexpectedly reverted
later.

This happens occasionally if a PR causes plans in multiple directories, but
is almost _guaranteed_ to happen if the initial plan has to wait until a
lock is freed up and a manual "atlantis plan" command is given.

Instead of printing a warning when this happens, we now merge again
if necessary while holding the lock. Plans are then guaranteed to only
be made when merged with the base branch for each directory being planned,
and applying later should be safe even if the base branch sees further
updates.

This fixes/affects runatlantis#804, runatlantis#867, runatlantis#979
finnag added a commit to finnag/atlantis that referenced this issue Mar 21, 2023
The current "merge" checkout strategy is unsafe. It merges the PR and the base
branch without holding the directory lock(s), so there is a potentially
very long window where another PR can be applied and be unexpectedly reverted
later.

This happens occasionally if a PR causes plans in multiple directories, but
is almost _guaranteed_ to happen if the initial plan has to wait until a
lock is freed up and a manual "atlantis plan" command is given.

Instead of printing a warning when this happens, we now merge again
if necessary while holding the lock. Plans are then guaranteed to only
be made when merged with the base branch for each directory being planned,
and applying later should be safe even if the base branch sees further
updates.

This fixes/affects runatlantis#804, runatlantis#867, runatlantis#979
nitrocode pushed a commit that referenced this issue Mar 25, 2023
…n base update (#3187)

* merge again if base branch has been updated

The current "merge" checkout strategy is unsafe. It merges the PR and the base
branch without holding the directory lock(s), so there is a potentially
very long window where another PR can be applied and be unexpectedly reverted
later.

This happens occasionally if a PR causes plans in multiple directories, but
is almost _guaranteed_ to happen if the initial plan has to wait until a
lock is freed up and a manual "atlantis plan" command is given.

Instead of printing a warning when this happens, we now merge again
if necessary while holding the lock. Plans are then guaranteed to only
be made when merged with the base branch for each directory being planned,
and applying later should be safe even if the base branch sees further
updates.

This fixes/affects #804, #867, #979

* Remove diverged test that no longer applies

* Reinstate TestClone_MasterHasDiverged test and make it pass

* Extend TestClone_MasterHasDiverged to test new merging functionality

We now verify that the first Clone with CheckoutMerge=true with
a diverged base branch atually clones and merges again.

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
nitrocode pushed a commit that referenced this issue May 5, 2023
…n base update (#3187)

* merge again if base branch has been updated

The current "merge" checkout strategy is unsafe. It merges the PR and the base
branch without holding the directory lock(s), so there is a potentially
very long window where another PR can be applied and be unexpectedly reverted
later.

This happens occasionally if a PR causes plans in multiple directories, but
is almost _guaranteed_ to happen if the initial plan has to wait until a
lock is freed up and a manual "atlantis plan" command is given.

Instead of printing a warning when this happens, we now merge again
if necessary while holding the lock. Plans are then guaranteed to only
be made when merged with the base branch for each directory being planned,
and applying later should be safe even if the base branch sees further
updates.

This fixes/affects #804, #867, #979

* Remove diverged test that no longer applies

* Reinstate TestClone_MasterHasDiverged test and make it pass

* Extend TestClone_MasterHasDiverged to test new merging functionality

We now verify that the first Clone with CheckoutMerge=true with
a diverged base branch atually clones and merges again.

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
ijames-gc pushed a commit to gocardless/atlantis that referenced this issue Feb 13, 2024
…n base update (runatlantis#3187)

* merge again if base branch has been updated

The current "merge" checkout strategy is unsafe. It merges the PR and the base
branch without holding the directory lock(s), so there is a potentially
very long window where another PR can be applied and be unexpectedly reverted
later.

This happens occasionally if a PR causes plans in multiple directories, but
is almost _guaranteed_ to happen if the initial plan has to wait until a
lock is freed up and a manual "atlantis plan" command is given.

Instead of printing a warning when this happens, we now merge again
if necessary while holding the lock. Plans are then guaranteed to only
be made when merged with the base branch for each directory being planned,
and applying later should be safe even if the base branch sees further
updates.

This fixes/affects runatlantis#804, runatlantis#867, runatlantis#979

* Remove diverged test that no longer applies

* Reinstate TestClone_MasterHasDiverged test and make it pass

* Extend TestClone_MasterHasDiverged to test new merging functionality

We now verify that the first Clone with CheckoutMerge=true with
a diverged base branch atually clones and merges again.

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
ijames-gc pushed a commit to gocardless/atlantis that referenced this issue Feb 13, 2024
…n base update (runatlantis#3187)

* merge again if base branch has been updated

The current "merge" checkout strategy is unsafe. It merges the PR and the base
branch without holding the directory lock(s), so there is a potentially
very long window where another PR can be applied and be unexpectedly reverted
later.

This happens occasionally if a PR causes plans in multiple directories, but
is almost _guaranteed_ to happen if the initial plan has to wait until a
lock is freed up and a manual "atlantis plan" command is given.

Instead of printing a warning when this happens, we now merge again
if necessary while holding the lock. Plans are then guaranteed to only
be made when merged with the base branch for each directory being planned,
and applying later should be safe even if the base branch sees further
updates.

This fixes/affects runatlantis#804, runatlantis#867, runatlantis#979

* Remove diverged test that no longer applies

* Reinstate TestClone_MasterHasDiverged test and make it pass

* Extend TestClone_MasterHasDiverged to test new merging functionality

We now verify that the first Clone with CheckoutMerge=true with
a diverged base branch atually clones and merges again.

---------

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants