Enable prefix based routing (#2047)

* Enable prefix based routing

Signed-off-by: Harsh Thakur <harshthakur9030@gmail.com>

* Optimize checking condition

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Disable few tests

* disable router modification for now

* run code generator

* Collect fission dump in CI

* Enable all tests back

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Remove unwanted code

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Add prefix support at more places and couple of todo's

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Few more changes

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Improve function trim support

* Support for prefix based urls in fission function test

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* multi route for fission function test

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Improve validations in trigger creations

* Adjust leading / in url from fission

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

* Change suburl to subpath for function test

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>

Co-authored-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Harsh Thakur
2021-06-10 13:54:49 +05:30
committed by GitHub
co-authored by Sanket Sudake
parent f01de5c802
commit aa45703a99
20 changed files with 149 additions and 44 deletions
+2 -1
View File
@@ -43,7 +43,7 @@ func Commands() *cobra.Command {
flag.PkgSrcChecksum, flag.PkgDeployChecksum, flag.PkgInsecure,
flag.FnBuildCmd,
flag.HtUrl, flag.HtMethod,
flag.HtUrl, flag.HtPrefix, flag.HtMethod,
// flag for newdeploy to use.
flag.RunTimeMinCPU, flag.RunTimeMaxCPU, flag.RunTimeMinMemory,
@@ -150,6 +150,7 @@ func Commands() *cobra.Command {
// for getting log from log database if
// we failed to get logs from function pod.
flag.FnLogDBType,
flag.FnSubPath,
},
})
+5 -5
View File
@@ -18,7 +18,6 @@ package function
import (
"fmt"
"strings"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
@@ -339,13 +338,13 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
// Allow the user to specify an HTTP trigger while creating a function.
triggerUrl := input.String(flagkey.HtUrl)
if len(triggerUrl) == 0 {
prefix := input.String(flagkey.HtPrefix)
if len(triggerUrl) == 0 && len(prefix) == 0 {
return nil
}
if !strings.HasPrefix(triggerUrl, "/") {
triggerUrl = fmt.Sprintf("/%s", triggerUrl)
if len(prefix) != 0 && len(triggerUrl) > 0 {
console.Warn("Prefix will take precedence over URL/RelativeURL")
}
method, err := httptrigger.GetMethod(input.String(flagkey.HtMethod))
if err != nil {
return errors.Wrap(err, "error getting HTTP trigger method")
@@ -359,6 +358,7 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
},
Spec: fv1.HTTPTriggerSpec{
RelativeURL: triggerUrl,
Prefix: &prefix,
Method: method,
FunctionReference: fv1.FunctionReference{
Type: fv1.FunctionReferenceTypeFunctionName,
+9 -7
View File
@@ -18,7 +18,6 @@ package function
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/url"
@@ -62,14 +61,17 @@ func (opts *TestSubCommand) do(input cli.Input) error {
if err != nil {
return err
}
routerURL = "127.0.0.1:" + localRouterPort
fnUri := m.Name
if m.Namespace != metav1.NamespaceDefault {
fnUri = fmt.Sprintf("%v/%v", m.Namespace, m.Name)
fnURL := "http://127.0.0.1:" + localRouterPort + util.UrlForFunction(m.Name, m.Namespace)
if input.IsSet(flagkey.FnSubPath) {
subPath := input.String(flagkey.FnSubPath)
if !strings.HasPrefix(subPath, "/") {
fnURL = fnURL + "/" + subPath
} else {
fnURL = fnURL + subPath
}
}
functionUrl, err := url.Parse(fmt.Sprintf("http://%s/fission-function/%s", routerURL, fnUri))
functionUrl, err := url.Parse(fnURL)
if err != nil {
return err
}