From afd7f7f436c304ff84a351b468bdaafc35a97d16 Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Fri, 9 Mar 2018 02:45:30 +0800 Subject: [PATCH] Show warning when trying to create a route with non-existent function (#539) --- fission/httptrigger.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fission/httptrigger.go b/fission/httptrigger.go index ec155630..21771aa0 100644 --- a/fission/httptrigger.go +++ b/fission/httptrigger.go @@ -28,6 +28,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/fission/fission" + "github.com/fission/fission/controller/client" "github.com/fission/fission/crd" ) @@ -57,6 +58,17 @@ func getMethod(method string) string { return "" } +func checkFunctionExistence(fissionClient *client.Client, fnName string) { + meta := &metav1.ObjectMeta{ + Name: fnName, + Namespace: metav1.NamespaceDefault, + } + _, err := fissionClient.FunctionGet(meta) + if err != nil { + fmt.Printf("function '%v' does not exist, use 'fission function create --name %v ...' to create the function\n", fnName, fnName) + } +} + func htCreate(c *cli.Context) error { client := getClient(c.GlobalString("server")) @@ -73,6 +85,8 @@ func htCreate(c *cli.Context) error { method = "GET" } + checkFunctionExistence(client, fnName) + // just name triggers by uuid. triggerName := uuid.NewV4().String() @@ -115,6 +129,8 @@ func htUpdate(c *cli.Context) error { fatal("Nothing to update. Use --function to specify a new function.") } + checkFunctionExistence(client, newFn) + ht, err := client.HTTPTriggerGet(&metav1.ObjectMeta{ Name: htName, Namespace: metav1.NamespaceDefault,