mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Using single quote style when setting annotations
Annotations must be strings. Use single-quote style so tools don't get confused about the type.
This commit is contained in:
@@ -637,12 +637,12 @@ func TestSetAnnotation_Fn(t *testing.T) {
|
||||
kind: Deployment`))
|
||||
|
||||
rn := assertNoError(t)(r0.Pipe(SetAnnotation("a.b.c", "d.e.f")))
|
||||
assert.Equal(t, "d.e.f\n", assertNoErrorString(t)(rn.String()))
|
||||
assert.Equal(t, "'d.e.f'\n", assertNoErrorString(t)(rn.String()))
|
||||
assert.Equal(t, `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
a.b.c: d.e.f
|
||||
a.b.c: 'd.e.f'
|
||||
`, assertNoErrorString(t)(r0.String()))
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,13 @@ type AnnotationSetter struct {
|
||||
}
|
||||
|
||||
func (s AnnotationSetter) Filter(rn *RNode) (*RNode, error) {
|
||||
// some tools get confused about the type if annotations are not quoted
|
||||
v := NewScalarRNode(s.Value)
|
||||
v.YNode().Tag = "!!str"
|
||||
v.YNode().Style = yaml.SingleQuotedStyle
|
||||
return rn.Pipe(
|
||||
PathGetter{Path: []string{"metadata", "annotations"}, Create: yaml.MappingNode},
|
||||
FieldSetter{Name: s.Key, Value: NewScalarRNode(s.Value)})
|
||||
FieldSetter{Name: s.Key, Value: v})
|
||||
}
|
||||
|
||||
func SetAnnotation(key, value string) AnnotationSetter {
|
||||
|
||||
Reference in New Issue
Block a user