Skip to content

Commit ea00827

Browse files
committed
feat: add field for retaining first doc separator
1 parent 72b0fd1 commit ea00827

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

kyaml/kio/byteio_reader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ type ByteReader struct {
160160
// AnchorsAweigh set to true attempts to replace all YAML anchor aliases
161161
// with their definitions (anchor values) immediately after the read.
162162
AnchorsAweigh bool
163+
164+
// PreserveInitialDocSep if true adds the kioutil.PreserveInitialDocSep annotation to the first resource
165+
PreserveInitialDocSep bool
163166
}
164167

165168
var _ Reader = &ByteReader{}
@@ -333,6 +336,10 @@ func (r *ByteReader) decode(originalYAML string, index int, decoder *yaml.Decode
333336
r.SetAnnotations[kioutil.SeqIndentAnnotation] = seqIndentStyle
334337
}
335338
}
339+
340+
if index == 0 && r.PreserveInitialDocSep && node.Kind == yaml.DocumentNode {
341+
r.SetAnnotations[kioutil.InitialDocSepAnnotation] = "true"
342+
}
336343
}
337344
var keys []string
338345
for k := range r.SetAnnotations {

kyaml/kio/kioutil/kioutil.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const (
3030
// SeqIndentAnnotation records the sequence nodes indentation of the input resource
3131
SeqIndentAnnotation AnnotationKey = internalPrefix + "seqindent"
3232

33+
// InitialDocSepAnnotation indicates that the initial document separator should be kept
34+
InitialDocSepAnnotation AnnotationKey = internalPrefix + "initial-doc-sep"
35+
3336
// IdAnnotation records the id of the resource to map inputs to outputs
3437
IdAnnotation AnnotationKey = internalPrefix + "id"
3538

0 commit comments

Comments
 (0)