mirror of https://github.com/knative/func.git
chore: tweak output & verbose messages (#173)
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
This commit is contained in:
parent
f4851fb669
commit
551331925a
18
client.go
18
client.go
|
@ -93,6 +93,9 @@ type Describer interface {
|
|||
|
||||
type Description struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Image string `json:"image" yaml:"image"`
|
||||
KService string `json:"kservice" yaml:"kservice"`
|
||||
Namespace string `json:"namespace" yaml:"namespace"`
|
||||
Routes []string `json:"routes" yaml:"routes"`
|
||||
Subscriptions []Subscription `json:"subscriptions" yaml:"subscriptions"`
|
||||
}
|
||||
|
@ -363,7 +366,7 @@ func (c *Client) Initialize(cfg Function) (err error) {
|
|||
// TODO: Create a status structure and return it for clients to use
|
||||
// for output, such as from the CLI.
|
||||
if c.verbose {
|
||||
fmt.Printf("OK %v %v\n", f.Name, f.Root)
|
||||
fmt.Println("Function project created")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -371,6 +374,10 @@ func (c *Client) Initialize(cfg Function) (err error) {
|
|||
// Build the Function at path. Errors if the Function is either unloadable or does
|
||||
// not contain a populated Image.
|
||||
func (c *Client) Build(path string) (err error) {
|
||||
if c.verbose {
|
||||
fmt.Println("Building Function image:")
|
||||
}
|
||||
|
||||
f, err := NewFunction(path)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -394,7 +401,7 @@ func (c *Client) Build(path string) (err error) {
|
|||
// TODO: create a statu structure and return it here for optional
|
||||
// use by the cli for user echo (rather than rely on verbose mode here)
|
||||
if c.verbose {
|
||||
fmt.Printf("OK %v\n", f.Image)
|
||||
fmt.Printf("Function image has been built, image: %v\n", f.Image)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -402,7 +409,6 @@ func (c *Client) Build(path string) (err error) {
|
|||
// Deploy the Function at path. Errors if the Function has not been
|
||||
// initialized with an image tag.
|
||||
func (c *Client) Deploy(path string) (err error) {
|
||||
|
||||
f, err := NewFunction(path)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -414,11 +420,17 @@ func (c *Client) Deploy(path string) (err error) {
|
|||
}
|
||||
|
||||
// Push the image for the named service to the configured registry
|
||||
if c.verbose {
|
||||
fmt.Println("\nPushing Function image to the registry:")
|
||||
}
|
||||
if err = c.pusher.Push(f); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Deploy a new or Update the previously-deployed Function
|
||||
if c.verbose {
|
||||
fmt.Println("\nDeploying Function to cluster:")
|
||||
}
|
||||
return c.deployer.Deploy(f)
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ func runDescribe(cmd *cobra.Command, args []string) (err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
d.Image = function.Image
|
||||
|
||||
write(os.Stdout, description(d), config.Format)
|
||||
return
|
||||
|
@ -109,25 +110,43 @@ func newDescribeConfig(args []string) describeConfig {
|
|||
type description faas.Description
|
||||
|
||||
func (d description) Human(w io.Writer) error {
|
||||
fmt.Fprintln(w, d.Name)
|
||||
fmt.Fprintln(w, "Function name:")
|
||||
fmt.Fprintf(w, " %v\n", d.Name)
|
||||
fmt.Fprintln(w, "Function is built in image:")
|
||||
fmt.Fprintf(w, " %v\n", d.Image)
|
||||
fmt.Fprintln(w, "Function is deployed as Knative Service:")
|
||||
fmt.Fprintf(w, " %v\n", d.KService)
|
||||
fmt.Fprintln(w, "Function is deployed in namespace:")
|
||||
fmt.Fprintf(w, " %v\n", d.Namespace)
|
||||
fmt.Fprintln(w, "Routes:")
|
||||
|
||||
for _, route := range d.Routes {
|
||||
fmt.Fprintf(w, " %v\n", route)
|
||||
}
|
||||
fmt.Fprintln(w, "Subscriptions (Source, Type, Broker):")
|
||||
for _, s := range d.Subscriptions {
|
||||
fmt.Fprintf(w, " %v %v %v\n", s.Source, s.Type, s.Broker)
|
||||
|
||||
if len(d.Subscriptions) > 0 {
|
||||
fmt.Fprintln(w, "Subscriptions (Source, Type, Broker):")
|
||||
for _, s := range d.Subscriptions {
|
||||
fmt.Fprintf(w, " %v %v %v\n", s.Source, s.Type, s.Broker)
|
||||
}
|
||||
}
|
||||
return d.Plain(w)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d description) Plain(w io.Writer) error {
|
||||
fmt.Fprintf(w, "NAME %v\n", d.Name)
|
||||
fmt.Fprintf(w, "Name %v\n", d.Name)
|
||||
fmt.Fprintf(w, "Image %v\n", d.Image)
|
||||
fmt.Fprintf(w, "Knative Service %v\n", d.KService)
|
||||
fmt.Fprintf(w, "Namespace %v\n", d.Namespace)
|
||||
|
||||
for _, route := range d.Routes {
|
||||
fmt.Fprintf(w, "ROUTE %v\n", route)
|
||||
fmt.Fprintf(w, "Route %v\n", route)
|
||||
}
|
||||
for _, s := range d.Subscriptions {
|
||||
fmt.Fprintf(w, "SUBSCRIPTION %v %v %v\n", s.Source, s.Type, s.Broker)
|
||||
|
||||
if len(d.Subscriptions) > 0 {
|
||||
for _, s := range d.Subscriptions {
|
||||
fmt.Fprintf(w, "Subscription %v %v %v\n", s.Source, s.Type, s.Broker)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -54,12 +54,18 @@ func (d *Deployer) Deploy(f faas.Function) (err error) {
|
|||
if errors.IsNotFound(err) {
|
||||
|
||||
// Let's create a new Service
|
||||
if d.Verbose {
|
||||
fmt.Printf("Creating Knative Service: %v\n", serviceName)
|
||||
}
|
||||
err := client.CreateService(generateNewService(serviceName, f.Image))
|
||||
if err != nil {
|
||||
err = fmt.Errorf("knative deployer failed to deploy the service: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if d.Verbose {
|
||||
fmt.Println("Waiting for Knative Service to become ready")
|
||||
}
|
||||
err, _ = client.WaitForService(serviceName, DefaultWaitingTimeout, wait.NoopMessageCallback())
|
||||
if err != nil {
|
||||
err = fmt.Errorf("knative deployer failed to wait for the service to become ready: %v", err)
|
||||
|
@ -72,7 +78,7 @@ func (d *Deployer) Deploy(f faas.Function) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Println("Function deployed on: " + route.Status.URL.String())
|
||||
fmt.Println("Function deployed at URL: " + route.Status.URL.String())
|
||||
|
||||
} else {
|
||||
err = fmt.Errorf("knative deployer failed to get the service: %v", err)
|
||||
|
@ -80,6 +86,9 @@ func (d *Deployer) Deploy(f faas.Function) (err error) {
|
|||
}
|
||||
} else {
|
||||
// Update the existing Service
|
||||
if d.Verbose {
|
||||
fmt.Printf("Updating existing Knative Service: %v\n", serviceName)
|
||||
}
|
||||
err = client.UpdateServiceWithRetry(serviceName, updateEnvVars(f.EnvVars), 3)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("knative deployer failed to update the service: %v", err)
|
||||
|
|
|
@ -87,6 +87,8 @@ func (d *Describer) Describe(name string) (description faas.Description, err err
|
|||
}
|
||||
}
|
||||
|
||||
description.KService = serviceName
|
||||
description.Namespace = d.namespace
|
||||
description.Routes = routeURLs
|
||||
description.Subscriptions = subscriptions
|
||||
description.Name, err = k8s.FromK8sAllowedName(service.Name)
|
||||
|
|
|
@ -35,6 +35,9 @@ func (remover *Remover) Remove(name string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
if remover.Verbose {
|
||||
fmt.Printf("Removing Knative Service: %v\n", serviceName)
|
||||
}
|
||||
err = client.DeleteService(serviceName, time.Second*60)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("knative remover failed to delete the service: %v", err)
|
||||
|
|
Loading…
Reference in New Issue