Skip to content

Commit

Permalink
rename func, use more generic fs
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-garrison committed Dec 12, 2023
1 parent b4dc2e3 commit 0807413
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ func (f *Feature) apply(m manifest) error {
applier = func(data string) error {
log.Info("patching using manifest", "feature", f.Name, "name", m.name, "path", targetPath)

return f.patchResourceFromData(data)
return f.patchResources(data)
}
} else {
applier = func(data string) error {
log.Info("applying manifest", "feature", f.Name, "name", m.name, "path", targetPath)

return f.createResourceFromData(data)
return f.createResources(data)
}
}

Expand Down
18 changes: 13 additions & 5 deletions pkg/feature/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"embed"
"fmt"
"html/template"
"io"
"io/fs"
"path/filepath"
"strings"
Expand All @@ -29,10 +30,10 @@ type manifest struct {
processedContent string
}

func loadManifestsFrom(embeddedFS embed.FS, rootPath string) ([]manifest, error) {
func loadManifestsFrom(fsys fs.FS, rootPath string) ([]manifest, error) {
var manifests []manifest

err := fs.WalkDir(embeddedFS, rootPath, func(path string, dirEntry fs.DirEntry, err error) error {
err := fs.WalkDir(fsys, rootPath, func(path string, dirEntry fs.DirEntry, err error) error {
if err != nil {
return err
}
Expand All @@ -41,7 +42,7 @@ func loadManifestsFrom(embeddedFS embed.FS, rootPath string) ([]manifest, error)
return nil
}

_, err = fs.ReadFile(embeddedFS, path)
_, err = fs.ReadFile(fsys, path)
if err != nil {
log.Error(err, "Failed to load manifest from", "path", path)
return err
Expand Down Expand Up @@ -75,12 +76,19 @@ func (m *manifest) targetPath() string {
return fmt.Sprintf("%s%s", m.path[:len(m.path)-len(filepath.Ext(m.path))], ".yaml")
}

func (m *manifest) processTemplate(fs embed.FS, data interface{}) error {
func (m *manifest) processTemplate(fsys fs.FS, data interface{}) error {
if !m.template {
return nil
}

templateContent, err := fs.ReadFile(m.path)
templateFile, err := fsys.Open(m.path)
if err != nil {
log.Error(err, "Failed to open template file", "path", m.path)
return err
}
defer templateFile.Close()

templateContent, err := io.ReadAll(templateFile)
if err != nil {
log.Error(err, "Failed to read template file", "path", m.path)
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/feature/raw_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
YamlSeparator = "(?m)^---[ \t]*$"
)

func (f *Feature) createResourceFromData(resources string) error {
func (f *Feature) createResources(resources string) error {
splitter := regexp.MustCompile(YamlSeparator)
objectStrings := splitter.Split(resources, -1)
for _, str := range objectStrings {
Expand Down Expand Up @@ -73,7 +73,7 @@ func (f *Feature) createResourceFromData(resources string) error {
return nil
}

func (f *Feature) patchResourceFromData(resources string) error {
func (f *Feature) patchResources(resources string) error {
splitter := regexp.MustCompile(YamlSeparator)
objectStrings := splitter.Split(resources, -1)
for _, str := range objectStrings {
Expand Down

0 comments on commit 0807413

Please sign in to comment.