@@ -286,20 +286,32 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
286286 }
287287
288288 if needsUpdate (updateableImage , applicationImage , latest ) {
289+ appImageWithTag := applicationImage .WithTag (latest )
290+ appImageFullNameWithTag := appImageWithTag .GetFullNameWithTag ()
291+
292+ // Check if new image is already set in Application Spec when write back is set to argocd
293+ // and compare with new image
294+ appImageSpec , err := getAppImage (& updateConf .UpdateApp .Application , appImageWithTag )
295+ if err != nil {
296+ continue
297+ }
298+ if appImageSpec == appImageFullNameWithTag {
299+ imgCtx .Infof ("New image %s already set in spec" , appImageFullNameWithTag )
300+ continue
301+ }
289302
290- imgCtx .Infof ("Setting new image to %s" , applicationImage .WithTag (latest ).GetFullNameWithTag ())
291303 needUpdate = true
304+ imgCtx .Infof ("Setting new image to %s" , appImageFullNameWithTag )
292305
293- err = setAppImage (& updateConf .UpdateApp .Application , applicationImage . WithTag ( latest ) )
306+ err = setAppImage (& updateConf .UpdateApp .Application , appImageWithTag )
294307
295308 if err != nil {
296309 imgCtx .Errorf ("Error while trying to update image: %v" , err )
297310 result .NumErrors += 1
298311 continue
299312 } else {
300- containerImageNew := applicationImage .WithTag (latest )
301- imgCtx .Infof ("Successfully updated image '%s' to '%s', but pending spec update (dry run=%v)" , updateableImage .GetFullNameWithTag (), containerImageNew .GetFullNameWithTag (), updateConf .DryRun )
302- changeList = append (changeList , ChangeEntry {containerImageNew , updateableImage .ImageTag , containerImageNew .ImageTag })
313+ imgCtx .Infof ("Successfully updated image '%s' to '%s', but pending spec update (dry run=%v)" , updateableImage .GetFullNameWithTag (), appImageFullNameWithTag , updateConf .DryRun )
314+ changeList = append (changeList , ChangeEntry {appImageWithTag , updateableImage .ImageTag , appImageWithTag .ImageTag })
303315 result .NumImagesUpdated += 1
304316 }
305317 } else {
@@ -382,6 +394,18 @@ func needsUpdate(updateableImage *image.ContainerImage, applicationImage *image.
382394 return ! updateableImage .ImageTag .Equals (latest ) || applicationImage .KustomizeImage != nil && applicationImage .DiffersFrom (updateableImage , false )
383395}
384396
397+ func getAppImage (app * v1alpha1.Application , img * image.ContainerImage ) (string , error ) {
398+ var err error
399+ if appType := GetApplicationType (app ); appType == ApplicationTypeKustomize {
400+ return GetKustomizeImage (app , img )
401+ } else if appType == ApplicationTypeHelm {
402+ return GetHelmImage (app , img )
403+ } else {
404+ err = fmt .Errorf ("could not update application %s - neither Helm nor Kustomize application" , app )
405+ return "" , err
406+ }
407+ }
408+
385409func setAppImage (app * v1alpha1.Application , img * image.ContainerImage ) error {
386410 var err error
387411 if appType := GetApplicationType (app ); appType == ApplicationTypeKustomize {
0 commit comments