1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

Avoid empty resources

This commit is contained in:
Ewout Prangsma 2018-08-10 15:49:10 +02:00
parent e20166794c
commit a02a7cbd50
No known key found for this signature in database
GPG key ID: 4DBAD380D93D0698

View file

@ -422,19 +422,25 @@ func main() {
// Build standalone yaml file for this group
{
output := &bytes.Buffer{}
for i, tempInfo := range templateGroup.Templates {
for _, tempInfo := range templateGroup.Templates {
if tempInfo.Predicate == nil || tempInfo.Predicate(templateOptions, false) {
name := tempInfo.Name
t, err := template.New(name).ParseFiles(filepath.Join(options.TemplatesDir, group, name))
if err != nil {
log.Fatalf("Failed to parse template %s: %v", name, err)
}
if i > 0 {
output.WriteString("\n---\n\n")
// Execute to tmp buffer
tmpBuf := &bytes.Buffer{}
t.Execute(tmpBuf, templateOptions)
// Add tmp buffer to output, unless empty
if strings.TrimSpace(tmpBuf.String()) != "" {
if output.Len() > 0 {
output.WriteString("\n---\n\n")
}
output.WriteString(fmt.Sprintf("## %s/%s\n", group, name))
tmpBuf.WriteTo(output)
output.WriteString("\n")
}
output.WriteString(fmt.Sprintf("## %s/%s\n", group, name))
t.Execute(output, templateOptions)
output.WriteString("\n")
}
}
@ -457,19 +463,25 @@ func main() {
// Build helm template file for this group
{
output := &bytes.Buffer{}
for i, tempInfo := range templateGroup.Templates {
for _, tempInfo := range templateGroup.Templates {
if tempInfo.Predicate == nil || tempInfo.Predicate(chartTemplateOptions, true) {
name := tempInfo.Name
t, err := template.New(name).ParseFiles(filepath.Join(options.TemplatesDir, group, name))
if err != nil {
log.Fatalf("Failed to parse template %s: %v", name, err)
}
if i > 0 {
output.WriteString("\n---\n\n")
// Execute to tmp buffer
tmpBuf := &bytes.Buffer{}
t.Execute(tmpBuf, templateOptions)
// Add tmp buffer to output, unless empty
if strings.TrimSpace(tmpBuf.String()) != "" {
if output.Len() > 0 {
output.WriteString("\n---\n\n")
}
output.WriteString(fmt.Sprintf("## %s/%s\n", group, name))
tmpBuf.WriteTo(output)
output.WriteString("\n")
}
output.WriteString(fmt.Sprintf("## %s/%s\n", group, name))
t.Execute(output, chartTemplateOptions)
output.WriteString("\n")
}
}