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
+4 -4
View File
@@ -30,10 +30,10 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Create),
}
wrapper.SetFlags(createCmd, flag.FlagSet{
Required: []flag.Flag{flag.HtUrl, flag.HtFnName},
Optional: []flag.Flag{flag.HtName, flag.HtMethod, flag.HtIngress,
Required: []flag.Flag{flag.HtFnName},
Optional: []flag.Flag{flag.HtUrl, flag.HtName, flag.HtMethod, flag.HtIngress,
flag.HtIngressRule, flag.HtIngressAnnotation, flag.HtIngressTLS,
flag.HtFnWeight, flag.HtHost, flag.NamespaceFunction, flag.SpecSave, flag.SpecDry},
flag.HtFnWeight, flag.HtHost, flag.NamespaceFunction, flag.SpecSave, flag.SpecDry, flag.HtPrefix},
})
getCmd := &cobra.Command{
@@ -56,7 +56,7 @@ func Commands() *cobra.Command {
Required: []flag.Flag{flag.HtName},
Optional: []flag.Flag{flag.HtUrl, flag.HtFnName,
flag.HtMethod, flag.HtIngress, flag.HtIngressRule, flag.HtIngressAnnotation,
flag.HtIngressTLS, flag.HtFnWeight, flag.HtHost, flag.NamespaceTrigger},
flag.HtIngressTLS, flag.HtFnWeight, flag.HtHost, flag.NamespaceTrigger, flag.HtPrefix},
})
deleteCmd := &cobra.Command{
+20 -3
View File
@@ -19,6 +19,7 @@ package httptrigger
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/pkg/errors"
@@ -87,10 +88,25 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
}
triggerUrl := input.String(flagkey.HtUrl)
if triggerUrl == "/" {
prefix := input.String(flagkey.HtPrefix)
if triggerUrl == "" && prefix == "" {
console.Error("You need to supply either Prefix or URL/RelativeURL")
os.Exit(1)
}
if triggerUrl != "" && prefix != "" {
console.Warn("Prefix will take precedence over URL/RelativeURL")
}
if triggerUrl == "/" || prefix == "/" {
return errors.New("url with only root path is not allowed")
} else if !strings.HasPrefix(triggerUrl, "/") {
triggerUrl = fmt.Sprintf("/%s", triggerUrl)
}
if triggerUrl != "" && !strings.HasPrefix(triggerUrl, "/") {
triggerUrl = "/" + triggerUrl
}
if prefix != "" && !strings.HasPrefix(prefix, "/") {
prefix = "/" + prefix
}
method, err := GetMethod(input.String(flagkey.HtMethod))
@@ -149,6 +165,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
FunctionReference: *functionRef,
CreateIngress: createIngress,
IngressConfig: *ingressConfig,
Prefix: &prefix,
},
}
+26 -3
View File
@@ -18,6 +18,7 @@ package httptrigger
import (
"fmt"
"strings"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -59,10 +60,26 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
return errors.Wrap(err, "error getting HTTP trigger")
}
if input.IsSet(flagkey.HtUrl) {
ht.Spec.RelativeURL = input.String(flagkey.HtUrl)
triggerUrl := input.String(flagkey.HtUrl)
prefix := input.String(flagkey.HtPrefix)
if triggerUrl != "" && prefix != "" {
console.Warn("Prefix will take precedence over URL/RelativeURL")
}
if triggerUrl == "/" || prefix == "/" {
return errors.New("url with only root path is not allowed")
}
if triggerUrl != "" && !strings.HasPrefix(triggerUrl, "/") {
triggerUrl = "/" + triggerUrl
}
if prefix != "" && !strings.HasPrefix(prefix, "/") {
prefix = "/" + prefix
}
ht.Spec.RelativeURL = triggerUrl
ht.Spec.Prefix = &prefix
if input.IsSet(flagkey.HtMethod) {
ht.Spec.Method = input.String(flagkey.HtMethod)
}
@@ -98,9 +115,15 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
}
if input.IsSet(flagkey.HtIngressRule) || input.IsSet(flagkey.HtIngressAnnotation) || input.IsSet(flagkey.HtIngressTLS) {
fallbackURL := ""
if ht.Spec.Prefix != nil && *ht.Spec.Prefix != "" {
fallbackURL = *ht.Spec.Prefix
} else {
fallbackURL = ht.Spec.RelativeURL
}
ingress, err := GetIngressConfig(
input.StringSlice(flagkey.HtIngressAnnotation), input.String(flagkey.HtIngressRule),
input.String(flagkey.HtIngressTLS), ht.Spec.RelativeURL, &ht.Spec.IngressConfig)
input.String(flagkey.HtIngressTLS), fallbackURL, &ht.Spec.IngressConfig)
if err != nil {
return errors.Wrap(err, "error parsing ingress configuration")
}