openfaas / faas

OpenFaaS - Serverless Functions Made Simple
https://www.openfaas.com
MIT License
25.02k stars 1.93k forks source link

Invoke function in the UI is not working when direct_function is set to false #1565

Closed phgache closed 4 years ago

phgache commented 4 years ago

My actions before raising this issue

Expected Behaviour

The "invoke" button should call the function and the UI shoud show the function return.

Current Behaviour

image

As you can the see the call is failing because when the operator try to lookup for the function service, the name used is concatenated with the namespace. This is working with direct_function set to true because in this case the operator is not involved.

Given that, imho there is two options :

  1. Removing the namespace when the UI is calling the function because it is working in both mode (direct_function)
  2. Make the gateway and operator being able to work with the namespace added to the function name.

I have seen new feature about using multiple namespaces so the option 2 is maybe the best one as it will probably have less impacts.

Possible Solution

I’m not 100% sure that this is the best option, but as OpenFaaS does not support multiple namespace when direct_function is set to false, removing it in the « trimURLTransformer » could be an option :

main.go

    nilURLTransformer := handlers.TransparentURLPathTransformer{}
    trimURLTransformer := handlers.FunctionPrefixTrimmingURLPathTransformer{}

    if config.DirectFunctions {
        functionURLResolver = handlers.FunctionAsHostBaseURLResolver{
            FunctionSuffix:    config.DirectFunctionsSuffix,
            FunctionNamespace: config.Namespace,
        }
        functionURLTransformer = trimURLTransformer
    } else {
        functionURLResolver = urlResolver
        functionURLTransformer = nilURLTransformer
    }

forwarding_proxy.go

// Transform returns the URL path unchanged.
func (f TransparentURLPathTransformer) Transform(r *http.Request) string {
    return r.URL.Path // remove the namespace at the end
}

Steps to Reproduce (for bugs)

  1. Deploy the openfaas with direct_functions set to false
  2. Deploy nodeinfo function sample
  3. Hit the invoke button

Context

This issue seems to only occurs in the UI which is has a minimal impact on our project. I raise this issue also to be sure that there is no further impact that I was not able to see.

Your Environment

If using Swarm, run the following and include the output:

curl -sLS https://raw.githubusercontent.com/moby/moby/master/contrib/check-config.sh | bash

Next steps

You may join Slack for community support.

LucasRoesler commented 4 years ago

We are getting really close with multiple namespace support in the operator, i would rather fix this bug in the operator instead of hacking the gateway here. I will definitely take a look this weekend

LucasRoesler commented 4 years ago

@phgache I have created a potential fix in faas-netes, if you checkout https://github.com/openfaas/faas-netes/pull/683 you can see the testing instructions and if you are feeling adventurous, give it a try and help us verify the fix

alexellis commented 4 years ago

Fixed in: https://github.com/openfaas/faas-netes/releases/tag/0.12.3

@phgache please could you try it out?

phgache commented 4 years ago

Hi,

I have deployed the new version and the bug is fixed.

Thanks @LucasRoesler & @alexellis