Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Conversation

@phsiao
Copy link
Contributor

@phsiao phsiao commented Oct 28, 2017

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.

  • Ready to review
  • Automated Tests
  • Docs

Copy link
Contributor

@andresmgot andresmgot left a 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.

Deps: deps,
Topic: topic,
Schedule: schedule,
Service: spec.ServiceSpec{
Copy link
Contributor

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)


// 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)
Copy link
Contributor

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.

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")
Copy link
Contributor

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"`
Copy link
Contributor

@andresmgot andresmgot Oct 30, 2017

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)

@phsiao
Copy link
Contributor Author

phsiao commented Oct 30, 2017

Thanks @andresmgot, I will work on addressing these feedbacks.

@andresmgot
Copy link
Contributor

Thanks @phsiao, the CLI code looks good for me. Let me know if you have any issue applying the changes in the controller

@phsiao
Copy link
Contributor Author

phsiao commented Nov 5, 2017

Failed in

# (from function `verify_function' in file tests/../script/libtest.bash, line 268,
#  from function `test_kubeless_function' in file tests/../script/libtest.bash, line 273,
#  in test file tests/integration-tests.bats, line 72)
#   `test_kubeless_function post-dotnetcore' failed with status 2
# make[1]: *** [post-dotnetcore-verify] Error 1

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?

@phsiao phsiao changed the title Add ServiceSpec to FunctionSpec WIP: Add ServiceSpec to FunctionSpec Nov 6, 2017
@phsiao
Copy link
Contributor Author

phsiao commented Nov 6, 2017

Marking it WIP, trying to figure out how to make CreateIngress and its tests play well in the test sandbox environment.

@ngtuna
Copy link
Contributor

ngtuna commented Nov 8, 2017

@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.

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")
Copy link
Contributor

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.

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")
Copy link
Contributor

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"

@phsiao
Copy link
Contributor Author

phsiao commented Nov 8, 2017

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.

@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?

@andresmgot
Copy link
Contributor

@phsiao I agree with @ngtuna, I missed the PodTemplateSpec that we are already using. It makes sense to use v1.ServiceSpec since it will allow users to specify their own yaml in the future specifying different properties of the service (not exposed by the CLI) without having to modify the code.

In the controller we will need to do something similar to what we do when creating the deployment:

	//copy all func's Spec.Template to the deployment
	tmplCopy, err := api.Scheme.DeepCopy(funcObj.Spec.Template)
	if err != nil {
		return err
	}
	dpm.Spec.Template = tmplCopy.(v1.PodTemplateSpec)

@andresmgot
Copy link
Contributor

@phsiao is the PR ready to be reviewed?

@phsiao
Copy link
Contributor Author

phsiao commented Nov 13, 2017

@andresmgot not yet, still working on the following two issues.

  1. Modify runtime image to support specifying custom port via environment variable. I have finally figured out how to test the runtimes, but it is very slow as I am testing them one-by-one when I have a chance. I will submit a pull request separately with what I think would work, and would love to see if there are faster way to test them.

  2. CreateIngress. CreateIngress appears to be decoupled from any of the kubernetes resource record, and I think it is best to change that especially with custom port. I just have not had a chance to look into how to integrate that with the existing tests.

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.

@ngtuna ngtuna self-assigned this Dec 14, 2017
@ngtuna ngtuna changed the title WIP: Add ServiceSpec to FunctionSpec Add ServiceSpec to FunctionSpec Dec 21, 2017
@ngtuna
Copy link
Contributor

ngtuna commented Dec 21, 2017

Rebased and updated createIngress to take advantage of custom port

Copy link
Contributor

@andresmgot andresmgot left a 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 {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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

@ngtuna
Copy link
Contributor

ngtuna commented Dec 27, 2017

All builds and tests passed. It's good to merge now 🛬

@ngtuna ngtuna merged commit fef344f into vmware-archive:master Dec 27, 2017
sayanh pushed a commit to sayanh/kubeless that referenced this pull request Jan 17, 2018
…functionspec

Add ServiceSpec to FunctionSpec
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants