-
Notifications
You must be signed in to change notification settings - Fork 472
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
Refactor label parsing to set OF labels last #229
Refactor label parsing to set OF labels last #229
Conversation
Question for @alexellis and @stefanprodan, while writing this I noticed that we are using pointers to maps in the request. Concretely Edit: here is the reference playground snippet https://play.golang.org/p/8h5ufOIjn5b |
There will be a Go-specific reason for using a reference here. Wouldn't changing it be a breaking change to the whole project? Example of indexing: https://play.golang.org/p/cFdZ-Agh6ii |
handlers/labels.go
Outdated
// OFFunctionNameLabel is the label key used by OpenFaaS to store the function name | ||
// on the resources managed by OpenFaaS for that function. This key is also used to | ||
// denote that a resource is a "Function" | ||
OFFunctionNameLabel = "faas_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.
What does the OF
prefix add?
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.
In retrospect, those aren't needed. I will remove them
handlers/labels.go
Outdated
|
||
// getMinReplicaCount extracts the functions minimum replica count from the user's | ||
// request labels. If the value is not found, this will return the default value, 1. | ||
func getMinReplicaCount(labels *map[string]string) *int32 { |
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.
It would be better to return an error than logging an 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 will update it to return an error, I was simply moved the existing function. The error printing was in the original 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.
What is the expected error behavior if we can't parse the replica count value? Or if the value is non-valid? should the caller (the handler in or a helper to the handler) also return the error or should it ignore the error and set it to the minimum, which is the current behavior?
handlers/labels.go
Outdated
|
||
// parseLabels will copy the user request labels and ensure that any required internal labels | ||
// are set appropriately. | ||
func parseLabels(functionName string, requestLables *map[string]string) map[string]string { |
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'm not seeing any parsing in parseLabels
. Is this the correct name for the 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.
Reasonable alternatives could be buildLabels
or getLabels
handlers/deploy.go
Outdated
} | ||
|
||
initialReplicas := getMinReplicaCount(request.Labels) | ||
labels := parseLabels(request.Service, request.Labels) |
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 the UID value should also be added 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.
Sounds good, I originally intended to fold that into the function but wasn't very sure if since the logic only existed in the update
I have pushed changes for each of your comments, they are individual commits to make it easier to review each change. I can squash the commits once it is approved. Thinking more about how changing the I was mostly curious from an academic perspective if there was a specific feature or capability that using a pointer there enabled? It isn't obvious to me and I am just looking to learn more. |
dca3875
to
b24d6fe
Compare
I just rebased on master and I am now getting build errors
|
b24d6fe
to
da51428
Compare
**What** - Ensure that internal OF labels are set after user labels to ensure that users do no override these internal values - Refactor the getMinReplicaCount to work with the labels pointer, this helps simplify the control flow in the handler methods - Add constants for the label keys and update all references to those keys throughout Closes openfaas#209 Signed-off-by: Lucas Roesler <[email protected]>
Signed-off-by: Lucas Roesler <[email protected]>
**What** - moves the uid label into a constant - sets it inside the labels method so that it is applied consistently Signed-off-by: Lucas Roesler <[email protected]>
**What** - rename parseLabels to buildLables to make the name more semantic Signed-off-by: Lucas Roesler <[email protected]>
**What** - Return parsing errors from getMinReplicaCount - Add tests for the expected errors Signed-off-by: Lucas Roesler <[email protected]>
da51428
to
6edf7e3
Compare
I need more time to understand this before merging. |
Description
that users do no override these internal values
helps simplify the control flow in the handler methods
keys throughout
Motivation and Context
Closes #209
How Has This Been Tested?
Unit tests have been added and I have tested in minikube
Types of changes
Checklist:
git commit -s