mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-09 00:16:46 +00:00
Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> Included Test cases for utils Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> Multi namespace handling in invoke Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> List Namespaces capability included Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> remove faasd namespace from list result Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> Create Secret Folder Path Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> Filter only namespaces with openfass label Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> Include Testcase for utility function Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> move default function secets to openfaas-fn namespace secrets Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> Corrected issue with secret moving Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/containerd/containerd"
|
|
faasd "github.com/openfaas/faasd/pkg"
|
|
)
|
|
|
|
const watchdogPort = 8080
|
|
|
|
type InvokeResolver struct {
|
|
client *containerd.Client
|
|
}
|
|
|
|
func NewInvokeResolver(client *containerd.Client) *InvokeResolver {
|
|
return &InvokeResolver{client: client}
|
|
}
|
|
|
|
func (i *InvokeResolver) Resolve(functionName string) (url.URL, error) {
|
|
actualFunctionName := functionName
|
|
log.Printf("Resolve: %q\n", actualFunctionName)
|
|
|
|
namespace := getNamespace(functionName, faasd.FunctionNamespace)
|
|
|
|
if strings.Contains(functionName, ".") {
|
|
actualFunctionName = strings.TrimSuffix(functionName, "."+namespace)
|
|
}
|
|
|
|
function, err := GetFunction(i.client, actualFunctionName, namespace)
|
|
if err != nil {
|
|
return url.URL{}, fmt.Errorf("%s not found", actualFunctionName)
|
|
}
|
|
|
|
serviceIP := function.IP
|
|
|
|
urlStr := fmt.Sprintf("http://%s:%d", serviceIP, watchdogPort)
|
|
|
|
urlRes, err := url.Parse(urlStr)
|
|
if err != nil {
|
|
return url.URL{}, err
|
|
}
|
|
|
|
return *urlRes, nil
|
|
}
|
|
|
|
func getNamespace(name, defaultNamespace string) string {
|
|
namespace := defaultNamespace
|
|
if strings.Contains(name, ".") {
|
|
namespace = name[strings.LastIndexAny(name, ".")+1:]
|
|
}
|
|
return namespace
|
|
}
|