MCPcopy
hub / github.com/helm/helm / recAllTpls

Function recAllTpls

pkg/engine/engine.go:534–583  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

532// As it recurses, it also sets the values to be appropriate for the template
533// scope.
534func 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
586func isTemplateValid(accessor ci.Accessor, templateName string) bool {

Callers 1

allTemplatesFunction · 0.85

Calls 12

MetadataAsMapMethod · 0.95
IsRootMethod · 0.95
FilesMethod · 0.95
NameMethod · 0.95
DependenciesMethod · 0.95
ChartFullPathMethod · 0.95
TemplatesMethod · 0.95
newFilesFunction · 0.85
isTemplateValidFunction · 0.85
AsMapMethod · 0.80
TableMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…