github.com/replicatedhq/ship@v0.55.0/pkg/lifecycle/render/helm/render.go (about) 1 package helm 2 3 import ( 4 "context" 5 6 "github.com/pkg/errors" 7 "github.com/replicatedhq/libyaml" 8 "github.com/replicatedhq/ship/pkg/api" 9 "github.com/replicatedhq/ship/pkg/lifecycle/render/github" 10 "github.com/replicatedhq/ship/pkg/lifecycle/render/root" 11 ) 12 13 // Renderer is something that can render a helm asset as part of a planner.Plan 14 type Renderer interface { 15 Execute( 16 rootFs root.Fs, 17 asset api.HelmAsset, 18 meta api.ReleaseMetadata, 19 templateContext map[string]interface{}, 20 configGroups []libyaml.ConfigGroup, 21 ) func(ctx context.Context) error 22 } 23 24 var _ Renderer = &LocalRenderer{} 25 26 // LocalRenderer can add a helm step to the plan, the step will fetch the 27 // chart to a temporary location and then run a local operation to run the helm templating 28 type LocalRenderer struct { 29 Templater Templater 30 Fetcher ChartFetcher 31 GitHub github.Renderer 32 } 33 34 // NewRenderer makes a new renderer 35 func NewRenderer(cloner ChartFetcher, templater Templater, github github.Renderer) Renderer { 36 return &LocalRenderer{ 37 Fetcher: cloner, 38 Templater: templater, 39 GitHub: github, 40 } 41 } 42 43 func (r *LocalRenderer) Execute( 44 rootFs root.Fs, 45 asset api.HelmAsset, 46 meta api.ReleaseMetadata, 47 templateContext map[string]interface{}, 48 configGroups []libyaml.ConfigGroup, 49 ) func(ctx context.Context) error { 50 return func(ctx context.Context) error { 51 chartLocation, err := r.Fetcher.FetchChart( 52 ctx, 53 asset, 54 rootFs.RootPath, 55 meta, 56 configGroups, 57 templateContext, 58 ) 59 60 if err != nil { 61 return errors.Wrap(err, "fetch chart") 62 } 63 64 err = r.Templater.Template(chartLocation, rootFs, asset, meta, configGroups, templateContext) 65 if err != nil { 66 return errors.Wrap(err, "execute templating") 67 } 68 69 return nil 70 } 71 72 }