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

feat: Add logic for project name into lock #4192

Merged

Conversation

lukemassa
Copy link
Contributor

@lukemassa lukemassa commented Jan 31, 2024

what

Add logic of project name into locks.

why

I'm actually not totally sure why Project in models didn't have a ProjectName before. Adding this made it so we can, e.g., correctly identify the project plan files that need to be deleted when we run atlantis unlock (See #3845)

This is not a total fix, and instead kicks the can down the road a little bit. Specifically, I do not implement project_finder() to understand about project names, because frankly I'm not totally sure how, so I just assume the project doesn't have a name (i.e. empty string for ProjectName). That said, this is no worse than the current implementation, which implicitly assumes the project doesn't have a name "deeper" in the call stack.

In this sense, in my opinion this PR is a net positive, in that it moves us in the right direction, fixes a particular bug, and (as far as I know) doesn't introduce any regressions.

tests

Confirming the expected behavior change

I configured a workspace with a name projectname, did a plan, then attempted to unlock.
Before:

{"level":"error","ts":"2024-02-05T23:35:23.329-0500","caller":"events/unlock_command_runner.go:62","msg":"failed to delete locks by pull remove /Users/lukemassa/.atlantis/repos/cloud/playground/lmassa-test-atlantis/36/lmassa/lmassa.tfplan: no such file or directory","json":{"repo":"cloud/playground/lmassa-test-atlantis","pull":"36"},"stacktrace":"github.com/runatlantis/atlantis/server/events.(*UnlockCommandRunner).Run\n\t/Users/lukemassa/atlantis/server/events/unlock_command_runner.go:62\ngh.neting.cc/runatlantis/atlantis/server/events.(*DefaultCommandRunner).RunCommentCommand\n\t/Users/lukemassa/atlantis/server/events/command_runner.go:365"}

After:

{"level":"info","ts":"2024-02-05T23:41:15.515-0500","caller":"events/working_dir.go:426","msg":"Deleting plan: /Users/lukemassa/.atlantis/repos/cloud/playground/lmassa-test-atlantis/36/lmassa/projectname-lmassa.tfplan","json":{}}

Confirming no regressions

  1. If name is absent, the behavior is as before:
{"level":"info","ts":"2024-02-07T14:39:26.711-0500","caller":"events/working_dir.go:426","msg":"Deleting plan: /Users/lukemassa/.atlantis/repos/cloud/playground/lmassa-test-atlantis/36/lmassa/lmassa.tfplan","json":{}}
  1. Whether or not name is present, closing the PR itself retains its previous behavior of blowing away the entire directory (and there is no log line of atlantis even attempting to delete the plan file)
{"level":"info","ts":"2024-02-07T14:44:49.270-0500","caller":"events/working_dir.go:393","msg":"Deleting repo pull directory: /Users/lukemassa/.atlantis/repos/cloud/playground/lmassa-test-atlantis/36","json":{}}

references

Closes: #3845

@lukemassa lukemassa marked this pull request as ready for review February 6, 2024 04:59
@lukemassa lukemassa requested review from a team as code owners February 6, 2024 04:59
@lukemassa lukemassa requested review from jamengual, nitrocode and X-Guardian and removed request for a team February 6, 2024 04:59
@lukemassa lukemassa force-pushed the add_logic_for_project_name_into_lock branch from 29aea90 to f354831 Compare February 6, 2024 05:00
@github-actions github-actions bot added the go Pull requests that update Go code label Feb 6, 2024
@lukemassa lukemassa force-pushed the add_logic_for_project_name_into_lock branch from 58c4bc9 to 6cec24c Compare February 8, 2024 14:33
@lukemassa lukemassa force-pushed the add_logic_for_project_name_into_lock branch from 6cec24c to 3b6ac72 Compare February 12, 2024 15:35
@lukemassa
Copy link
Contributor Author

/cherry-pick release-0.27

@lukemassa lukemassa merged commit 783c011 into runatlantis:main Feb 12, 2024
24 checks passed
@GenPage
Copy link
Member

GenPage commented Feb 12, 2024

/cherry-pick release-0.27

gcp-cherry-pick-bot bot pushed a commit that referenced this pull request Feb 12, 2024
* feat: Add logic for project name into lock

* More logic

* Fix tests

* Add tests
GenPage pushed a commit that referenced this pull request Mar 8, 2024
* feat: Add logic for project name into lock

* More logic

* Fix tests

* Add tests
GenPage pushed a commit that referenced this pull request Mar 8, 2024
* feat: Add logic for project name into lock

* More logic

* Fix tests

* Add tests

Co-authored-by: Luke Massa <lmassa@tripadvisor.com>
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Atlantis unlock fails to delete plan of environment with project name
3 participants