-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Process SM related templates in memory #15
Process SM related templates in memory #15
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this improvement! I left a few suggestions about naming and small change on the way how we can structure builder so we allow other filesystems to be used easily.
When reviewing the code I found a bug in the original implementation too :)
There's also dead code I cannot comment directly on, which we could remove https://github.com/maistra/opendatahub-operator/pull/15/files#diff-897801bd6ac96d166eb19cd078cd2b46eb522fce98d8e3573f08473ca2661e70R119-R121
pkg/feature/manifest.go
Outdated
} | ||
|
||
func loadManifestsFrom(path string) ([]manifest, error) { | ||
func loadManifestsFrom(embeddedFS embed.FS, rootPath string) ([]manifest, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could align it with walk fs.WalkDir
expects. We do not need anything specific from embeddedFS
to make this whole thing work, and this is a limitation we don't need.
func loadManifestsFrom(embeddedFS embed.FS, rootPath string) ([]manifest, error) { | |
func loadManifestsFrom(fsys fs.FS, rootPath string) ([]manifest, error) { |
note: I can't apply suggestion on the whole func
so you will need to make changes in the editor, not here.
pkg/feature/manifest.go
Outdated
@@ -62,28 +75,30 @@ 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(data interface{}) error { | |||
func (m *manifest) processTemplate(fs embed.FS, data interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reasons as above
func (m *manifest) processTemplate(fs embed.FS, data interface{}) error { | |
func (m *manifest) processTemplate(fsys fs.FS, data interface{}) error { |
pkg/feature/manifest.go
Outdated
m.processedContent = buffer.String() | ||
m.processed = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we don't need m.processed
anymore. Can't we assume that if m.processedContent == ""
that means it was not a template?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8a2c375 agreed
pkg/feature/raw_resources.go
Outdated
@@ -106,7 +97,7 @@ func (f *Feature) patchResourceFromFile(filename string) error { | |||
} | |||
|
|||
// Convert the patch from YAML to JSON | |||
patchAsJSON, err := yaml.YAMLToJSON(data) | |||
patchAsJSON, err := yaml.YAMLToJSON([]byte(data)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a bug in here. We split the whole thing into chunks based on ---
separate, but instead of patching resources one by one we apply the entire data
(so all the resources all at once). This means that currently we only have single-resource files in use, that's why this bug never showed up.
We should either give up on the assumption there can be more than one resource per file OR fix it to apply one by one. I would vouch for fixing it. Can you take care of it in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/feature/builder.go
Outdated
@@ -79,7 +79,7 @@ func (fb *featureBuilder) Manifests(paths ...string) *featureBuilder { | |||
var manifests []manifest | |||
|
|||
for _, path := range paths { | |||
manifests, err = loadManifestsFrom(path) | |||
manifests, err = loadManifestsFrom(embeddedFiles, path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not quite sure about this one from the pure API perspective. By hardcoding it to the global variable (//go:embed
) we are locking it for any other sources like we made possible before.
What I would think about instead is to make fsys fs.FS
a field on the featureBuilder
struct, add extra method such as func (fb *featureBuilder) ManifestSource(fsys fs.FS) *featureBuilder
which will allow us to set it (with godoc mentioning it's a root fs from which manifest paths are loaded). By default, in the Load()
func, where we instantiate a Feature
, we would set it to embeddedFiles
and if ManifestSource
is not called in the builder chain that would stay like that. Not a big change, but gives us flexibility. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e072121 done here
return errors.WithStack(err) | ||
} | ||
|
||
log.Info("converted template to manifest", "feature", f.Name, "path", m.targetPath()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as a follow-up PR should change log levels from info to debug in most places. It's too much meaningless output in the logs now just to see that stuff is happening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comments, but I think I wasn't exactly clear on the suggestions. Here's what I had in mind:
func (fb *featureBuilder) Load() (*Feature, error) {
feature := &Feature{
Name: fb.name,
Enabled: true,
fsys: embeddedFiles,
}
+ suggestions below.
pkg/feature/builder.go
Outdated
fsys := fb.fsys | ||
if fsys == nil { | ||
fsys = embeddedFiles | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean it like this, sorry for misleading you with my original comment. I thought about using featureBuilder
to populate this field in Feature
instance eventually... let's blame it on the fact that I'm sick now.
Have a look at the follow-up suggestions.
fsys := fb.fsys | |
if fsys == nil { | |
fsys = embeddedFiles | |
} |
pkg/feature/feature.go
Outdated
@@ -159,34 +159,34 @@ func (f *Feature) addCleanup(cleanupFuncs ...Action) { | |||
|
|||
func (f *Feature) ApplyManifest(filename string) error { | |||
m := loadManifestFrom(filename) | |||
if err := m.processTemplate(f.Spec); err != nil { | |||
if err := m.processTemplate(embeddedFiles, f.Spec); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := m.processTemplate(embeddedFiles, f.Spec); err != nil { | |
if err := m.processTemplate(f.fsys, f.Spec); err != nil { |
Co-authored-by: Bartosz Majsak <bartosz.majsak@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor suggestions + bunch of commits I couldn't make as suggestions, but I hope you agree with them :)
Great job!
tests/integration/servicemesh/test-templates/authorino/mesh-authz-ext-provider.patch.tmpl
Outdated
Show resolved
Hide resolved
tests/integration/servicemesh/service_mesh_setup_features_int_test.go
Outdated
Show resolved
Hide resolved
tests/integration/servicemesh/service_mesh_setup_features_int_test.go
Outdated
Show resolved
Hide resolved
tests/integration/servicemesh/service_mesh_setup_features_int_test.go
Outdated
Show resolved
Hide resolved
Co-authored-by: Bartosz Majsak <bartosz.majsak@gmail.com>
edf0ebc
into
maistra:service-mesh-integration
This PR changes our approach with templates to now process/store the templates in memory, rather than copying .tmpl files to
/tmp/....
and then creating the .yaml files there as well.This means that when creating a feature.Manifests(path), you no longer will include the "rootdir" or similar variable in the path. See PR changes for examples of this, since you point directly to the path in
/templates
.Used image
quay.io/cgarriso/opendatahub-operator:template-in-memory
for testing, created DSCI with SM enabled as well as DSC with dashboard to ensure changes with Manifest(path) there still functioned as expected.