From 4525e3d80a5c10031f7963b302e152a0f70c7090 Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 27 Jul 2017 13:12:00 +0700 Subject: [PATCH] fix typo, validateInput --- cmd/kubeless/ingressCreate.go | 33 +++++++++++++-------------------- cmd/kubeless/ingressList.go | 6 +++--- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/cmd/kubeless/ingressCreate.go b/cmd/kubeless/ingressCreate.go index 13a7fb793..78ed92518 100644 --- a/cmd/kubeless/ingressCreate.go +++ b/cmd/kubeless/ingressCreate.go @@ -17,12 +17,11 @@ limitations under the License. package main import ( - "errors" - "github.com/Sirupsen/logrus" "github.com/kubeless/kubeless/pkg/spec" "github.com/kubeless/kubeless/pkg/utils" "github.com/spf13/cobra" + k8sErrors "k8s.io/apimachinery/pkg/api/errors" ) var ingressCreateCmd = &cobra.Command{ @@ -48,10 +47,7 @@ var ingressCreateCmd = &cobra.Command{ logrus.Fatal(err) } - err = validateInput(function, ns) - if err != nil { - logrus.Fatal(err) - } + validateInput(function, ns) client := utils.GetClientOutOfCluster() @@ -62,31 +58,28 @@ var ingressCreateCmd = &cobra.Command{ }, } -func validateInput(function, ns string) error { +func validateInput(function, ns string) { tprClient, err := utils.GetTPRClientOutOfCluster() if err != nil { - return err + logrus.Fatalf("error validate input %v", err) } - funcList := spec.FunctionList{} + f := spec.Function{} err = tprClient.Get(). Resource("functions"). Namespace(ns). + Name(function). Do(). - Into(&funcList) + Into(&f) if err != nil { - return err - } - - for _, f := range funcList.Items { - if f.Metadata.Name == function { - return nil + if k8sErrors.IsNotFound(err) { + logrus.Fatalf("function %s doesn't exist in namespace %s", function, ns) + } else { + logrus.Fatalf("error validate input %v", err) } } - - return errors.New("function doesn't exist") } func init() { - ingressCreateCmd.Flags().StringP("domain", "", "", "Specify runtime") - ingressCreateCmd.Flags().StringP("function", "", "", "Specify handler") + ingressCreateCmd.Flags().StringP("domain", "", "", "Specify a valid domain for the function") + ingressCreateCmd.Flags().StringP("function", "", "", "Name of the function") } diff --git a/cmd/kubeless/ingressList.go b/cmd/kubeless/ingressList.go index 205e0cda2..bdc4e4895 100644 --- a/cmd/kubeless/ingressList.go +++ b/cmd/kubeless/ingressList.go @@ -64,11 +64,11 @@ func doIngressList(w io.Writer, client kubernetes.Interface, ns, output string) return err } - return prinIngress(w, ingList.Items, output) + return printIngress(w, ingList.Items, output) } -// prinIngress formats the output of ingress list -func prinIngress(w io.Writer, ings []v1beta1.Ingress, output string) error { +// printIngress formats the output of ingress list +func printIngress(w io.Writer, ings []v1beta1.Ingress, output string) error { if output == "" { table := tablewriter.NewWriter(w) table.SetHeader([]string{"Name", "namespace", "host", "path", "service name", "service port"})