@@ -22,7 +22,7 @@ import (
22
22
23
23
"github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
24
24
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
25
- "gopkg.in /yaml.v3"
25
+ yaml "sigs.k8s.io /yaml/goyaml .v3"
26
26
)
27
27
28
28
// Stores some statistics about the results of a run
@@ -61,6 +61,8 @@ const (
61
61
WriteBackGit WriteBackMethod = 1
62
62
)
63
63
64
+ const defaultIndent = 2
65
+
64
66
// WriteBackConfig holds information on how to write back the changes to an Application
65
67
type WriteBackConfig struct {
66
68
Method WriteBackMethod
@@ -425,6 +427,7 @@ func marshalWithIndent(in interface{}, indent int) (out []byte, err error) {
425
427
defer encoder .Close ()
426
428
// note: yaml.v3 will only respect indents from 1 to 9 inclusive.
427
429
encoder .SetIndent (indent )
430
+ encoder .CompactSeqIndent ()
428
431
if err = encoder .Encode (in ); err != nil {
429
432
return nil , err
430
433
}
@@ -434,30 +437,6 @@ func marshalWithIndent(in interface{}, indent int) (out []byte, err error) {
434
437
return b .Bytes (), nil
435
438
}
436
439
437
- func guessIndent (root * yaml.Node ) int {
438
- node := root
439
- if root .Kind == yaml .DocumentNode {
440
- if len (node .Content ) == 0 {
441
- return 2
442
- }
443
- node = root .Content [0 ]
444
- }
445
- // anything other than a map at the root makes guessing difficult
446
- if node .Kind != yaml .MappingNode || len (node .Content ) == 0 {
447
- return 2
448
- }
449
- // first level map entries that are themselves mappings or sequences,
450
- // in block style, and are indented, allow guessing the preferred indent.
451
- for i , child := range node .Content {
452
- if i % 2 == 1 && child .Column > 1 && child .Column < 10 && child .Style != yaml .FlowStyle {
453
- if child .Kind == yaml .MappingNode || child .Kind == yaml .SequenceNode {
454
- return child .Column - 1
455
- }
456
- }
457
- }
458
- return 2
459
- }
460
-
461
440
// marshalParamsOverride marshals the parameter overrides of a given application
462
441
// into YAML bytes
463
442
func marshalParamsOverride (app * v1alpha1.Application , originalData []byte ) ([]byte , error ) {
@@ -481,16 +460,16 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
481
460
}
482
461
483
462
if len (originalData ) == 0 {
484
- override , err = marshalWithIndent (newParams , 2 )
463
+ override , err = marshalWithIndent (newParams , defaultIndent )
485
464
break
486
465
}
487
466
err = yaml .Unmarshal (originalData , & params )
488
467
if err != nil {
489
- override , err = marshalWithIndent (newParams , 2 )
468
+ override , err = marshalWithIndent (newParams , defaultIndent )
490
469
break
491
470
}
492
471
mergeKustomizeOverride (& params , & newParams )
493
- override , err = marshalWithIndent (params , 2 )
472
+ override , err = marshalWithIndent (params , defaultIndent )
494
473
case ApplicationTypeHelm :
495
474
if appSource .Helm == nil {
496
475
return []byte {}, nil
@@ -504,7 +483,6 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
504
483
if err != nil {
505
484
return nil , err
506
485
}
507
- indent := guessIndent (& helmNewValues )
508
486
509
487
for _ , c := range images {
510
488
if c .ImageAlias == "" {
@@ -546,7 +524,7 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
546
524
}
547
525
}
548
526
549
- override , err = marshalWithIndent (& helmNewValues , indent )
527
+ override , err = marshalWithIndent (& helmNewValues , defaultIndent )
550
528
} else {
551
529
var params helmOverride
552
530
newParams := helmOverride {
@@ -559,16 +537,16 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
559
537
log .WithContext ().AddField ("application" , app ).Debugf ("values: '%s'" , outputParams )
560
538
561
539
if len (originalData ) == 0 {
562
- override , err = marshalWithIndent (newParams , 2 )
540
+ override , err = marshalWithIndent (newParams , defaultIndent )
563
541
break
564
542
}
565
543
err = yaml .Unmarshal (originalData , & params )
566
544
if err != nil {
567
- override , err = marshalWithIndent (newParams , 2 )
545
+ override , err = marshalWithIndent (newParams , defaultIndent )
568
546
break
569
547
}
570
548
mergeHelmOverride (& params , & newParams )
571
- override , err = marshalWithIndent (params , 2 )
549
+ override , err = marshalWithIndent (params , defaultIndent )
572
550
}
573
551
default :
574
552
err = fmt .Errorf ("unsupported application type" )
0 commit comments