@@ -460,95 +460,97 @@ func marshalKustomizeOverride(app *v1alpha1.Application, originalData []byte) ([
460
460
return marshalWithIndent (overrides , defaultIndent )
461
461
}
462
462
463
- // marshalParamsOverride marshals the parameter overrides of a given application
464
- // into YAML bytes
465
- func marshalParamsOverride (app * v1alpha1.Application , originalData []byte ) ([]byte , error ) {
466
- var override []byte
467
- var err error
468
-
463
+ func marshalHelmOverride (app * v1alpha1.Application , originalData []byte ) (override []byte , err error ) {
469
464
appSource := getApplicationSource (app )
465
+ if appSource .Helm == nil {
466
+ return []byte {}, nil
467
+ }
470
468
471
- switch GetApplicationType (app ) {
472
- case ApplicationTypeKustomize :
473
- override , err = marshalKustomizeOverride (app , originalData )
474
- case ApplicationTypeHelm :
475
- if appSource .Helm == nil {
476
- return []byte {}, nil
477
- }
469
+ if strings .HasPrefix (app .Annotations [common .WriteBackTargetAnnotation ], common .HelmPrefix ) {
470
+ images := GetImagesAndAliasesFromApplication (app )
478
471
479
- if strings .HasPrefix (app .Annotations [common .WriteBackTargetAnnotation ], common .HelmPrefix ) {
480
- images := GetImagesAndAliasesFromApplication (app )
472
+ helmNewValues := yaml.Node {}
473
+ if unmarshalErr := yaml .Unmarshal (originalData , & helmNewValues ); unmarshalErr != nil {
474
+ return nil , unmarshalErr
475
+ }
481
476
482
- helmNewValues := yaml.Node {}
483
- err = yaml .Unmarshal (originalData , & helmNewValues )
484
- if err != nil {
485
- return nil , err
477
+ for _ , c := range images {
478
+ if c .ImageAlias == "" {
479
+ continue
486
480
}
487
481
488
- for _ , c := range images {
489
- if c .ImageAlias == "" {
490
- continue
491
- }
492
-
493
- helmAnnotationParamName , helmAnnotationParamVersion := getHelmParamNamesFromAnnotation (app .Annotations , c )
482
+ helmAnnotationParamName , helmAnnotationParamVersion := getHelmParamNamesFromAnnotation (app .Annotations , c )
494
483
495
- if helmAnnotationParamName == "" {
496
- return nil , fmt .Errorf ("could not find an image-name annotation for image %s" , c .ImageName )
497
- }
498
- // for image-spec annotation, helmAnnotationParamName holds image-spec annotation value,
499
- // and helmAnnotationParamVersion is empty
500
- if helmAnnotationParamVersion == "" {
501
- if c .GetParameterHelmImageSpec (app .Annotations , common .ImageUpdaterAnnotationPrefix ) == "" {
502
- // not a full image-spec, so image-tag is required
503
- return nil , fmt .Errorf ("could not find an image-tag annotation for image %s" , c .ImageName )
504
- }
505
- } else {
506
- // image-tag annotation is present, so continue to process image-tag
507
- helmParamVersion := getHelmParam (appSource .Helm .Parameters , helmAnnotationParamVersion )
508
- if helmParamVersion == nil {
509
- return nil , fmt .Errorf ("%s parameter not found" , helmAnnotationParamVersion )
510
- }
511
- err = setHelmValue (& helmNewValues , helmAnnotationParamVersion , helmParamVersion .Value )
512
- if err != nil {
513
- return nil , fmt .Errorf ("failed to set image parameter version value: %v" , err )
514
- }
484
+ if helmAnnotationParamName == "" {
485
+ return nil , fmt .Errorf ("could not find an image-name annotation for image %s" , c .ImageName )
486
+ }
487
+ // for image-spec annotation, helmAnnotationParamName holds image-spec annotation value,
488
+ // and helmAnnotationParamVersion is empty
489
+ if helmAnnotationParamVersion == "" {
490
+ if c .GetParameterHelmImageSpec (app .Annotations , common .ImageUpdaterAnnotationPrefix ) == "" {
491
+ // not a full image-spec, so image-tag is required
492
+ return nil , fmt .Errorf ("could not find an image-tag annotation for image %s" , c .ImageName )
515
493
}
516
-
517
- helmParamName := getHelmParam (appSource .Helm .Parameters , helmAnnotationParamName )
518
- if helmParamName == nil {
519
- return nil , fmt .Errorf ("%s parameter not found" , helmAnnotationParamName )
494
+ } else {
495
+ // image-tag annotation is present, so continue to process image-tag
496
+ helmParamVersion := getHelmParam (appSource .Helm .Parameters , helmAnnotationParamVersion )
497
+ if helmParamVersion == nil {
498
+ return nil , fmt .Errorf ("%s parameter not found" , helmAnnotationParamVersion )
520
499
}
521
-
522
- err = setHelmValue (& helmNewValues , helmAnnotationParamName , helmParamName .Value )
500
+ err = setHelmValue (& helmNewValues , helmAnnotationParamVersion , helmParamVersion .Value )
523
501
if err != nil {
524
- return nil , fmt .Errorf ("failed to set image parameter name value: %v" , err )
502
+ return nil , fmt .Errorf ("failed to set image parameter version value: %v" , err )
525
503
}
526
504
}
527
505
528
- override , err = marshalWithIndent (& helmNewValues , defaultIndent )
529
- } else {
530
- var params helmOverride
531
- newParams := helmOverride {
532
- Helm : helmParameters {
533
- Parameters : appSource .Helm .Parameters ,
534
- },
506
+ helmParamName := getHelmParam (appSource .Helm .Parameters , helmAnnotationParamName )
507
+ if helmParamName == nil {
508
+ return nil , fmt .Errorf ("%s parameter not found" , helmAnnotationParamName )
535
509
}
536
510
537
- outputParams := appSource .Helm .ValuesYAML ()
538
- log .WithContext ().AddField ("application" , app ).Debugf ("values: '%s'" , outputParams )
539
-
540
- if len (originalData ) == 0 {
541
- override , err = marshalWithIndent (newParams , defaultIndent )
542
- break
543
- }
544
- err = yaml .Unmarshal (originalData , & params )
511
+ err = setHelmValue (& helmNewValues , helmAnnotationParamName , helmParamName .Value )
545
512
if err != nil {
546
- override , err = marshalWithIndent (newParams , defaultIndent )
547
- break
513
+ return nil , fmt .Errorf ("failed to set image parameter name value: %v" , err )
548
514
}
549
- mergeHelmOverride (& params , & newParams )
550
- override , err = marshalWithIndent (params , defaultIndent )
551
515
}
516
+ return marshalWithIndent (& helmNewValues , defaultIndent )
517
+ }
518
+
519
+ var params helmOverride
520
+ newParams := helmOverride {
521
+ Helm : helmParameters {
522
+ Parameters : appSource .Helm .Parameters ,
523
+ },
524
+ }
525
+
526
+ outputParams := appSource .Helm .ValuesYAML ()
527
+ log .WithContext ().AddField ("application" , app ).Debugf ("values: '%s'" , outputParams )
528
+
529
+ if len (originalData ) == 0 {
530
+ override , err = marshalWithIndent (newParams , defaultIndent )
531
+ return override , err
532
+ }
533
+ err = yaml .Unmarshal (originalData , & params )
534
+ if err != nil {
535
+ // TODO: if err is not nill, why do we try to do marshalWithIndent and not return nil?
536
+ override , err = marshalWithIndent (newParams , defaultIndent )
537
+ return override , err
538
+ }
539
+ mergeHelmOverride (& params , & newParams )
540
+ return marshalWithIndent (params , defaultIndent )
541
+ }
542
+
543
+ // marshalParamsOverride marshals the parameter overrides of a given application
544
+ // into YAML bytes
545
+ func marshalParamsOverride (app * v1alpha1.Application , originalData []byte ) ([]byte , error ) {
546
+ var override []byte
547
+ var err error
548
+
549
+ switch GetApplicationType (app ) {
550
+ case ApplicationTypeKustomize :
551
+ override , err = marshalKustomizeOverride (app , originalData )
552
+ case ApplicationTypeHelm :
553
+ override , err = marshalHelmOverride (app , originalData )
552
554
default :
553
555
err = fmt .Errorf ("unsupported application type" )
554
556
}
0 commit comments