Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
fix typo, validateInput
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtuna committed Jul 31, 2017
1 parent 3098164 commit 4525e3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
33 changes: 13 additions & 20 deletions cmd/kubeless/ingressCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()

Expand All @@ -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")
}
6 changes: 3 additions & 3 deletions cmd/kubeless/ingressList.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down

0 comments on commit 4525e3d

Please sign in to comment.