@@ -329,40 +329,51 @@ func writeKustomization(app *v1alpha1.Application, wbc *WriteBackConfig, gitC gi
329329 return err , false
330330 }
331331
332- if err = updateKustomizeFile (filterFunc , kustFile ); err != nil {
333- return err , false
334- }
335-
336- return nil , false
332+ return updateKustomizeFile (filterFunc , kustFile )
337333}
338334
339335// updateKustomizeFile reads the kustomization file at path, applies the filter to it, and writes the result back
340336// to the file. This is the same behavior as kyaml.UpdateFile, but it preserves the original order
341337// of YAML fields to minimize git diffs.
342- func updateKustomizeFile (filter kyaml.Filter , path string ) error {
338+ func updateKustomizeFile (filter kyaml.Filter , path string ) ( error , bool ) {
343339 // Read the yaml
344340 y , err := kyaml .ReadFile (path )
345341 if err != nil {
346- return err
342+ return err , false
343+ }
344+
345+ originalData , err := y .String ()
346+ if err != nil {
347+ return err , false
347348 }
348349
349350 // Update the yaml
350351 yCpy := y .Copy ()
351352 if err := yCpy .PipeE (filter ); err != nil {
352- return err
353+ return err , false
353354 }
354355
355356 // Preserve the original order of fields
356357 if err := order .SyncOrder (y , yCpy ); err != nil {
357- return err
358+ return err , false
359+ }
360+
361+ override , err := yCpy .String ()
362+ if err != nil {
363+ return err , false
364+ }
365+
366+ if originalData == override {
367+ log .Debugf ("target parameter file and marshaled data are the same, skipping commit." )
368+ return nil , true
358369 }
359370
360371 // Write the yaml
361- if err := kyaml .WriteFile (yCpy , path ); err != nil {
362- return err
372+ if err := os .WriteFile (path , [] byte ( override ), 0600 ); err != nil {
373+ return err , false
363374 }
364375
365- return nil
376+ return nil , false
366377}
367378
368379func imagesFilter (images v1alpha1.KustomizeImages ) (kyaml.Filter , error ) {
0 commit comments