Skip to content

Commit 2605ec1

Browse files
eplightningjannfis
authored andcommitted
fix: Prevent concurrent updates to git repositories (#177)
* Add method docs and RequiresLocking method
1 parent d2890f3 commit 2605ec1

File tree

4 files changed

+63
-28
lines changed

4 files changed

+63
-28
lines changed

cmd/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ func runImageUpdater(cfg *ImageUpdaterConfig, warmUp bool) (argocd.ImageUpdaterR
117117
log.Infof("Starting image update cycle, considering %d annotated application(s) for update", len(appList))
118118
}
119119

120+
syncState := argocd.NewSyncIterationState()
121+
120122
// Allow a maximum of MaxConcurrency number of goroutines to exist at the
121123
// same time. If in warm-up mode, set to 1 explicitly.
122124
var concurrency int = cfg.MaxConcurrency
@@ -153,7 +155,7 @@ func runImageUpdater(cfg *ImageUpdaterConfig, warmUp bool) (argocd.ImageUpdaterR
153155
GitCommitUser: cfg.GitCommitUser,
154156
GitCommitEmail: cfg.GitCommitMail,
155157
}
156-
res := argocd.UpdateApplication(upconf)
158+
res := argocd.UpdateApplication(upconf, syncState)
157159
result.NumApplicationsProcessed += 1
158160
result.NumErrors += res.NumErrors
159161
result.NumImagesConsidered += res.NumImagesConsidered

go.sum

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
7979
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
8080
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
8181
github.com/bifurcation/mint v0.0.0-20180715133206-93c51c6ce115/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU=
82-
github.com/blang/semver v3.5.0+incompatible h1:CGxCgetQ64DKk7rdZ++Vfnb1+ogGNnB17OJKJXD2Cfs=
8382
github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
8483
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
8584
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
@@ -266,7 +265,6 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP
266265
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
267266
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
268267
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
269-
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 h1:LbsanbbD6LieFkXbj9YNNBupiGHJgFeLpO0j0Fza1h8=
270268
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
271269
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk=
272270
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -304,21 +302,18 @@ github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
304302
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
305303
github.com/google/cadvisor v0.35.0/go.mod h1:1nql6U13uTHaLYB8rLS5x9IJc2qT6Xd/Tr1sTX6NE48=
306304
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
307-
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
308305
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
309306
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
310307
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
311308
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
312309
github.com/google/go-jsonnet v0.16.0/go.mod h1:sOcuej3UW1vpPTZOr8L7RQimqai1a57bt5j22LzGZCw=
313310
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
314-
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
315311
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
316312
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
317313
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
318314
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
319315
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
320316
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
321-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
322317
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
323318
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
324319
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
@@ -392,7 +387,6 @@ github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0
392387
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
393388
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
394389
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
395-
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
396390
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
397391
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
398392
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -429,13 +423,11 @@ github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7
429423
github.com/malexdev/utfutil v0.0.0-20180510171754-00c8d4a8e7a8/go.mod h1:UtpLyb/EupVKXF/N0b4NRe1DNg+QYJsnsHQ038romhM=
430424
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
431425
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
432-
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
433426
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
434427
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
435428
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
436429
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
437430
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
438-
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
439431
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
440432
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
441433
github.com/mattn/go-shellwords v1.0.5/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
@@ -562,7 +554,6 @@ github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjM
562554
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
563555
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
564556
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
565-
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
566557
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
567558
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
568559
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
@@ -579,7 +570,6 @@ github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgK
579570
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
580571
github.com/spf13/cobra v0.0.2/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
581572
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
582-
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
583573
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
584574
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
585575
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
@@ -603,7 +593,6 @@ github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
603593
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
604594
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
605595
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
606-
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
607596
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
608597
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
609598
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -722,7 +711,6 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
722711
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
723712
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
724713
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
725-
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
726714
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
727715
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
728716
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -816,7 +804,6 @@ google.golang.org/grpc v1.15.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9M
816804
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
817805
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
818806
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
819-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
820807
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
821808
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
822809
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -849,7 +836,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
849836
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
850837
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
851838
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
852-
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
853839
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
854840
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
855841
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
@@ -932,7 +918,6 @@ sigs.k8s.io/structured-merge-diff/v2 v2.0.1/go.mod h1:Wb7vfKAodbKgf6tn1Kl0VvGj7m
932918
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
933919
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 h1:dOmIZBMfhcHS09XZkMyUgkq5trg3/jRyJYFZUiaOp8E=
934920
sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
935-
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
936921
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
937922
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
938923
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=

pkg/argocd/update.go

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path"
99
"strings"
10+
"sync"
1011

1112
"github.com/argoproj-labs/argocd-image-updater/ext/git"
1213
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
@@ -79,8 +80,45 @@ type helmOverride struct {
7980
Helm helmParameters `json:"helm"`
8081
}
8182

83+
// SyncIterationState holds shared state of a running update operation
84+
type SyncIterationState struct {
85+
lock sync.Mutex
86+
repositoryLocks map[string]*sync.Mutex
87+
}
88+
89+
// NewSyncIterationState returns a new instance of SyncIterationState
90+
func NewSyncIterationState() *SyncIterationState {
91+
return &SyncIterationState{
92+
repositoryLocks: make(map[string]*sync.Mutex),
93+
}
94+
}
95+
96+
// GetRepositoryLock returns the lock for a specified repository
97+
func (state *SyncIterationState) GetRepositoryLock(repository string) *sync.Mutex {
98+
state.lock.Lock()
99+
defer state.lock.Unlock()
100+
101+
lock, exists := state.repositoryLocks[repository]
102+
if !exists {
103+
lock = &sync.Mutex{}
104+
state.repositoryLocks[repository] = lock
105+
}
106+
107+
return lock
108+
}
109+
110+
// RequiresLocking returns true if write-back method requires repository locking
111+
func (wbc *WriteBackConfig) RequiresLocking() bool {
112+
switch wbc.Method {
113+
case WriteBackGit:
114+
return true
115+
default:
116+
return false
117+
}
118+
}
119+
82120
// UpdateApplication update all images of a single application. Will run in a goroutine.
83-
func UpdateApplication(updateConf *UpdateConfiguration) ImageUpdaterResult {
121+
func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationState) ImageUpdaterResult {
84122
var needUpdate bool = false
85123

86124
result := ImageUpdaterResult{}
@@ -237,7 +275,7 @@ func UpdateApplication(updateConf *UpdateConfiguration) ImageUpdaterResult {
237275
logCtx := log.WithContext().AddField("application", app)
238276
if !updateConf.DryRun {
239277
logCtx.Infof("Committing %d parameter update(s) for application %s", result.NumImagesUpdated, app)
240-
err := commitChanges(&updateConf.UpdateApp.Application, wbc)
278+
err := commitChangesLocked(&updateConf.UpdateApp.Application, wbc, state)
241279
if err != nil {
242280
logCtx.Errorf("Could not update application spec: %v", err)
243281
result.NumErrors += 1
@@ -342,6 +380,16 @@ func getWriteBackConfig(app *v1alpha1.Application, kubeClient *kube.KubernetesCl
342380
return wbc, nil
343381
}
344382

383+
func commitChangesLocked(app *v1alpha1.Application, wbc *WriteBackConfig, state *SyncIterationState) error {
384+
if wbc.RequiresLocking() {
385+
lock := state.GetRepositoryLock(app.Spec.Source.RepoURL)
386+
lock.Lock()
387+
defer lock.Unlock()
388+
}
389+
390+
return commitChanges(app, wbc)
391+
}
392+
345393
// commitChanges commits any changes required for updating one or more images
346394
// after the UpdateApplication cycle has finished.
347395
func commitChanges(app *v1alpha1.Application, wbc *WriteBackConfig) error {

pkg/argocd/update_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func Test_UpdateApplication(t *testing.T) {
7474
KubeClient: &kubeClient,
7575
UpdateApp: appImages,
7676
DryRun: false,
77-
})
77+
}, NewSyncIterationState())
7878
assert.Equal(t, 0, res.NumErrors)
7979
assert.Equal(t, 0, res.NumSkipped)
8080
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -134,7 +134,7 @@ func Test_UpdateApplication(t *testing.T) {
134134
KubeClient: &kubeClient,
135135
UpdateApp: appImages,
136136
DryRun: false,
137-
})
137+
}, NewSyncIterationState())
138138
assert.Equal(t, 0, res.NumErrors)
139139
assert.Equal(t, 0, res.NumSkipped)
140140
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -189,7 +189,7 @@ func Test_UpdateApplication(t *testing.T) {
189189
KubeClient: &kubeClient,
190190
UpdateApp: appImages,
191191
DryRun: false,
192-
})
192+
}, NewSyncIterationState())
193193
assert.Equal(t, 0, res.NumErrors)
194194
assert.Equal(t, 1, res.NumSkipped)
195195
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -244,7 +244,7 @@ func Test_UpdateApplication(t *testing.T) {
244244
KubeClient: &kubeClient,
245245
UpdateApp: appImages,
246246
DryRun: false,
247-
})
247+
}, NewSyncIterationState())
248248
assert.Equal(t, 0, res.NumErrors)
249249
assert.Equal(t, 0, res.NumSkipped)
250250
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -319,7 +319,7 @@ func Test_UpdateApplication(t *testing.T) {
319319
KubeClient: &kubeClient,
320320
UpdateApp: appImages,
321321
DryRun: false,
322-
})
322+
}, NewSyncIterationState())
323323
assert.Equal(t, 0, res.NumErrors)
324324
assert.Equal(t, 0, res.NumSkipped)
325325
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -394,7 +394,7 @@ func Test_UpdateApplication(t *testing.T) {
394394
KubeClient: &kubeClient,
395395
UpdateApp: appImages,
396396
DryRun: false,
397-
})
397+
}, NewSyncIterationState())
398398
assert.Equal(t, 0, res.NumErrors)
399399
assert.Equal(t, 0, res.NumSkipped)
400400
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -449,7 +449,7 @@ func Test_UpdateApplication(t *testing.T) {
449449
KubeClient: &kubeClient,
450450
UpdateApp: appImages,
451451
DryRun: false,
452-
})
452+
}, NewSyncIterationState())
453453
assert.Equal(t, 1, res.NumErrors)
454454
assert.Equal(t, 0, res.NumSkipped)
455455
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -502,7 +502,7 @@ func Test_UpdateApplication(t *testing.T) {
502502
KubeClient: &kubeClient,
503503
UpdateApp: appImages,
504504
DryRun: false,
505-
})
505+
}, NewSyncIterationState())
506506
assert.Equal(t, 1, res.NumErrors)
507507
assert.Equal(t, 0, res.NumSkipped)
508508
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -557,7 +557,7 @@ func Test_UpdateApplication(t *testing.T) {
557557
KubeClient: &kubeClient,
558558
UpdateApp: appImages,
559559
DryRun: false,
560-
})
560+
}, NewSyncIterationState())
561561
assert.Equal(t, 1, res.NumErrors)
562562
assert.Equal(t, 0, res.NumSkipped)
563563
assert.Equal(t, 1, res.NumApplicationsProcessed)
@@ -612,7 +612,7 @@ func Test_UpdateApplication(t *testing.T) {
612612
KubeClient: &kubeClient,
613613
UpdateApp: appImages,
614614
DryRun: false,
615-
})
615+
}, NewSyncIterationState())
616616
assert.Equal(t, 1, res.NumErrors)
617617
assert.Equal(t, 0, res.NumSkipped)
618618
assert.Equal(t, 1, res.NumApplicationsProcessed)

0 commit comments

Comments
 (0)