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

Commit

Permalink
Remove --trigger-http flag (#654)
Browse files Browse the repository at this point in the history
* Remove --trigger-http flag

* Remove unnecessary test
  • Loading branch information
andresmgot authored Mar 27, 2018
1 parent 7709a30 commit f5d6534
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 89 deletions.
52 changes: 3 additions & 49 deletions cmd/kubeless/function/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ var deployCmd = &cobra.Command{
}
funcName := args[0]

triggerHTTP, err := cmd.Flags().GetBool("trigger-http")
if err != nil {
logrus.Fatal(err)
}

schedule, err := cmd.Flags().GetString("schedule")
if err != nil {
logrus.Fatal(err)
Expand Down Expand Up @@ -198,46 +193,7 @@ var deployCmd = &cobra.Command{
logrus.Infof("Function %s submitted for deployment", funcName)
logrus.Infof("Check the deployment status executing 'kubeless function ls %s'", funcName)

triggers := []bool{triggerHTTP, topic != "", schedule != ""}
triggerCount := 0
for _, v := range triggers {
if v {
triggerCount++
}
}
if triggerCount > 1 {
logrus.Fatal("exactly one of --trigger-http, --trigger-topic, --schedule must be specified")
}

// Specifying trigger is not mandatory, if no trigger is specified then just return
if triggerCount == 0 {
return
}

switch {
case triggerHTTP:
httpTrigger := kubelessApi.HTTPTrigger{}
httpTrigger.TypeMeta = metav1.TypeMeta{
Kind: "HTTPTrigger",
APIVersion: "kubeless.io/v1beta1",
}
httpTrigger.ObjectMeta = metav1.ObjectMeta{
Name: funcName,
Namespace: ns,
}
httpTrigger.ObjectMeta.Labels = map[string]string{
"created-by": "kubeless",
"function": funcName,
}
httpTrigger.Spec.FunctionName = funcName
httpTrigger.Spec.RouteName = funcName

err = utils.CreateHTTPTriggerCustomResource(kubelessClient, &httpTrigger)
if err != nil {
logrus.Fatalf("Failed to deploy HTTP job trigger %s. Received:\n%s", funcName, err)
}
break
case schedule != "":
if schedule != "" {
cronJobTrigger := kubelessApi.CronJobTrigger{}
cronJobTrigger.TypeMeta = metav1.TypeMeta{
Kind: "CronJobTrigger",
Expand All @@ -257,8 +213,8 @@ var deployCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Failed to deploy cron job trigger %s. Received:\n%s", funcName, err)
}
break
case topic != "":
}
if topic != "" {
kafkaTrigger := kubelessApi.KafkaTrigger{}
kafkaTrigger.TypeMeta = metav1.TypeMeta{
Kind: "KafkaTrigger",
Expand All @@ -278,7 +234,6 @@ var deployCmd = &cobra.Command{
if err != nil {
logrus.Fatalf("Failed to deploy Kafka trigger %s. Received:\n%s", funcName, err)
}
break
}
},
}
Expand All @@ -296,7 +251,6 @@ func init() {
deployCmd.Flags().StringP("schedule", "", "", "Specify schedule in cron format for scheduled function")
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().StringP("cpu", "", "", "Request amount of cpu for the function, which is measured in units of cores. Please see the following link for more information: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu")
deployCmd.Flags().Bool("trigger-http", false, "Deploy a http-based function to Kubeless")
deployCmd.Flags().StringP("runtime-image", "", "", "Custom runtime image")
deployCmd.Flags().StringP("timeout", "", "180", "Maximum timeout (in seconds) for the function to complete its execution")
deployCmd.Flags().Bool("headless", false, "Deploy http-based function without a single service IP and load balancing support from Kubernetes. See: https://kubernetes.io/docs/concepts/services-networking/service/#headless-services")
Expand Down
3 changes: 0 additions & 3 deletions cmd/kubeless/function/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ func init() {
updateCmd.Flags().StringArrayP("env", "", []string{}, "Specify environment variable of the function")
updateCmd.Flags().StringP("namespace", "", "", "Specify namespace for the function")
updateCmd.Flags().StringP("dependencies", "", "", "Specify a file containing list of dependencies for the function")
updateCmd.Flags().StringP("trigger-topic", "", "", "Deploy a pubsub function to Kubeless")
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().StringP("timeout", "", "180", "Maximum timeout (in seconds) for the function to complete its execution")
updateCmd.Flags().Bool("headless", false, "Deploy http-based function without a single service IP and load balancing support from Kubernetes. See: https://kubernetes.io/docs/concepts/services-networking/service/#headless-services")
Expand Down
5 changes: 1 addition & 4 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ You create it with:
```console
$ kubeless function deploy get-python --runtime python2.7 \
--from-file test.py \
--handler test.foobar \
--trigger-http
--handler test.foobar
INFO[0000] Deploying function...
INFO[0000] Function get-python submitted for deployment
INFO[0000] Check the deployment status executing 'kubeless function ls get-python'
Expand All @@ -85,11 +84,9 @@ Let's dissect the command:
* `--from-file test.py`: This is the file containing the function code. It is supported to specify a zip file as far as it doesn't exceed the maximum size for an etcd entry (1 MB).
* `--handler test.foobar`: This specifies the file and the exposed function that will be used when receiving requests. In this example we are using the function `foobar` from the file `test.py`.
* `--env` to pass env vars to the function like `--env foo=bar,bar=foo`. See the [detail](https://github.com/kubeless/kubeless/pull/316#issuecomment-332172876)
* `--trigger-http`: This sets the function trigger.

Other available options are:

* `--trigger-http` to trigger the function using HTTP requests.
* `--trigger-topic` to trigger the function with a certain Kafka topic. See the [next example](#pubsub-function).
* `--timeout` to specify the timeout (in seconds) for the function to complete its execution (default "180")
* `--schedule` to trigger the function following a certain schedule using Cron notation. F.e. `--schedule "*/10 * * * *"` would trigger the function every 10 minutes.
Expand Down
1 change: 0 additions & 1 deletion docs/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Try our example:
```console
$ cd examples
$ kubeless function deploy get-python \
--trigger-http \
--runtime python2.7 \
--handler helloget.foo \
--from-file python/helloget.py
Expand Down
5 changes: 2 additions & 3 deletions docs/runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ $ kubeless function deploy myFunction --runtime nodejs6 \
--env NPM_SCOPE=@myorg \
--dependencies package.json \
--handler test.foobar \
--from-file test.js \
--trigger-http
--from-file test.js
```

### Python HTTP Trigger
Expand Down Expand Up @@ -152,7 +151,7 @@ $ kubeless function deploy \
--from-file ./handler.py \
--handler handler.hello \
--runtime python2.7 \
--trigger-http hello
hello
$ kubeless function ls
NAME NAMESPACE HANDLER RUNTIME TYPE TOPIC
get-python default foo.foo python2.7 HTTP
Expand Down
52 changes: 26 additions & 26 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
get-python:
kubeless function deploy get-python --trigger-http --runtime python2.7 --handler helloget.foo --from-file python/helloget.py
kubeless function deploy get-python --runtime python2.7 --handler helloget.foo --from-file python/helloget.py

get-python-verify:
kubeless function call get-python |egrep hello.world
Expand All @@ -14,13 +14,13 @@ get-python-update-verify:
kubeless function call get-python |egrep hello.world.updated

get-python-deps:
kubeless function deploy get-python-deps --trigger-http --runtime python2.7 --handler helloget.foo --from-file python/hellowithdeps.py --dependencies python/requirements.txt
kubeless function deploy get-python-deps --runtime python2.7 --handler helloget.foo --from-file python/hellowithdeps.py --dependencies python/requirements.txt

get-python-deps-verify:
kubeless function call get-python-deps |egrep Google

get-python-custom-port:
kubeless function deploy get-python-custom-port --trigger-http --runtime python2.7 --handler helloget.foo --from-file python/helloget.py --port 8081
kubeless function deploy get-python-custom-port --runtime python2.7 --handler helloget.foo --from-file python/helloget.py --port 8081

get-python-custom-port-verify:
kubectl get svc get-python-custom-port -o yaml | grep 'targetPort: 8081'
Expand All @@ -39,13 +39,13 @@ get-python-deps-update-verify:
kubectl exec -it $(pod) pip freeze | grep -q "twitter=="

get-python-34:
kubeless function deploy get-python --trigger-http --runtime python3.4 --handler helloget.foo --from-file python/helloget.py
kubeless function deploy get-python --runtime python3.4 --handler helloget.foo --from-file python/helloget.py

get-python-34-verify:
kubeless function call get-python |egrep hello.world

get-python-36:
kubeless function deploy get-python-36 --trigger-http --runtime python3.6 --handler helloget.foo --from-file python/helloget.py
kubeless function deploy get-python-36 --runtime python3.6 --handler helloget.foo --from-file python/helloget.py

get-python-36-verify:
kubeless function call get-python-36 |egrep hello.world
Expand All @@ -72,21 +72,21 @@ scheduled-get-python-verify:
timeout-python:
$(eval TMPDIR := $(shell mktemp -d))
printf 'def foo(event, context):\n%4swhile 1: pass\n%4sreturn "hello world"\n' > $(TMPDIR)/hello-loop.py
kubeless function deploy timeout-python --trigger-http --runtime python2.7 --handler helloget.foo --from-file $(TMPDIR)/hello-loop.py --timeout 3
kubeless function deploy timeout-python --runtime python2.7 --handler helloget.foo --from-file $(TMPDIR)/hello-loop.py --timeout 3
rm -rf $(TMPDIR)

timeout-python-verify:
$(eval MSG := $(shell kubeless function call timeout-python 2>&1 || true))
echo $(MSG) | egrep Request.timeout.exceeded

get-nodejs:
kubeless function deploy get-nodejs --trigger-http --runtime nodejs6 --handler helloget.foo --from-file nodejs/helloget.js
kubeless function deploy get-nodejs --runtime nodejs6 --handler helloget.foo --from-file nodejs/helloget.js

get-nodejs-verify:
kubeless function call get-nodejs |egrep hello.world

get-nodejs-custom-port:
kubeless function deploy get-nodejs-custom-port --trigger-http --runtime nodejs6 --handler helloget.foo --from-file nodejs/helloget.js --port 8083
kubeless function deploy get-nodejs-custom-port --runtime nodejs6 --handler helloget.foo --from-file nodejs/helloget.js --port 8083

get-nodejs-custom-port-verify:
kubectl get svc get-nodejs-custom-port -o yaml | grep 'targetPort: 8083'
Expand All @@ -95,54 +95,54 @@ get-nodejs-custom-port-verify:
timeout-nodejs:
$(eval TMPDIR := $(shell mktemp -d))
printf 'module.exports = { foo: function (event, context) { while(true) {} } }\n' > $(TMPDIR)/hello-loop.js
kubeless function deploy timeout-nodejs --trigger-http --runtime nodejs6 --handler helloget.foo --from-file $(TMPDIR)/hello-loop.js --timeout 4
kubeless function deploy timeout-nodejs --runtime nodejs6 --handler helloget.foo --from-file $(TMPDIR)/hello-loop.js --timeout 4
rm -rf $(TMPDIR)

timeout-nodejs-verify:
$(eval MSG := $(shell kubeless function call timeout-nodejs 2>&1 || true))
echo $(MSG) | egrep Request.timeout.exceeded

get-nodejs-deps:
kubeless function deploy get-nodejs-deps --trigger-http --runtime nodejs6 --handler helloget.handler --from-file nodejs/hellowithdeps.js --dependencies nodejs/package.json
kubeless function deploy get-nodejs-deps --runtime nodejs6 --handler helloget.handler --from-file nodejs/hellowithdeps.js --dependencies nodejs/package.json

get-nodejs-deps-verify:
kubeless function call get-nodejs-deps --data '{"hello": "world"}' | grep -q 'hello.*world.*date.*UTC'

get-nodejs-multi:
cd nodejs; zip helloFunctions.zip *js
kubeless function deploy get-nodejs-multi --trigger-http --runtime nodejs6 --handler index.helloGet --from-file nodejs/helloFunctions.zip
kubeless function deploy get-nodejs-multi --runtime nodejs6 --handler index.helloGet --from-file nodejs/helloFunctions.zip
rm nodejs/helloFunctions.zip

get-nodejs-multi-verify:
kubeless function call get-nodejs-multi |egrep hello.world

get-python-metadata:
kubeless function deploy get-python-metadata --trigger-http --runtime python2.7 --handler helloget.foo --from-file python/helloget.py --env foo:bar,bar=foo,foo --memory 128Mi --label foo:bar,bar=foo,foobar
kubeless function deploy get-python-metadata --runtime python2.7 --handler helloget.foo --from-file python/helloget.py --env foo:bar,bar=foo,foo --memory 128Mi --label foo:bar,bar=foo,foobar

get-python-metadata-verify:
kubeless function call get-python-metadata |egrep hello.world

get-ruby:
kubeless function deploy get-ruby --trigger-http --runtime ruby2.4 --handler helloget.foo --from-file ruby/helloget.rb
kubeless function deploy get-ruby --runtime ruby2.4 --handler helloget.foo --from-file ruby/helloget.rb

get-ruby-verify:
kubeless function call get-ruby |egrep hello.world

get-ruby-deps:
kubeless function deploy get-ruby-deps --trigger-http --runtime ruby2.4 --handler hellowithdeps.foo --from-file ruby/hellowithdeps.rb --dependencies ruby/Gemfile
kubeless function deploy get-ruby-deps --runtime ruby2.4 --handler hellowithdeps.foo --from-file ruby/hellowithdeps.rb --dependencies ruby/Gemfile

get-ruby-deps-verify:
kubeless function call get-ruby-deps |egrep hello.world

get-ruby-custom-port:
kubeless function deploy get-ruby-custom-port --trigger-http --runtime ruby2.4 --handler helloget.foo --from-file ruby/helloget.rb --port 8082
kubeless function deploy get-ruby-custom-port --runtime ruby2.4 --handler helloget.foo --from-file ruby/helloget.rb --port 8082

get-ruby-custom-port-verify:
kubectl get svc get-ruby-custom-port -o yaml | grep 'targetPort: 8082'
kubeless function call get-ruby-custom-port |egrep hello.world

get-php:
kubeless function deploy get-php --trigger-http --runtime php7.2 --handler helloget.foo --from-file php/helloget.php
kubeless function deploy get-php --runtime php7.2 --handler helloget.foo --from-file php/helloget.php

get-php-update:
$(eval TMPDIR := $(shell mktemp -d))
Expand All @@ -157,7 +157,7 @@ get-php-verify:
kubeless function call get-php | egrep "hello world"

get-php-deps:
kubeless function deploy get-php-deps --trigger-http --runtime php7.2 --handler hellowithdeps.foo --from-file php/hellowithdeps.php --dependencies php/composer.json
kubeless function deploy get-php-deps --runtime php7.2 --handler hellowithdeps.foo --from-file php/hellowithdeps.php --dependencies php/composer.json

get-php-deps-verify:
kubeless function call get-php-deps &> /dev/null
Expand All @@ -173,15 +173,15 @@ get-php-deps-update-verify:
kubectl exec -it $(pod) cat /kubeless/composer.json | egrep "1.20"

post-php:
kubeless function deploy post-php --trigger-http --runtime php7.2 --handler hellowithdata.foo --from-file php/hellowithdata.php
kubeless function deploy post-php --runtime php7.2 --handler hellowithdata.foo --from-file php/hellowithdata.php

post-php-verify:
kubeless function call post-php --data '{"it-s": "alive"}'| egrep "it.*alive"

timeout-php:
$(eval TMPDIR := $(shell mktemp -d))
printf '<?php\n function foo() { while(1) {} } \n' > $(TMPDIR)/hello-loop.php
kubeless function deploy timeout-php --trigger-http --runtime php7.2 --handler helloget.foo --from-file $(TMPDIR)/hello-loop.php --timeout 4
kubeless function deploy timeout-php --runtime php7.2 --handler helloget.foo --from-file $(TMPDIR)/hello-loop.php --timeout 4
rm -rf $(TMPDIR)

timeout-php-verify:
Expand All @@ -191,7 +191,7 @@ timeout-php-verify:
timeout-ruby:
$(eval TMPDIR := $(shell mktemp -d))
printf 'def foo(event, context)\n%4swhile true do;sleep(1);end\n%4s"hello world"\nend' > $(TMPDIR)/hello-loop.rb
kubeless function deploy timeout-ruby --trigger-http --runtime ruby2.4 --handler helloget.foo --from-file $(TMPDIR)/hello-loop.rb --timeout 4
kubeless function deploy timeout-ruby --runtime ruby2.4 --handler helloget.foo --from-file $(TMPDIR)/hello-loop.rb --timeout 4
rm -rf $(TMPDIR)

timeout-ruby-verify:
Expand All @@ -200,7 +200,7 @@ timeout-ruby-verify:
echo $(MSG) | egrep "real\s*0m4."

get-dotnetcore:
kubeless function deploy get-dotnetcore --trigger-http --runtime dotnetcore2.0 --handler helloget.foo --from-file dotnetcore/helloget.cs
kubeless function deploy get-dotnetcore --runtime dotnetcore2.0 --handler helloget.foo --from-file dotnetcore/helloget.cs

get-dotnetcore-verify:
kubeless function call get-dotnetcore |egrep hello.world
Expand All @@ -220,7 +220,7 @@ custom-get-python-update-verify:
get: get-python get-nodejs get-python-metadata get-ruby get-ruby-deps get-python-custom-port

post-python:
kubeless function deploy post-python --trigger-http --runtime python2.7 --handler hellowithdata.handler --from-file python/hellowithdata.py
kubeless function deploy post-python --runtime python2.7 --handler hellowithdata.handler --from-file python/hellowithdata.py

post-python-verify:
kubeless function call post-python --data '{"it-s": "alive"}'|egrep "it.*alive"
Expand All @@ -233,14 +233,14 @@ post-python-verify:
echo $$logs | grep -q "event-id.*"

post-python-custom-port:
kubeless function deploy post-python-custom-port --trigger-http --runtime python2.7 --handler hellowithdata.handler --from-file python/hellowithdata.py --port 8081
kubeless function deploy post-python-custom-port --runtime python2.7 --handler hellowithdata.handler --from-file python/hellowithdata.py --port 8081

post-python-custom-port-verify:
kubectl get svc post-python-custom-port -o yaml | grep 'targetPort: 8081'
kubeless function call post-python-custom-port --data '{"it-s": "alive"}'|egrep "it.*alive"

post-nodejs:
kubeless function deploy post-nodejs --trigger-http --runtime nodejs6 --handler hellowithdata.handler --from-file nodejs/hellowithdata.js
kubeless function deploy post-nodejs --runtime nodejs6 --handler hellowithdata.handler --from-file nodejs/hellowithdata.js

post-nodejs-verify:
kubeless function call post-nodejs --data '{"it-s": "alive"}'|egrep "it.*alive"
Expand All @@ -253,7 +253,7 @@ post-nodejs-verify:
echo $$logs | grep -q "event-id.*"

post-ruby:
kubeless function deploy post-ruby --trigger-http --runtime ruby2.4 --handler hellowithdata.handler --from-file ruby/hellowithdata.rb
kubeless function deploy post-ruby --runtime ruby2.4 --handler hellowithdata.handler --from-file ruby/hellowithdata.rb

post-ruby-verify:
kubeless function call post-ruby --data '{"it-s": "alive"}'|egrep "it.*alive"
Expand All @@ -266,7 +266,7 @@ post-ruby-verify:
echo $$logs | grep -q "event-id.*"

post-dotnetcore:
kubeless function deploy post-dotnetcore --runtime dotnetcore2.0 --handler hellowithdata.handler --from-file dotnetcore/hellowithdata.cs --trigger-http
kubeless function deploy post-dotnetcore --runtime dotnetcore2.0 --handler hellowithdata.handler --from-file dotnetcore/hellowithdata.cs

post-dotnetcore-verify:
kubeless function call post-dotnetcore --data '{"it-s": "alive"}'|egrep "it.*alive"
Expand Down
3 changes: 0 additions & 3 deletions tests/integration-tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ load ../script/libtest
test_kubeless_function_update get-python-deps
kubeless_function_delete get-python-deps
}
@test "Test function ingress: get-python" {
test_kubeless_ingress get-python
}
@test "Test function autoscale: get-python" {
if kubectl api-versions | tr '\n' ' ' | grep -q -v "autoscaling/v2beta1"; then
skip "Autoscale is only supported for Kubernetes >= 1.8"
Expand Down

0 comments on commit f5d6534

Please sign in to comment.