Skip to content

Commit 77706cb

Browse files
authored
Revert "fix: Delete locks and workdirs with potentially stale previous plans which fixes 1624 (#1704)" (#2316)
This reverts commit 82ac706.
1 parent cd7eb8d commit 77706cb

File tree

5 files changed

+1
-100
lines changed

5 files changed

+1
-100
lines changed

Diff for: runatlantis.io/docs/using-atlantis.md

-5
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ atlantis plan -w staging
4545
* `-w workspace` Switch to this [Terraform workspace](https://www.terraform.io/docs/state/workspaces.html) before planning. Defaults to `default`. If not using Terraform workspaces you can ignore this.
4646
* `--verbose` Append Atlantis log to comment.
4747

48-
::: warning NOTE
49-
A `atlantis plan` (without flags), like autoplans, discards all plans previously created with `atlantis plan` `-p`/`-d`/`-w`
50-
:::
51-
5248
### Additional Terraform flags
5349

5450
If you need to run `terraform plan` with additional arguments, like `-target=resource` or `-var 'foo-bar'` or `-var-file myfile.tfvars`
@@ -69,7 +65,6 @@ Runs `terraform apply` for the plan that matches the directory/project/workspace
6965

7066
::: tip
7167
If no directory/project/workspace is specified, ex. `atlantis apply`, this command will apply **all unapplied plans from this pull request**.
72-
This includes all projects that have been planned manually with `atlantis plan` `-p`/`-d`/`-w` since the last autoplan or `atlantis plan` command.
7368
:::
7469

7570
### Examples

Diff for: server/controllers/events/events_controller_e2e_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,6 @@ func setupE2E(t *testing.T, repoDir string) (events_controllers.VCSEventsControl
872872
locker := events.NewDefaultWorkingDirLocker()
873873
parser := &config.ParserValidator{}
874874

875-
deleteLockCommand := mocks.NewMockDeleteLockCommand()
876-
877875
globalCfgArgs := valid.GlobalCfgArgs{
878876
AllowRepoCfg: true,
879877
MergeableReq: false,
@@ -1027,7 +1025,6 @@ func setupE2E(t *testing.T, repoDir string) (events_controllers.VCSEventsControl
10271025
parallelPoolSize,
10281026
silenceNoProjects,
10291027
boltdb,
1030-
deleteLockCommand,
10311028
)
10321029

10331030
e2ePullReqStatusFetcher := vcs.NewPullReqStatusFetcher(e2eVCSClient)

Diff for: server/events/command_runner_test.go

+1-71
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ func setup(t *testing.T) *vcsmocks.MockClient {
133133
parallelPoolSize,
134134
SilenceNoProjects,
135135
defaultBoltDB,
136-
deleteLockCommand,
137136
)
138137

139138
pullReqStatusFetcher := vcs.NewPullReqStatusFetcher(vcsClient)
@@ -530,77 +529,9 @@ func TestRunUnlockCommandFail_VCSComment(t *testing.T) {
530529
vcsClient.VerifyWasCalledOnce().CreateComment(fixtures.GithubRepo, fixtures.Pull.Num, "Failed to delete PR locks", "unlock")
531530
}
532531

533-
func TestRunAutoplanCommand_DeleteLocksByPull(t *testing.T) {
534-
setup(t)
535-
tmp, cleanup := TempDir(t)
536-
defer cleanup()
537-
boltDB, err := db.New(tmp)
538-
Ok(t, err)
539-
dbUpdater.DB = boltDB
540-
applyCommandRunner.DB = boltDB
541-
autoMerger.GlobalAutomerge = true
542-
defer func() { autoMerger.GlobalAutomerge = false }()
543-
544-
When(projectCommandBuilder.BuildAutoplanCommands(matchers.AnyPtrToEventsCommandContext())).
545-
ThenReturn([]command.ProjectContext{
546-
{
547-
CommandName: command.Plan,
548-
},
549-
{
550-
CommandName: command.Plan,
551-
},
552-
}, nil)
553-
When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}})
554-
When(workingDir.GetPullDir(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn(tmp, nil)
555-
fixtures.Pull.BaseRepo = fixtures.GithubRepo
556-
ch.RunAutoplanCommand(fixtures.GithubRepo, fixtures.GithubRepo, fixtures.Pull, fixtures.User)
557-
deleteLockCommand.VerifyWasCalledOnce().DeleteLocksByPull(fixtures.Pull.BaseRepo.FullName, fixtures.Pull.Num)
558-
}
559-
560-
func TestRunGenericPlanCommand_DeleteLocksByPull(t *testing.T) {
561-
setup(t)
562-
tmp, cleanup := TempDir(t)
563-
defer cleanup()
564-
boltDB, err := db.New(tmp)
565-
Ok(t, err)
566-
dbUpdater.DB = boltDB
567-
applyCommandRunner.DB = boltDB
568-
autoMerger.GlobalAutomerge = true
569-
defer func() { autoMerger.GlobalAutomerge = false }()
570-
571-
When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}})
572-
When(workingDir.GetPullDir(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn(tmp, nil)
573-
pull := &github.PullRequest{State: github.String("open")}
574-
modelPull := models.PullRequest{BaseRepo: fixtures.GithubRepo, State: models.OpenPullState, Num: fixtures.Pull.Num}
575-
When(githubGetter.GetPullRequest(fixtures.GithubRepo, fixtures.Pull.Num)).ThenReturn(pull, nil)
576-
When(eventParsing.ParseGithubPull(pull)).ThenReturn(modelPull, modelPull.BaseRepo, fixtures.GithubRepo, nil)
577-
578-
fixtures.Pull.BaseRepo = fixtures.GithubRepo
579-
ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Plan})
580-
deleteLockCommand.VerifyWasCalledOnce().DeleteLocksByPull(fixtures.Pull.BaseRepo.FullName, fixtures.Pull.Num)
581-
}
582-
583-
func TestRunSpecificPlanCommandDoesnt_DeleteLocksByPull(t *testing.T) {
584-
setup(t)
585-
tmp, cleanup := TempDir(t)
586-
defer cleanup()
587-
boltDB, err := db.New(tmp)
588-
Ok(t, err)
589-
dbUpdater.DB = boltDB
590-
applyCommandRunner.DB = boltDB
591-
autoMerger.GlobalAutomerge = true
592-
defer func() { autoMerger.GlobalAutomerge = false }()
593-
594-
When(projectCommandRunner.Plan(matchers.AnyModelsProjectCommandContext())).ThenReturn(command.ProjectResult{PlanSuccess: &models.PlanSuccess{}})
595-
When(workingDir.GetPullDir(matchers.AnyModelsRepo(), matchers.AnyModelsPullRequest())).ThenReturn(tmp, nil)
596-
fixtures.Pull.BaseRepo = fixtures.GithubRepo
597-
ch.RunCommentCommand(fixtures.GithubRepo, nil, nil, fixtures.User, fixtures.Pull.Num, &events.CommentCommand{Name: command.Plan, ProjectName: "default"})
598-
deleteLockCommand.VerifyWasCalled(Never()).DeleteLocksByPull(fixtures.Pull.BaseRepo.FullName, fixtures.Pull.Num)
599-
}
600-
601532
// Test that if one plan fails and we are using automerge, that
602533
// we delete the plans.
603-
func TestRunAutoplanCommandWithError_DeletePlans(t *testing.T) {
534+
func TestRunAutoplanCommand_DeletePlans(t *testing.T) {
604535
setup(t)
605536
tmp, cleanup := TempDir(t)
606537
defer cleanup()
@@ -643,7 +574,6 @@ func TestRunAutoplanCommandWithError_DeletePlans(t *testing.T) {
643574
ThenReturn(tmp, nil)
644575
fixtures.Pull.BaseRepo = fixtures.GithubRepo
645576
ch.RunAutoplanCommand(fixtures.GithubRepo, fixtures.GithubRepo, fixtures.Pull, fixtures.User)
646-
// gets called twice: the first time before the plan starts, the second time after the plan errors
647577
pendingPlanFinder.VerifyWasCalledOnce().DeletePlans(tmp)
648578
}
649579

Diff for: server/events/plan_command_runner.go

-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func NewPlanCommandRunner(
2222
parallelPoolSize int,
2323
SilenceNoProjects bool,
2424
pullStatusFetcher PullStatusFetcher,
25-
deleteLockCommand DeleteLockCommand,
2625
) *PlanCommandRunner {
2726
return &PlanCommandRunner{
2827
silenceVCSStatusNoPlans: silenceVCSStatusNoPlans,
@@ -40,7 +39,6 @@ func NewPlanCommandRunner(
4039
parallelPoolSize: parallelPoolSize,
4140
SilenceNoProjects: SilenceNoProjects,
4241
pullStatusFetcher: pullStatusFetcher,
43-
deleteLockCommand: deleteLockCommand,
4442
}
4543
}
4644

@@ -66,7 +64,6 @@ type PlanCommandRunner struct {
6664
autoMerger *AutoMerger
6765
parallelPoolSize int
6866
pullStatusFetcher PullStatusFetcher
69-
deleteLockCommand DeleteLockCommand
7067
}
7168

7269
func (p *PlanCommandRunner) runAutoplan(ctx *command.Context) {
@@ -109,13 +106,6 @@ func (p *PlanCommandRunner) runAutoplan(ctx *command.Context) {
109106
ctx.Log.Warn("unable to update plan commit status: %s", err)
110107
}
111108

112-
// discard previous plans that might not be relevant anymore
113-
ctx.Log.Debug("deleting locks and workdir(s) with previous plans")
114-
_, err = p.deleteLockCommand.DeleteLocksByPull(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num)
115-
if err != nil {
116-
ctx.Log.Err("deleting locks: %s", err)
117-
}
118-
119109
// Only run commands in parallel if enabled
120110
var result command.Result
121111
if p.isParallelEnabled(projectCmds) {
@@ -190,16 +180,6 @@ func (p *PlanCommandRunner) run(ctx *command.Context, cmd *CommentCommand) {
190180

191181
projectCmds, policyCheckCmds := p.partitionProjectCmds(ctx, projectCmds)
192182

193-
// if the plan is generic, new plans will be generated based on changes
194-
// discard previous plans that might not be relevant anymore
195-
if !cmd.IsForSpecificProject() {
196-
ctx.Log.Debug("deleting locks and workdir(s) with previous plans")
197-
_, err = p.deleteLockCommand.DeleteLocksByPull(ctx.Pull.BaseRepo.FullName, ctx.Pull.Num)
198-
if err != nil {
199-
ctx.Log.Err("deleting locks: %s", err)
200-
}
201-
}
202-
203183
// Only run commands in parallel if enabled
204184
var result command.Result
205185
if p.isParallelEnabled(projectCmds) {

Diff for: server/server.go

-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
616616
userConfig.ParallelPoolSize,
617617
userConfig.SilenceNoProjects,
618618
boltdb,
619-
deleteLockCommand,
620619
)
621620

622621
pullReqStatusFetcher := vcs.NewPullReqStatusFetcher(vcsClient)

0 commit comments

Comments
 (0)