|
|
@ -18,7 +18,7 @@ package releaseutil
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// SimpleHead defines what the structure of the head of a manifest file
|
|
|
|
// SimpleHead defines what the structure of the head of a manifest file
|
|
|
@ -31,17 +31,18 @@ type SimpleHead struct {
|
|
|
|
} `json:"metadata,omitempty"`
|
|
|
|
} `json:"metadata,omitempty"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sep = regexp.MustCompile("(?:^|\\s*\n)---\\s*")
|
|
|
|
|
|
|
|
|
|
|
|
// SplitManifests takes a string of manifest and returns a map contains individual manifests
|
|
|
|
// SplitManifests takes a string of manifest and returns a map contains individual manifests
|
|
|
|
func SplitManifests(bigfile string) map[string]string {
|
|
|
|
func SplitManifests(bigfile string) map[string]string {
|
|
|
|
// This is not the best way of doing things, but it's how k8s itself does it.
|
|
|
|
|
|
|
|
// Basically, we're quickly splitting a stream of YAML documents into an
|
|
|
|
// Basically, we're quickly splitting a stream of YAML documents into an
|
|
|
|
// array of YAML docs. In the current implementation, the file name is just
|
|
|
|
// array of YAML docs. In the current implementation, the file name is just
|
|
|
|
// a place holder, and doesn't have any further meaning.
|
|
|
|
// a place holder, and doesn't have any further meaning.
|
|
|
|
sep := "\n---\n"
|
|
|
|
|
|
|
|
tpl := "manifest-%d"
|
|
|
|
tpl := "manifest-%d"
|
|
|
|
res := map[string]string{}
|
|
|
|
res := map[string]string{}
|
|
|
|
tmp := strings.Split(bigfile, sep)
|
|
|
|
// Making sure that any extra whitespace in YAML stream doesn't interfere in splitting documents correctly.
|
|
|
|
for i, d := range tmp {
|
|
|
|
docs := sep.Split(bigfile, -1)
|
|
|
|
|
|
|
|
for i, d := range docs {
|
|
|
|
res[fmt.Sprintf(tpl, i)] = d
|
|
|
|
res[fmt.Sprintf(tpl, i)] = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
return res
|
|
|
|