@@ -17,7 +17,7 @@ import (
1717// TemplateDir processes the template files in the specified directory and writes
1818// the rendered content to the corresponding files in the Git repository's worktree.
1919// It uses the provided template directory and Git repository to perform the operations.
20- func TemplateDir (templateDirectory string , repo * git.Repository ) error {
20+ func TemplateDir (templateDirectory string , templateInput map [ string ] interface {}, repo * git.Repository ) error {
2121 logger := log .GetLogger ()
2222
2323 workTree , err := repo .Worktree ()
@@ -36,7 +36,6 @@ func TemplateDir(templateDirectory string, repo *git.Repository) error {
3636 }()
3737
3838 te := template .NewTemplateExecution ()
39- templateInput := make (map [string ]interface {})
4039
4140 // Recursively walk through all files in the template directory
4241 err = filepath .WalkDir (templateDirectory , func (path string , d os.DirEntry , walkError error ) error {
@@ -63,14 +62,18 @@ func TemplateDir(templateDirectory string, repo *git.Repository) error {
6362 return fmt .Errorf ("failed to read template file %s: %w" , relativePath , err )
6463 }
6564
66- templateResult , errInWalk = te .Execute (path , string (templateFromFile ), templateInput )
67- if err != nil {
68- return fmt .Errorf ("failed to execute template %s: %w" , relativePath , err )
65+ wrappedTemplateInput := map [string ]interface {}{
66+ "values" : templateInput ,
67+ }
68+
69+ templateResult , errInWalk = te .Execute (path , string (templateFromFile ), wrappedTemplateInput )
70+ if errInWalk != nil {
71+ return fmt .Errorf ("failed to execute template %s: %w" , relativePath , errInWalk )
6972 }
7073
7174 fileInWorkTree , errInWalk = workTree .Filesystem .OpenFile (relativePath , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , 0644 )
7275 if errInWalk != nil {
73- return fmt .Errorf ("failed to open file in worktree %s: %w" , relativePath , err )
76+ return fmt .Errorf ("failed to open file in worktree %s: %w" , relativePath , errInWalk )
7477 }
7578 defer func (pathInRepo billy.File ) {
7679 err := pathInRepo .Close ()
@@ -81,12 +84,12 @@ func TemplateDir(templateDirectory string, repo *git.Repository) error {
8184
8285 _ , errInWalk = fileInWorkTree .Write (templateResult )
8386 if errInWalk != nil {
84- return fmt .Errorf ("failed to write to file in worktree %s: %w" , relativePath , err )
87+ return fmt .Errorf ("failed to write to file in worktree %s: %w" , relativePath , errInWalk )
8588 }
8689
8790 // Add the file to the git index
8891 if _ , errInWalk = workTree .Add (relativePath ); errInWalk != nil {
89- return fmt .Errorf ("failed to add file to git index: %w" , err )
92+ return fmt .Errorf ("failed to add file to git index: %w" , errInWalk )
9093 }
9194 }
9295 return nil
@@ -188,11 +191,12 @@ func TemplateProviders(ctx context.Context, clusterProviders, serviceProviders,
188191}
189192
190193func getImageResource (cv * ocmcli.ComponentVersion ) (* ocmcli.Resource , error ) {
191- for _ , resource := range cv .Component . Resources {
192- if resource . Type == "ociImage" {
193- return & resource , nil
194- }
194+ resources := cv .GetResourcesByType ( ocmcli . OCIImageResourceType )
195+
196+ if len ( resources ) > 0 {
197+ return & resources [ 0 ], nil
195198 }
199+
196200 return nil , fmt .Errorf ("image resource not found for component %s" , cv .Component .Name )
197201}
198202
@@ -219,8 +223,8 @@ func templateProvider(options *ProviderOptions, templateSource, dir string, repo
219223 "values" : map [string ]interface {}{
220224 "name" : options .Name ,
221225 "image" : map [string ]interface {}{
222- "location" : options .Image ,
223- "pullSecrets " : options .ImagePullSecrets ,
226+ "location" : options .Image ,
227+ "imagePullSecrets " : options .ImagePullSecrets ,
224228 },
225229 },
226230 }
0 commit comments