-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Atlantis unlock and discard all plans via VCS comment #1003
Atlantis unlock and discard all plans via VCS comment #1003
Conversation
054c119
to
65923b4
Compare
Hi @parmouraly thanks for the PR! |
Hi @lkysow thanks for the quick feedback! On a more philosophical level one thing I was wondering about is the usage of the keyword |
Got side-tracked with looking into a bug for which I've put a PR up. |
Would love to see some movement on this as its a very important feature for me, please reach out if i can be of any assistance on this. |
hey @matthewellis-pp 👋 |
Hi @parmouraly so you've got closer to what I was asking for. I don't think we need to change project_command_builder. I think we should be able to call if !c.validateCtxAndComment(ctx) {
return
}
+ if cmd.CommandName() == models.DiscardCommand {
+ c.DeleteLockCommand.Delete(cmd)
+ l.VCSClient.CreateComment(lock.Pull.BaseRepo, lock.Pull.Num, comment)
+ return
+ }
if cmd.CommandName() == models.ApplyCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think unlock
is better than discard like you mentioned in another one of your comments.
.gitignore
Outdated
atlantis | ||
temp.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops that was unintentional. Removed
server/events/comment_parser.go
Outdated
@@ -61,6 +61,8 @@ type CommentBuilder interface { | |||
BuildPlanComment(repoRelDir string, workspace string, project string, commentArgs []string) string | |||
// BuildApplyComment builds an apply comment for the specified args. | |||
BuildApplyComment(repoRelDir string, workspace string, project string) string | |||
// BuildDiscardComment builds a discard comment for the specified args. | |||
BuildDiscardComment(repoRelDir string, workspace string, project string, commentArgs []string) string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't need commentArgs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
server/events/comment_parser.go
Outdated
@@ -264,6 +274,22 @@ func (e *CommentParser) BuildApplyComment(repoRelDir string, workspace string, p | |||
return fmt.Sprintf("%s %s%s", atlantisExecutable, models.ApplyCommand.String(), flags) | |||
} | |||
|
|||
// BuildDiscardComment builds discard comment for the specified args. | |||
func (e *CommentParser) BuildDiscardComment(repoRelDir string, workspace string, project string, commentArgs []string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't need this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
server/events/comment_parser.go
Outdated
To plan a specific project, use the -d, -w and -p flags. | ||
apply Runs 'terraform apply' on all unapplied plans from this pull request. | ||
To only apply a specific plan, use the -d, -w and -p flags. | ||
discard Discards all plans in this PR as well as the atlantis locks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you support -d, -w and -p then this should read.
Discards all plans in this PR and deletes all locks held by this PR.
To discard a specific project, use the -d, -w and -p flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking, for simplicity, to only support general discard/unlock for the whole PR in this version. Would that be OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that sounds good.
server/events/delete_lock_command.go
Outdated
@@ -0,0 +1,84 @@ | |||
// Copyright 2017 HootSuite Media Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this boilerplate because this is a new file. That's only for old files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
server/events/markdown_renderer.go
Outdated
applyCommandTitle = "Apply" | ||
planCommandTitle = "Plan" | ||
applyCommandTitle = "Apply" | ||
discardCommandTitle = "Discard" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to modify this renderer. Should be able to construct this comment in command_runner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I left the bit that shows the option for discarding plans
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean after a successful plan, you get options to click to unlock, apply etc, so I added the unlock option
This successfully deletes the atlantis lock and allows a competing PR to plan, but doesn not delete the actual plans, so a user can still apply after the lock is discarded. This will be investigated in a follow up commit Also fixed the basic mark down rendering for the discard command
Specifically deleting plans via VCS commenting now reuses the same logic as the LockController which is used by the UI delete plan action. Also via VCS commenting it's only possible atm to delete all the plans involved in the PR, as well as release all related Atlantis locks
Co-authored-by: Luke Kysow <[email protected]>
Co-authored-by: Luke Kysow <[email protected]>
02b1d4b
to
56fc1a2
Compare
Just rebased to master ^ |
* :arrow_forward: To **apply** this plan, comment: | ||
* `atlantis apply -d .` | ||
* :put_litter_in_its_place: To **delete** this plan click [here](lock-url), or to delete all plans comment and atlantis locks: | ||
* `atlantis unlock` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this look @lkysow . Are you happy with this keyword? I can adapt the comment parser, model etc if so
PS: oops just spotted a typo in the above comment will fix with next commit
server/locks_controller_test.go
Outdated
@@ -140,129 +135,23 @@ func TestDeleteLock_InvalidLockID(t *testing.T) { | |||
responseContains(t, w, http.StatusBadRequest, "Invalid lock id \"%A@\"") | |||
} | |||
|
|||
// TODO: I'm going to adapt the next 5 test cases to use some mock of DeleteLockCommand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I OK to generate mocks for DeleteLockCommand
so I can refactor these tests @lkysow ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks like that will be too hard to instantiate a concrete instance of.
Just trying to keep this as simple as possible
2f728d1
to
a8793fa
Compare
4178426
to
58c0c9e
Compare
@lkysow I think so far I've addressed all your comments. I think the three main outstanding points are:
Is there anything else I'm forgetting? Do you think we are close to merging this one? |
server/events/comment_parser.go
Outdated
name = models.DiscardCommand | ||
flagSet = pflag.NewFlagSet(models.DiscardCommand.String(), pflag.ContinueOnError) | ||
flagSet.SetOutput(ioutil.Discard) | ||
flagSet.StringVarP(&workspace, workspaceFlagLong, workspaceFlagShort, "", "Discard the plan for this workspace.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll need to remove the flags -p, etc. here if you're only doing the whole PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup good spot 👍 Been a long time I edited this file and totally forgot about it...
I've converted this back to draft because I'm missing quite a few tests still... Coming soon |
@lkysow this is a working version 🎉 In the mean time I'll see if I can push a couple more unit tests for |
Also supply usage tip when unlock is used incorrectly
l.Logger.Err("unable to delete project status: %s", err) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work on this command.
@@ -249,7 +248,8 @@ var planSuccessWrappedTmpl = template.Must(template.New("").Parse( | |||
// to do next. | |||
var planNextSteps = "{{ if .PlanWasDeleted }}This plan was not saved because one or more projects failed and automerge requires all plans pass.{{ else }}* :arrow_forward: To **apply** this plan, comment:\n" + | |||
" * `{{.ApplyCmd}}`\n" + | |||
"* :put_litter_in_its_place: To **delete** this plan click [here]({{.LockURL}})\n" + | |||
"* :put_litter_in_its_place: To **delete** this plan click [here]({{.LockURL}}), or to delete all plans and atlantis locks comment:\n" + | |||
" * `atlantis unlock`\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to move this to the bottom where we talk about running atlantis apply to apply all plans because unlocking all plans makes more sense there than nested with each individual plan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea good point didn't think about it like that. I just kept it in the already existing delete
section to avoid adding a new bullet point but yea sounds good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just gonna be a bit a of a pain to update the renderer_tests
:-D
} | ||
return "" | ||
} | ||
|
||
// DeleteLockCommandResult is the result of attempting to delete an atlantis lock. | ||
type DeleteLockCommandResult int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some changes that make this unnecessary, mainly following the pattern before where error
means error and nil
means lock not found.
Merged with #1091! Great work 🎉 |
Objective
In order to allow someone to discard a plans and
Atlantis
locks without having to close/reopen their PR, we would like to add upstream functionality that enables devs to discard plans via VCS comments in an analogous way to planning/applying.Context
The ability to discard an atlantis plan on demand is useful particularly for long lived PRs after a successful plan, as they would tend to block other people from performing Atlantis plan on the same project(s) for as long as the original PR is still open and successfully planned, which is not optimal for parallel working.
Atlantis provides a UI action that allows you to discard a plan and remove the atlantis lock.
However for security reasons because of the access Atlantis agents have to modify infrastructure, the UI might not always be reachable due to firewall restrictions.