Skip to content

Commit 4d95783

Browse files
krrrr38nitrocode
andauthored
Enable or disable repo_locking per repo in repos.yaml and atlantis.yaml (#2700)
* disable repo locking repos.yaml and atlantis.yaml with allow override * rename disable_repo_locking into repo_locking * add both enable/disable repo_locking test Co-authored-by: nitrocode <[email protected]>
1 parent 66dc30e commit 4d95783

21 files changed

+231
-61
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ We use [pegomock](https://github.com/petergtz/pegomock) for mocking. If you're
130130
modifying any interfaces that are mocked, you'll need to regen the mocks for that
131131
interface.
132132
133-
Install using `go get github.com/petergtz/pegomock/pegomock`
133+
Install using `go install github.com/petergtz/pegomock/pegomock`
134134
135135
If you see errors like:
136136
```

runatlantis.io/docs/repo-level-atlantis-yaml.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ projects:
5656
workspace: default
5757
terraform_version: v0.11.0
5858
delete_source_branch_on_merge: true
59+
repo_locking: true
5960
autoplan:
6061
when_modified: ["*.tf", "../modules/**/*.tf"]
6162
enabled: true
@@ -264,6 +265,7 @@ dir: mydir
264265
workspace: myworkspace
265266
execution_order_group: 0
266267
delete_source_branch_on_merge: false
268+
repo_locking: true
267269
autoplan:
268270
terraform_version: 0.11.0
269271
apply_requirements: ["approved"]
@@ -273,10 +275,12 @@ workflow: myworkflow
273275
| Key | Type | Default | Required | Description |
274276
|----------------------------------------|-----------------------|-------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
275277
| name | string | none | maybe | Required if there is more than one project with the same `dir` and `workspace`. This project name can be used with the `-p` flag. |
276-
| branch | string | none | no | Regex matching projects by the base branch of pull request (the branch the pull request is getting merged into). Only projects that match the PR's branch will be considered. By default, all branches are matched. || dir | string | none | **yes** | The directory of this project relative to the repo root. For example if the project was under `./project1` then use `project1`. Use `.` to indicate the repo root. |
278+
| branch | string | none | no | Regex matching projects by the base branch of pull request (the branch the pull request is getting merged into). Only projects that match the PR's branch will be considered. By default, all branches are matched. |
279+
| dir | string | none | **yes** | The directory of this project relative to the repo root. For example if the project was under `./project1` then use `project1`. Use `.` to indicate the repo root. |
277280
| workspace | string | `"default"` | no | The [Terraform workspace](https://www.terraform.io/docs/state/workspaces.html) for this project. Atlantis will switch to this workplace when planning/applying and will create it if it doesn't exist. |
278281
| execution_order_group | int | `0` | no | Index of execution order group. Projects will be sort by this field before planning/applying. |
279282
| delete_source_branch_on_merge | bool | `false` | no | Automatically deletes the source branch on merge. |
283+
| repo_locking | bool | `true` | no | Get a repository lock in this project when plan. |
280284
| autoplan | [Autoplan](#autoplan) | none | no | A custom autoplan configuration. If not specified, will use the autoplan config. See [Autoplanning](autoplanning.html). |
281285
| terraform_version | string | none | no | A specific Terraform version to use when running commands for this project. Must be [Semver compatible](https://semver.org/), ex. `v0.11.0`, `0.12.0-beta1`. |
282286
| apply_requirements<br />*(restricted)* | array[string] | none | no | Requirements that must be satisfied before `atlantis apply` can be run. Currently the only supported requirements are `approved`, `mergeable`, and `undiverged`. See [Apply Requirements](apply-requirements.html) for more details. |

runatlantis.io/docs/server-side-repo-config.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ repos:
4444

4545
# allowed_overrides specifies which keys can be overridden by this repo in
4646
# its atlantis.yaml file.
47-
allowed_overrides: [apply_requirements, workflow, delete_source_branch_on_merge]
47+
allowed_overrides: [apply_requirements, workflow, delete_source_branch_on_merge, repo_locking]
4848

4949
# allowed_workflows specifies which workflows the repos that match
5050
# are allowed to select.
@@ -58,7 +58,11 @@ repos:
5858
# delete_source_branch_on_merge defines whether the source branch would be deleted on merge
5959
# If false (default), the source branch won't be deleted on merge
6060
delete_source_branch_on_merge: true
61-
61+
62+
# repo_locking defines whether lock repository when planning.
63+
# If true (default), atlantis try to get a lock.
64+
repo_locking: true
65+
6266
# pre_workflow_hooks defines arbitrary list of scripts to execute before workflow execution.
6367
pre_workflow_hooks:
6468
- run: my-pre-workflow-hook-command arg1
@@ -392,16 +396,17 @@ If you set a workflow with the key `default`, it will override this.
392396
:::
393397

394398
### Repo
395-
| Key | Type | Default | Required | Description |
396-
|-------------------------------|----------|---------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
399+
| Key | Type | Default | Required | Description |
400+
|-------------------------------|----------|---------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
397401
| id | string | none | yes | Value can be a regular expression when specified as /&lt;regex&gt;/ or an exact string match. Repo IDs are of the form `{vcs hostname}/{org}/{name}`, ex. `github.com/owner/repo`. Hostname is specified without scheme or port. For Bitbucket Server, {org} is the **name** of the project, not the key. |
398402
| branch | string | none | no | An regex matching pull requests by base branch (the branch the pull request is getting merged into). By default, all branches are matched |
399-
| workflow | string | none | no | A custom workflow. |
400-
| apply_requirements | []string | none | no | Requirements that must be satisfied before `atlantis apply` can be run. Currently the only supported requirements are `approved`, `mergeable`, and `undiverged`. See [Apply Requirements](apply-requirements.html) for more details. |
401-
| allowed_overrides | []string | none | no | A list of restricted keys that `atlantis.yaml` files can override. The only supported keys are `apply_requirements`, `workflow` and `delete_source_branch_on_merge` |
402-
| allowed_workflows | []string | none | no | A list of workflows that `atlantis.yaml` files can select from. |
403-
| allow_custom_workflows | bool | false | no | Whether or not to allow [Custom Workflows](custom-workflows.html). |
404-
| delete_source_branch_on_merge | bool | false | no | Whether or not to delete the source branch on merge (only AzureDevOps and GitLab support) |
403+
| workflow | string | none | no | A custom workflow. |
404+
| apply_requirements | []string | none | no | Requirements that must be satisfied before `atlantis apply` can be run. Currently the only supported requirements are `approved`, `mergeable`, and `undiverged`. See [Apply Requirements](apply-requirements.html) for more details. |
405+
| allowed_overrides | []string | none | no | A list of restricted keys that `atlantis.yaml` files can override. The only supported keys are `apply_requirements`, `workflow`, `delete_source_branch_on_merge` and `repo_locking` |
406+
| allowed_workflows | []string | none | no | A list of workflows that `atlantis.yaml` files can select from. |
407+
| allow_custom_workflows | bool | false | no | Whether or not to allow [Custom Workflows](custom-workflows.html). |
408+
| delete_source_branch_on_merge | bool | false | no | Whether or not to delete the source branch on merge (only AzureDevOps and GitLab support) |
409+
| repo_locking | bool | false | no | Whether or not to get a lock |
405410

406411

407412
:::tip Notes

server/controllers/events/events_controller_e2e_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,12 @@ func setupE2E(t *testing.T, repoDir string) (events_controllers.VCSEventsControl
899899
Ok(t, err)
900900
backend := boltdb
901901
lockingClient := locking.NewClient(boltdb)
902+
noOpLocker := locking.NewNoOpLocker()
902903
applyLocker = locking.NewApplyClient(boltdb, userConfig.DisableApply)
903904
projectLocker := &events.DefaultProjectLocker{
904-
Locker: lockingClient,
905-
VCSClient: e2eVCSClient,
905+
Locker: lockingClient,
906+
NoOpLocker: noOpLocker,
907+
VCSClient: e2eVCSClient,
906908
}
907909
workingDir := &events.FileWorkspace{
908910
DataDir: dataDir,

server/core/config/parser_validator_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ func TestParseGlobalCfg(t *testing.T) {
12221222
input: `repos:
12231223
- id: /.*/
12241224
allowed_overrides: [invalid]`,
1225-
expErr: "repos: (0: (allowed_overrides: \"invalid\" is not a valid override, only \"apply_requirements\", \"workflow\" and \"delete_source_branch_on_merge\" are supported.).).",
1225+
expErr: "repos: (0: (allowed_overrides: \"invalid\" is not a valid override, only \"apply_requirements\", \"workflow\", \"delete_source_branch_on_merge\" and \"repo_locking\" are supported.).).",
12261226
},
12271227
"invalid apply_requirement": {
12281228
input: `repos:
@@ -1450,6 +1450,7 @@ workflows:
14501450
AllowedOverrides: []string{},
14511451
AllowCustomWorkflows: Bool(false),
14521452
DeleteSourceBranchOnMerge: Bool(false),
1453+
RepoLocking: Bool(true),
14531454
},
14541455
},
14551456
Workflows: map[string]valid.Workflow{

server/core/config/raw/global_cfg.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Repo struct {
3030
AllowedOverrides []string `yaml:"allowed_overrides" json:"allowed_overrides"`
3131
AllowCustomWorkflows *bool `yaml:"allow_custom_workflows,omitempty" json:"allow_custom_workflows,omitempty"`
3232
DeleteSourceBranchOnMerge *bool `yaml:"delete_source_branch_on_merge,omitempty" json:"delete_source_branch_on_merge,omitempty"`
33+
RepoLocking *bool `yaml:"repo_locking,omitempty" json:"repo_locking,omitempty"`
3334
}
3435

3536
func (g GlobalCfg) Validate() error {
@@ -173,8 +174,8 @@ func (r Repo) Validate() error {
173174
overridesValid := func(value interface{}) error {
174175
overrides := value.([]string)
175176
for _, o := range overrides {
176-
if o != valid.ApplyRequirementsKey && o != valid.WorkflowKey && o != valid.DeleteSourceBranchOnMergeKey {
177-
return fmt.Errorf("%q is not a valid override, only %q, %q and %q are supported", o, valid.ApplyRequirementsKey, valid.WorkflowKey, valid.DeleteSourceBranchOnMergeKey)
177+
if o != valid.ApplyRequirementsKey && o != valid.WorkflowKey && o != valid.DeleteSourceBranchOnMergeKey && o != valid.RepoLockingKey {
178+
return fmt.Errorf("%q is not a valid override, only %q, %q, %q and %q are supported", o, valid.ApplyRequirementsKey, valid.WorkflowKey, valid.DeleteSourceBranchOnMergeKey, valid.RepoLockingKey)
178179
}
179180
}
180181
return nil
@@ -268,5 +269,6 @@ OUTER:
268269
AllowedOverrides: r.AllowedOverrides,
269270
AllowCustomWorkflows: r.AllowCustomWorkflows,
270271
DeleteSourceBranchOnMerge: r.DeleteSourceBranchOnMerge,
272+
RepoLocking: r.RepoLocking,
271273
}
272274
}

server/core/config/raw/project.go

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Project struct {
3030
Autoplan *Autoplan `yaml:"autoplan,omitempty"`
3131
ApplyRequirements []string `yaml:"apply_requirements,omitempty"`
3232
DeleteSourceBranchOnMerge *bool `yaml:"delete_source_branch_on_merge,omitempty"`
33+
RepoLocking *bool `yaml:"repo_locking,omitempty"`
3334
ExecutionOrderGroup *int `yaml:"execution_order_group,omitempty"`
3435
}
3536

@@ -118,6 +119,10 @@ func (p Project) ToValid() valid.Project {
118119
v.DeleteSourceBranchOnMerge = p.DeleteSourceBranchOnMerge
119120
}
120121

122+
if p.RepoLocking != nil {
123+
v.RepoLocking = p.RepoLocking
124+
}
125+
121126
if p.ExecutionOrderGroup != nil {
122127
v.ExecutionOrderGroup = *p.ExecutionOrderGroup
123128
}

0 commit comments

Comments
 (0)