recAllTpls recurses through the templates in a chart. As it recurses, it also sets the values to be appropriate for the template scope.
(c ci.Charter, templates map[string]renderable, values common.Values)
| 532 | // As it recurses, it also sets the values to be appropriate for the template |
| 533 | // scope. |
| 534 | func recAllTpls(c ci.Charter, templates map[string]renderable, values common.Values) map[string]any { |
| 535 | vals := values.AsMap() |
| 536 | subCharts := make(map[string]any) |
| 537 | accessor, err := ci.NewAccessor(c) |
| 538 | if err != nil { |
| 539 | slog.Error("error accessing chart", "error", err) |
| 540 | } |
| 541 | chartMetaData := accessor.MetadataAsMap() |
| 542 | chartMetaData["IsRoot"] = accessor.IsRoot() |
| 543 | |
| 544 | next := map[string]any{ |
| 545 | "Chart": chartMetaData, |
| 546 | "Files": newFiles(accessor.Files()), |
| 547 | "Release": vals["Release"], |
| 548 | "Capabilities": vals["Capabilities"], |
| 549 | "Values": make(common.Values), |
| 550 | "Subcharts": subCharts, |
| 551 | } |
| 552 | |
| 553 | // If there is a {{.Values.ThisChart}} in the parent metadata, |
| 554 | // copy that into the {{.Values}} for this template. |
| 555 | if accessor.IsRoot() { |
| 556 | next["Values"] = vals["Values"] |
| 557 | } else if vs, err := values.Table("Values." + accessor.Name()); err == nil { |
| 558 | next["Values"] = vs |
| 559 | } |
| 560 | |
| 561 | for _, child := range accessor.Dependencies() { |
| 562 | // TODO: Handle error |
| 563 | sub, _ := ci.NewAccessor(child) |
| 564 | subCharts[sub.Name()] = recAllTpls(child, templates, next) |
| 565 | } |
| 566 | |
| 567 | newParentID := accessor.ChartFullPath() |
| 568 | for _, t := range accessor.Templates() { |
| 569 | if t == nil { |
| 570 | continue |
| 571 | } |
| 572 | if !isTemplateValid(accessor, t.Name) { |
| 573 | continue |
| 574 | } |
| 575 | templates[path.Join(newParentID, t.Name)] = renderable{ |
| 576 | tpl: string(t.Data), |
| 577 | vals: next, |
| 578 | basePath: path.Join(newParentID, "templates"), |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | return next |
| 583 | } |
| 584 | |
| 585 | // isTemplateValid returns true if the template is valid for the chart type |
| 586 | func isTemplateValid(accessor ci.Accessor, templateName string) bool { |
no test coverage detected
searching dependent graphs…