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: when using order group, abort plan/apply if any fail #3323

Merged
merged 5 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion runatlantis.io/docs/repo-level-atlantis-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ automerge: true
delete_source_branch_on_merge: true
parallel_plan: true
parallel_apply: true
abort_on_execution_order_fail: true
projects:
- name: my-project-name
branch: /main/
Expand All @@ -64,6 +65,7 @@ projects:
plan_requirements: [mergeable, approved, undiverged]
apply_requirements: [mergeable, approved, undiverged]
import_requirements: [mergeable, approved, undiverged]
execution_order_group: 1
workflow: myworkflow
workflows:
myworkflow:
Expand Down Expand Up @@ -259,6 +261,7 @@ to be allowed to set this key. See [Server-Side Repo Config Use Cases](server-si
### Order of planning/applying
```yaml
version: 3
abort_on_execution_order_fail: true
projects:
- dir: project1
execution_order_group: 2
Expand All @@ -268,7 +271,10 @@ projects:
With this config above, Atlantis runs planning/applying for project2 first, then for project1.
Several projects can have same `execution_order_group`. Any order in one group isn't guaranteed.
`parallel_plan` and `parallel_apply` respect these order groups, so parallel planning/applying works
in each group one by one.
in each group one by one.

If any plan/apply fails and `abort_on_execution_order_fail` is set to true on a repo level, all the
following groups will be aborted. For this example, if project2 fails then project1 will not run.

### Custom Backend Config
See [Custom Workflow Use Cases: Custom Backend Config](custom-workflows.html#custom-backend-config)
Expand Down
10 changes: 10 additions & 0 deletions server/core/config/raw/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const DefaultDeleteSourceBranchOnMerge = false
// DefaultEmojiReaction is the default emoji reaction for repos
const DefaultEmojiReaction = ""

// DefaultAbortOnExcecutionOrderFail being false is the default setting for abort on execution group failiures
const DefaultAbortOnExcecutionOrderFail = false

// RepoCfg is the raw schema for repo-level atlantis.yaml config.
type RepoCfg struct {
Version *int `yaml:"version,omitempty"`
Expand All @@ -37,6 +40,7 @@ type RepoCfg struct {
DeleteSourceBranchOnMerge *bool `yaml:"delete_source_branch_on_merge,omitempty"`
EmojiReaction *string `yaml:"emoji_reaction,omitempty"`
AllowedRegexpPrefixes []string `yaml:"allowed_regexp_prefixes,omitempty"`
AbortOnExcecutionOrderFail *bool `yaml:"abort_on_execution_order_fail,omitempty"`
}

func (r RepoCfg) Validate() error {
Expand Down Expand Up @@ -88,6 +92,11 @@ func (r RepoCfg) ToValid() valid.RepoCfg {
emojiReaction = *r.EmojiReaction
}

abortOnExcecutionOrderFail := DefaultAbortOnExcecutionOrderFail
if r.AbortOnExcecutionOrderFail != nil {
abortOnExcecutionOrderFail = *r.AbortOnExcecutionOrderFail
}

return valid.RepoCfg{
Version: *r.Version,
Projects: validProjects,
Expand All @@ -99,5 +108,6 @@ func (r RepoCfg) ToValid() valid.RepoCfg {
DeleteSourceBranchOnMerge: r.DeleteSourceBranchOnMerge,
AllowedRegexpPrefixes: r.AllowedRegexpPrefixes,
EmojiReaction: emojiReaction,
AbortOnExcecutionOrderFail: abortOnExcecutionOrderFail,
}
}
47 changes: 26 additions & 21 deletions server/core/config/raw/repo_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,43 +259,48 @@ func TestConfig_ToValid(t *testing.T) {
},
},
{
description: "automerge and parallel_apply omitted",
description: "automerge, parallel_apply and abort_on_execution_order_fail omitted",
input: raw.RepoCfg{
Version: Int(2),
},
exp: valid.RepoCfg{
Version: 2,
Automerge: false,
ParallelApply: false,
Workflows: map[string]valid.Workflow{},
Version: 2,
Automerge: false,
ParallelApply: false,
AbortOnExcecutionOrderFail: false,
Workflows: map[string]valid.Workflow{},
},
},
{
description: "automerge and parallel_apply true",
description: "automerge, parallel_apply and abort_on_execution_order_fail true",
input: raw.RepoCfg{
Version: Int(2),
Automerge: Bool(true),
ParallelApply: Bool(true),
Version: Int(2),
Automerge: Bool(true),
ParallelApply: Bool(true),
AbortOnExcecutionOrderFail: Bool(true),
},
exp: valid.RepoCfg{
Version: 2,
Automerge: true,
ParallelApply: true,
Workflows: map[string]valid.Workflow{},
Version: 2,
Automerge: true,
ParallelApply: true,
AbortOnExcecutionOrderFail: true,
Workflows: map[string]valid.Workflow{},
},
},
{
description: "automerge and parallel_apply false",
description: "automerge, parallel_apply and abort_on_execution_order_fail false",
input: raw.RepoCfg{
Version: Int(2),
Automerge: Bool(false),
ParallelApply: Bool(false),
Version: Int(2),
Automerge: Bool(false),
ParallelApply: Bool(false),
AbortOnExcecutionOrderFail: Bool(false),
},
exp: valid.RepoCfg{
Version: 2,
Automerge: false,
ParallelApply: false,
Workflows: map[string]valid.Workflow{},
Version: 2,
Automerge: false,
ParallelApply: false,
AbortOnExcecutionOrderFail: false,
Workflows: map[string]valid.Workflow{},
},
},
{
Expand Down
1 change: 1 addition & 0 deletions server/core/config/valid/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type RepoCfg struct {
RepoLocking *bool
EmojiReaction string
AllowedRegexpPrefixes []string
AbortOnExcecutionOrderFail bool
}

func (r RepoCfg) FindProjectsByDirWorkspace(repoRelDir string, workspace string) []Project {
Expand Down
2 changes: 1 addition & 1 deletion server/events/apply_command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (a *ApplyCommandRunner) Run(ctx *command.Context, cmd *CommentCommand) {
var result command.Result
if a.isParallelEnabled(projectCmds) {
ctx.Log.Info("Running applies in parallel")
result = runProjectCmdsParallelGroups(projectCmds, a.prjCmdRunner.Apply, a.parallelPoolSize)
result = runProjectCmdsParallelGroups(ctx, projectCmds, a.prjCmdRunner.Apply, a.parallelPoolSize)
} else {
result = runProjectCmds(projectCmds, a.prjCmdRunner.Apply)
}
Expand Down
Loading