Skip to content

Commit 91b359f

Browse files
committed
fix: always set str tag on string scalars
When yaml.v3 parses yaml, string scalars are tagged "!!str". It is possible that we could parse a values file which sets the version to eg 1.23 (a float), so that when we later update the value to "v2.4" it can't be serialized. To protect against this, set the tag whenever we create or update scalars that are explicitly intended to be strings. Signed-off-by: Brian Ewins <bewins@nerdwallet.com>
1 parent 81c0e65 commit 91b359f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pkg/argocd/update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ func setHelmValue(currentValues *yaml.Node, key string, value interface{}) error
627627
// If we're at the final key, set the value and return
628628
if current.Kind == yaml.ScalarNode {
629629
current.Value = value.(string)
630+
current.Tag = "!!str"
630631
} else {
631632
return fmt.Errorf("unexpected type %s for key %s", nodeKindString(current.Kind), k)
632633
}
@@ -640,10 +641,12 @@ func setHelmValue(currentValues *yaml.Node, key string, value interface{}) error
640641
&yaml.Node{
641642
Kind: yaml.ScalarNode,
642643
Value: k,
644+
Tag: "!!str",
643645
},
644646
&yaml.Node{
645647
Kind: yaml.ScalarNode,
646648
Value: value.(string),
649+
Tag: "!!str",
647650
},
648651
)
649652
return nil
@@ -652,6 +655,7 @@ func setHelmValue(currentValues *yaml.Node, key string, value interface{}) error
652655
&yaml.Node{
653656
Kind: yaml.ScalarNode,
654657
Value: k,
658+
Tag: "!!str",
655659
},
656660
&yaml.Node{
657661
Kind: yaml.MappingNode,

0 commit comments

Comments
 (0)