-
Notifications
You must be signed in to change notification settings - Fork 42
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
Parse and Resolve the Namespace of Fission function #176
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.
Nice PR @xiekeyang 😁 Other than a couple of style-related changes, LGTM. In the meantime, I am going to clone this branch locally to trigger the CI on it
pkg/fnenv/fission/resolver.go
Outdated
@@ -15,18 +16,18 @@ func NewResolver(controller *client.Client) *Resolver { | |||
return &Resolver{controller} | |||
} | |||
|
|||
func (re *Resolver) Resolve(fnName string) (string, error) { | |||
func (re *Resolver) Resolve(ref *types.FnRef) (string, 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.
Pass ref by value; it is small enough, and we pass it by value elsewhere in the code.
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 for all other uses of FnRef in this PR ;)
pkg/fnenv/resolver.go
Outdated
@@ -182,10 +177,13 @@ func resolveTask(ps Resolver, id string, task *types.TaskSpec, resolvedC chan so | |||
if task == nil || resolvedC == nil { | |||
return nil | |||
} | |||
|
|||
// t, err := types.ParseFnRef(task.FunctionRef) |
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.
Remove this comment :)
pkg/types/types.proto
Outdated
@@ -233,8 +233,12 @@ message FnRef { | |||
// Runtime is the Function Runtime environment (fnenv) that was used to resolve the function. | |||
string runtime = 2; | |||
|
|||
|
|||
// Namespace is the namespace of the fission function. | |||
string Namespace = 3; |
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.
make the namespace lowercase (go-proto makes all defined fields public)
pkg/types/fnref.go
Outdated
) | ||
|
||
var ( | ||
fnRefReg = regexp.MustCompile(fmt.Sprintf("^(?:(\\w+)%s)?(\\w+)$", RuntimeDelimiter)) | ||
fnRefReg = regexp.MustCompile("^(?:(\\w+)://)?(?:([a-zA-Z0-9][a-zA-Z0-9_-]{1,128})/)?(\\w+)$") |
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.
Replace the ://
with a reference to the RuntimeDelimiter
constant
pkg/types/fnref.go
Outdated
) | ||
|
||
const ( | ||
groupFnRef = iota |
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 know it wasn't there before either, but could you add a comment above this group enum to explain the purpose of them? maybe: // Capture groups for the FnRef regex
pkg/fnenv/mock/mock.go
Outdated
func (mf *Resolver) Resolve(fnName string) (string, error) { | ||
fnID, ok := mf.FnNameIDs[fnName] | ||
func (mf *Resolver) Resolve(ref *types.FnRef) (string, error) { | ||
fnID, ok := mf.FnNameIDs[ref.ID] |
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.
When using FnRef
as reference, the problem is that we have to be careful with NPEs, such as here. If you turn FnRef into a value, we don't run into this problem.
FYI, cool thing about protobuf generated structs is that they generate getters (GetID()
), which have a nil check in them. So even when using pointers, it is safer to use the getters. When using values, this obviously does not matter and directly referencing the field is faster.
@@ -156,5 +156,9 @@ func createFunctionMeta(fn types.FnRef) *metav1.ObjectMeta { | |||
} | |||
|
|||
func (fe *FunctionEnv) createRouterURL(fn types.FnRef) string { | |||
return fe.routerURL + "/fission-function/" + fn.ID | |||
if fn.Namespace == metav1.NamespaceDefault { | |||
return fe.routerURL + "/fission-function/" + fn.ID |
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.
Minor detail, just wondering, is this actually needed? Doesn't $FISSION_ROUTER/fission-function/$FN
work the same as $FISSION_ROUTER/fission-function/default/$FN
? If it is, we can leave out this if condition (to simplify the code). If it is not, it is a bug (or at least something that should be the case) in Fission and we should file an issue for it.
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 check is mandatory. The correct use can refer to here
I doubt that this is a bug.
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, I raised an issue for it in the fission repo: fission/fission#819 (it is not really a bug, but it is inconsistent/unexpected behavior). We can keep it like this here :)
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 👍 You mentioned that you wanted to add an example, and you marked this PR as [WIP]. So just ping me if it is ready for a final CI run and merge.
@erwinvaneyk I fix the problems as:
PTAL, thanks so much! |
@@ -156,5 +156,9 @@ func createFunctionMeta(fn types.FnRef) *metav1.ObjectMeta { | |||
} | |||
|
|||
func (fe *FunctionEnv) createRouterURL(fn types.FnRef) string { | |||
return fe.routerURL + "/fission-function/" + fn.ID | |||
if fn.Namespace == metav1.NamespaceDefault { | |||
return fe.routerURL + "/fission-function/" + fn.ID |
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, I raised an issue for it in the fission repo: fission/fission#819 (it is not really a bug, but it is inconsistent/unexpected behavior). We can keep it like this here :)
@xiekeyang - LGTM 👍 just one test file needs to be fixed (caused by the just merged #177 ) |
@erwinvaneyk Which test file? I have rebased #177 to this PR, and run all tests on my PC. All of them are passed. Maybe I miss some cases? |
It looks like you just missed one small thing: https://github.com/xiekeyang/fission-workflows/blob/4afcfc7ec0db6b0c6ab9714b37c6e981110fcae0/pkg/fnenv/workflows/workflows_test.go#L134 errors because the function now requires a third argument (the namespace) |
@erwinvaneyk Thanks for your remind. It is really a missing. I fix and re-push it: https://github.com/fission/fission-workflows/pull/176/files#diff-bab065f585cfa1d849f4f71fa601b621R134 |
This parse the function reference from raw string with member of namespace.
This resolve a function reference in tasks which has specific namespace. It is meaningful to fission functions.
Rebased #179 , it seems no failed test. |
Verified in https://travis-ci.org/fission/fission-workflows/builds/408488542 - Nice job @xiekeyang! 🎉 |
This is for closing #160.
This supports to parse and resolve out the function namespace from workflow config file.
User can set specific namespace or left it by default.
This is meaningful to fission functions.
This parses namespace out of all kinds of runtime (fission, native...).The runtimes except fission will drop the namespace value(always
default
). So that it will not lead to invocation failure.However, later we should improve it by refactoring framework of parser and resolver, especially auto-resolving.
I didn't add it to this patch, because I want to move the individual parser interface to nested sub to resolver interface. And we might need more discussion about auto-resolver.
@erwinvaneyk WDYT?