Fix copy comments for Folded style scalar nodes

This commit is contained in:
Phani Teja Marupaka
2020-06-26 12:22:08 -07:00
parent 85e9fa94b0
commit 600d4f2c0b
2 changed files with 33 additions and 1 deletions

View File

@@ -30,7 +30,16 @@ func (c *copier) VisitMap(s walk.Sources, _ *openapi.ResourceSchema) (*yaml.RNod
}
func (c *copier) VisitScalar(s walk.Sources, _ *openapi.ResourceSchema) (*yaml.RNode, error) {
copy(s.Dest(), s.Origin())
to := s.Origin()
// TODO: File a bug with upstream yaml to handle comments for FoldedStyle scalar nodes
// Hack: convert FoldedStyle scalar node to DoubleQuotedStyle as the line comments are
// being serialized without space
// https://github.com/GoogleContainerTools/kpt/issues/766
if to != nil && to.Document().Style == yaml.FoldedStyle {
to.Document().Style = yaml.DoubleQuotedStyle
}
copy(s.Dest(), to)
return s.Dest(), nil
}

View File

@@ -286,6 +286,29 @@ apiVersion: apps/v1
kind: Deployment
items:
- a # comment
`,
},
{
name: "copy_comments_folded_style",
from: `
apiVersion: v1
kind: ConfigMap
data:
somekey: "012345678901234567890123456789012345678901234567890123456789012345678901234" # x
`,
to: `
apiVersion: v1
kind: ConfigMap
data:
somekey: >-
012345678901234567890123456789012345678901234567890123456789012345678901234
`,
expected: `
apiVersion: v1
kind: ConfigMap
data:
somekey: "012345678901234567890123456789012345678901234567890123456789012345678901234" # x
`,
},
}