@@ -19,7 +19,9 @@ package util
1919import (
2020 "bufio"
2121 "bytes"
22+ "embed"
2223 "fmt"
24+ "io/fs"
2325 "os"
2426 "path"
2527 "path/filepath"
@@ -29,6 +31,9 @@ import (
2931 corev1 "k8s.io/api/core/v1"
3032)
3133
34+ //go:embed templates/common/config/*
35+ var commonTemplates embed.FS
36+
3237// TType - TemplateType
3338type TType string
3439
@@ -344,3 +349,34 @@ func GetTemplateData(t Template) (map[string]string, error) {
344349
345350 return data , nil
346351}
352+
353+ // GetCommonTemplates renders the common config templates (ssl.conf, etc.)
354+ // shipped with lib-common using the provided configOptions, and returns
355+ // map[filename]renderedContent.
356+ // Callers merge the result into their Template.CustomData before calling
357+ // EnsureSecrets/EnsureConfigMaps so that common templates are included in the
358+ // generated Secret/ConfigMaps without each operator duplicating the files.
359+ func GetCommonTemplates (configOptions map [string ]any ) (map [string ]string , error ) {
360+ dir := "templates/common/config"
361+ entries , err := fs .ReadDir (commonTemplates , dir )
362+ if err != nil {
363+ return nil , err
364+ }
365+
366+ result := make (map [string ]string , len (entries ))
367+ for _ , e := range entries {
368+ if e .IsDir () {
369+ continue
370+ }
371+ data , err := fs .ReadFile (commonTemplates , path .Join (dir , e .Name ()))
372+ if err != nil {
373+ return nil , err
374+ }
375+ rendered , err := ExecuteTemplateData (string (data ), configOptions )
376+ if err != nil {
377+ return nil , err
378+ }
379+ result [e .Name ()] = rendered
380+ }
381+ return result , nil
382+ }
0 commit comments