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

fix: Prevent concurrent updates to git repositories #177

Merged
merged 1 commit into from Mar 29, 2021

Conversation

eplightning
Copy link
Contributor

As requested, here's PR for my attempt at fixing issue with concurrent git push operations.

I cleaned it up a little bit and re-ran go mod tidy (I don't think it changed anything though). As always I'm open to changes, I didn't have chance to write much Go code lately.

Fixes #175

@codecov
Copy link

codecov bot commented Mar 29, 2021

Codecov Report

Merging #177 (1354f0f) into master (b879041) will decrease coverage by 0.50%.
The diff coverage is 35.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #177      +/-   ##
==========================================
- Coverage   68.88%   68.37%   -0.51%     
==========================================
  Files          19       19              
  Lines        1385     1404      +19     
==========================================
+ Hits          954      960       +6     
- Misses        346      358      +12     
- Partials       85       86       +1     
Impacted Files Coverage Δ
pkg/argocd/update.go 69.45% <35.00%> (-2.82%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b879041...1354f0f. Read the comment docs.

Copy link
Contributor

@jannfis jannfis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, awesome @eplightning - thanks a lot!

I have just a minor comment (please see below), and also would like to request whether you can put some comments to the new public methods and types that you introduced.

Regarding unit tests, I think we're fine without having those yet.

@@ -367,6 +392,16 @@ func getWriteBackConfig(app *v1alpha1.Application, kubeClient *kube.KubernetesCl
return wbc, nil
}

func commitChangesLocked(app *v1alpha1.Application, wbc *WriteBackConfig, state *SyncIterationState) error {
if wbc.Method == WriteBackGit {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could move that decision to a method within the WriteBackConfig used, e.g.

func (wbc *WriteBackConfig) RequiresLocking() bool {
	switch wbc.Method {
	case WriteBackGit:
		return true
	default:
		return false
	}
}

and then use

if wbc.RequiresLocking() {
...
}

This would probably make it easier to integrate further write-back methods that might need locking as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, this makes code bit cleaner too.

Integrated this change into this PR and also added comments for new public type and methods.

* Add method docs and RequiresLocking method
Copy link
Contributor

@jannfis jannfis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @eplightning!

LGTM.

@jannfis jannfis merged commit 5da428b into argoproj-labs:master Mar 29, 2021
jannfis pushed a commit to jannfis/argocd-image-updater that referenced this pull request Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git writeback should not write to the same repository concurrently
2 participants