-
Notifications
You must be signed in to change notification settings - Fork 744
Add ServiceSpec to FunctionSpec #397
Add ServiceSpec to FunctionSpec #397
Conversation
andresmgot
left a comment
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.
Thank you for the PR! I set some comments inline. Once you apply them you can continue with the support in the Controller.
cmd/kubeless/function.go
Outdated
| Deps: deps, | ||
| Topic: topic, | ||
| Schedule: schedule, | ||
| Service: spec.ServiceSpec{ |
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 case the user is updating the file these new flags may be unspecified. For not overwriting the previous behavior you need to set the default the defaultFunction (just like with the other parameters)
cmd/kubeless/function_test.go
Outdated
|
|
||
| // Given parameters should take precedence from default values | ||
| result3, err := getFunctionDescription("test", "default", "file.handler2", "function2", "dependencies2", "runtime2", "test_topic", "", "test-image2", "256Mi", false, []string{"TEST=2"}, []string{"test=2"}, expectedFunction) | ||
| result3, err := getFunctionDescription("test", "default", "file.handler2", "function2", "dependencies2", "runtime2", "test_topic", "", "test-image2", "256Mi", false, false, 8080, []string{"TEST=2"}, []string{"test=2"}, expectedFunction) |
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.
change the values so we check that the new parameters are persisted/overwritten by the default/new function.
cmd/kubeless/update.go
Outdated
| updateCmd.Flags().StringP("schedule", "", "", "Specify schedule in cron format for scheduled function") | ||
| updateCmd.Flags().Bool("trigger-http", false, "Deploy a http-based function to Kubeless") | ||
| updateCmd.Flags().StringP("runtime-image", "", "", "Custom runtime image") | ||
| updateCmd.Flags().Bool("headless", false, "Deploy the function as a headless service") |
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 would disable the headless parameter for the update command or make a function that actually checks if the value has been set (it is doable going over the provided parameters with the flag.Visit function). Since it is a boolean, it is difficult to say if the user wants to update its value to false or if the flag is missing.
Also I would set here the default value of the port to -1 or something like that to differentiate the intention of the user (and not use it if the value is the default).
pkg/spec/spec.go
Outdated
|
|
||
| // ServiceSpec contains service specification for a FunctionSpec | ||
| type ServiceSpec struct { | ||
| Headless bool `json:"headless"` |
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.
can you add a small inline comment explaining what is the purpose of each field? (I am doing the same for the FunctionSpec in other PR)
|
Thanks @andresmgot, I will work on addressing these feedbacks. |
|
Thanks @phsiao, the CLI code looks good for me. Let me know if you have any issue applying the changes in the controller |
|
Failed in Ironically, the dotnetcore image is the one that I has not touched to add support for customized port. Is there a way to get more details of the error? |
|
Marking it WIP, trying to figure out how to make CreateIngress and its tests play well in the test sandbox environment. |
|
@phsiao @andresmgot Just a suggestion: I would prefer to embed the whole official v1.ServiceSpec into FunctionSpec as the same way we did with v1.PodTemplateSpec, rather than introducing new service struct with two duplicated fields (headless can be defined with 'ServiceSpec.ClusterIP=none') and eventually add more. That would give more flexible and extensible to our function definition in future. |
cmd/kubeless/deploy.go
Outdated
| deployCmd.Flags().StringP("memory", "", "", "Request amount of memory, which is measured in bytes, for the function. It is expressed as a plain integer or a fixed-point interger with one of these suffies: E, P, T, G, M, K, Ei, Pi, Ti, Gi, Mi, Ki") | ||
| deployCmd.Flags().Bool("trigger-http", false, "Deploy a http-based function to Kubeless") | ||
| deployCmd.Flags().StringP("runtime-image", "", "", "Custom runtime image") | ||
| deployCmd.Flags().Bool("headless", false, "Deploy the function as a headless service") |
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.
The description probably confuses users what exactly function as a headless service is. I would rather say: "deploy the function without IP and load balancing support from Kubernetes. See: https://kubernetes.io/docs/concepts/services-networking/service/#headless-services"
Or something like that.
cmd/kubeless/deploy.go
Outdated
| deployCmd.Flags().Bool("trigger-http", false, "Deploy a http-based function to Kubeless") | ||
| deployCmd.Flags().StringP("runtime-image", "", "", "Custom runtime image") | ||
| deployCmd.Flags().Bool("headless", false, "Deploy the function as a headless service") | ||
| deployCmd.Flags().Int32("port", 8080, "Deploy the function as a service listens on the specified port") |
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 ^ "Deploy the function with a custom port"
@ngtuna I actually don't mind taking that approach, just feel that would be a larger change and did not know if it is worthwhile. Now I have a better idea of the code, I am less concerned about taking that approach. @andresmgot thought? |
|
@phsiao I agree with @ngtuna, I missed the PodTemplateSpec that we are already using. It makes sense to use In the controller we will need to do something similar to what we do when creating the deployment: |
|
@phsiao is the PR ready to be reviewed? |
|
@andresmgot not yet, still working on the following two issues.
However, other than those two, I think the patch can be reviewed/commented, just can't be merged because it does not have all the bits it needs to work. |
|
Rebased and updated createIngress to take advantage of custom port |
andresmgot
left a comment
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, just a couple of questions/suggestions
| } | ||
|
|
||
| port := funcObj.Spec.ServiceSpec.Ports[0].TargetPort | ||
| if port.IntVal <= 0 || port.IntVal > 65535 { |
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.
you don't need to do this check, you can delegate the validation to the kubernetes library
| } | ||
| var headless *bool = nil | ||
| var port *int32 = nil | ||
| cmd.Flags().Visit(func(flag *pflag.Flag) { |
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.
why doing this loop instead of just retrieving the values like in deployCmd?
| logrus.Fatal(err) | ||
| } | ||
|
|
||
| if port != nil && (*port <= 0 || *port > 65535) { |
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 would set this check in the getFunctionDescription function so you don't need to repeat it twice
…th customization. - ServiceSpec is built and attach to FucntionSpec in during function deploy and update. - Always builds customized ServiceSpec even when trigger-http is false to matchc current behavior.
|
All builds and tests passed. It's good to merge now 🛬 |
…functionspec Add ServiceSpec to FunctionSpec
Add ServiceSpec to FunctionSpec so it can support creating Service with customizations.
ServiceSpec contains headless (boolean) and port (integer).
I have not updated the controller yet to take advantage of this, but want to run it by the reviewers first.