Skip to content

Commit 447d3c0

Browse files
committed
fix: Prevent update loop with git write-back (#171)
Signed-off-by: jannfis <[email protected]>
1 parent 5117869 commit 447d3c0

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

pkg/argocd/update.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,7 @@ func UpdateApplication(updateConf *UpdateConfiguration) ImageUpdaterResult {
196196
imgCtx.Infof("Setting new image to %s", updateableImage.WithTag(latest).String())
197197
needUpdate = true
198198

199-
if appType := GetApplicationType(&updateConf.UpdateApp.Application); appType == ApplicationTypeKustomize {
200-
err = SetKustomizeImage(&updateConf.UpdateApp.Application, applicationImage.WithTag(latest))
201-
} else if appType == ApplicationTypeHelm {
202-
err = SetHelmImage(&updateConf.UpdateApp.Application, applicationImage.WithTag(latest))
203-
} else {
204-
result.NumErrors += 1
205-
err = fmt.Errorf("Could not update application %s - neither Helm nor Kustomize application", app)
206-
}
199+
err = setAppImage(&updateConf.UpdateApp.Application, applicationImage.WithTag(latest))
207200

208201
if err != nil {
209202
imgCtx.Errorf("Error while trying to update image: %v", err)
@@ -214,6 +207,14 @@ func UpdateApplication(updateConf *UpdateConfiguration) ImageUpdaterResult {
214207
result.NumImagesUpdated += 1
215208
}
216209
} else {
210+
// We need to explicitly set the up-to-date images in the spec too, so
211+
// that we correctly marshal out the parameter overrides to include all
212+
// images, regardless of those were updated or not.
213+
err = setAppImage(&updateConf.UpdateApp.Application, updateableImage.WithTag(updateableImage.ImageTag))
214+
if err != nil {
215+
imgCtx.Errorf("Error while trying to update image: %v", err)
216+
result.NumErrors += 1
217+
}
217218
imgCtx.Debugf("Image '%s' already on latest allowed version", updateableImage.GetFullNameWithTag())
218219
}
219220
}
@@ -252,6 +253,18 @@ func UpdateApplication(updateConf *UpdateConfiguration) ImageUpdaterResult {
252253
return result
253254
}
254255

256+
func setAppImage(app *v1alpha1.Application, img *image.ContainerImage) error {
257+
var err error
258+
if appType := GetApplicationType(app); appType == ApplicationTypeKustomize {
259+
err = SetKustomizeImage(app, img)
260+
} else if appType == ApplicationTypeHelm {
261+
err = SetHelmImage(app, img)
262+
} else {
263+
err = fmt.Errorf("Could not update application %s - neither Helm nor Kustomize application", app)
264+
}
265+
return err
266+
}
267+
255268
// marshalParamsOverride marshals the parameter overrides of a given application
256269
// into YAML bytes
257270
func marshalParamsOverride(app *v1alpha1.Application) ([]byte, error) {

0 commit comments

Comments
 (0)