-
Notifications
You must be signed in to change notification settings - Fork 68
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
Support flexible folder structures #542
Conversation
19cd42d
to
439cf00
Compare
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.
lgtm overall, a few minor things commented
codegen/module.go
Outdated
@@ -134,26 +129,10 @@ func (system *ModuleSystem) validateClassDir(class *ModuleClass, dir string) err | |||
// RegisterClassDir adds the given dir to the directories of the module class with given className. | |||
// This method allows projects built on zanzibar to have arbitrary directories to host module class | |||
// configs, therefore is mainly intended for external use. | |||
// | |||
// Deprecated: Module search paths deprecates this function. |
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.
Since we are on 0.1 release, shouldn't we just remove this method? This way we don't need do cleanup work in the future.
codegen/module.go
Outdated
@@ -218,6 +197,8 @@ func (system *ModuleSystem) populateResolvedDependencies( | |||
} | |||
|
|||
if dependencyInstance == nil { | |||
fmt.Printf("known module instances: %+v", resolvedModules) |
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.
debug leftover?
codegen/module.go
Outdated
// matched by a longer glob pattern like "endpoints/tchannel/*", so merely print a warning here | ||
// rather than failing to generate. It will fail at a later step if no globbing pattern matches | ||
// the wanted instance. | ||
fmt.Printf("warn: globbing pattern %q: %s\n", moduleDirectoryGlob, instanceErr.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.
This warning message seems unnecessary to me, it warns for each dir that does not contain a module config file, which could become quite a clutter when you have many modules nested.
codegen/module.go
Outdated
if strings.HasSuffix(instanceFile.Name(), yamlConfigSuffix) { | ||
className = strings.TrimSuffix(instanceFile.Name(), yamlConfigSuffix) | ||
yamlFileName = instanceFile.Name() | ||
// TODO(jacobg): Is this necessary? |
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 don't think it's necessary, should just delete it to avoid future confusion.
codegen/module.go
Outdated
NamePlural string | ||
ClassType moduleClassType | ||
|
||
// Deprecated: Hard coded list of directory names is replaced with dynamic module search path in build.yaml. |
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 as earlier, deletion instead of deprecation.
moduleSearchPaths: | ||
- clients/* | ||
- middlewares/* | ||
- endpoints/* |
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.
Since this is glob, I would not be surprised to see patterns like "endpoints/*/**" in the yaml file, can we have such a case to make sure things work as intended?
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.
**
is not supported, see https://golang.org/pkg/path/filepath/#Match
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.
okay, does that mean endpoint/*
does not match endpoint/foo/bar/endpoint-config.yaml
?
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.
Yes, you'd need to write endpoint/*/*
to capture that, we might want a more flexible globbing pattern library but I just used the standard library one for now.
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.
Okay, got it, this is definitely something worth to document.
439cf00
to
24f46f4
Compare
683ddd5
to
5402cdc
Compare
4120638
to
9001235
Compare
An assumption of the base module system was that the module classes (clients, endpoints, etc.) would have a single folder structure that would be extended (but not modified) by consumer applications. Specifically, the code generation system is given a base directory (
baseDirectory
) and it assumes the built-in modules would be located in exactly the subdirectory of that base directory (e.g. ifbaseDirectory = "examples/example-gateway"
thenendpoints
will always be located inexamples/example-gateway/endpoints
). That assumption is encoded in theDirectories
property, which enumerates all the places where Zanzibar will look for module instances.This poses a problem for supporting more flexible directory structures, such as keeping clients at
examples/example-gateway/clients
but allowing instances ofendpoints
to exist inexamples/example-gateway/apps/foo/endpoints
; applications could not customize the place where Zanzibar would look for module instances.This patch changes the module search logic to be more flexible. Instead of the assumption that the place where Zanzibar configuration files like
clients
will be found is known ahead of time, we instead assume that we will be provided a list of globbing patterns to enumerate all the configuration files that exist:The list will be provided in the
build.yaml
file which is provided by the application and can be customized without modifying Zanzibar. Zanzibar will then look for every instance type it is aware of in every folder. For example, you could have:There's nothing special about the relationship between the module classes and their paths.
Dependency names as stored in the
map[string][]*ModuleInstance
"tree" are now first extracted from the path name:clients/foo/client-config.yaml
foo
nested/clients/foo/client-config.yaml
nested/foo
nested/bar/foo/baz/foo-config.yaml
nested/bar/baz
app/demo/services/xyz/service-config.yaml
app/demo/xyz
As a convenience, the second to last part of the qualified name is removed (
clients/foo
is transformed tofoo
). To depend on a so-called nested dependency, you would use the qualified instance name in the dependency list:TODO:
[ ] (?) Removename
field from*-config.yaml
since it's now implied by the path