Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
svcat describe and get classes now support namespaced resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkhahn committed Apr 16, 2019
1 parent 63df33c commit bdf851d
Show file tree
Hide file tree
Showing 14 changed files with 2,676 additions and 2,823 deletions.
66 changes: 44 additions & 22 deletions cmd/svcat/class/describe_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,32 @@ package class

import (
"fmt"
"strings"

"github.com/kubernetes-incubator/service-catalog/cmd/svcat/command"
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/output"
servicecatalog "github.com/kubernetes-incubator/service-catalog/pkg/svcat/service-catalog"
"github.com/spf13/cobra"
)

type describeCmd struct {
// DescribeCmd contains the information needed to describe a specific class
type DescribeCmd struct {
*command.Context
lookupByKubeName bool
kubeName string
name string
*command.Namespaced
*command.Scoped

LookupByKubeName bool
KubeName string
Name string
}

// NewDescribeCmd builds a "svcat describe class" command
func NewDescribeCmd(cxt *command.Context) *cobra.Command {
describeCmd := &describeCmd{Context: cxt}
describeCmd := &DescribeCmd{
Context: cxt,
Namespaced: command.NewNamespaced(cxt),
Scoped: command.NewScoped(),
}
cmd := &cobra.Command{
Use: "class NAME",
Aliases: []string{"classes", "cl"},
Expand All @@ -47,44 +56,57 @@ func NewDescribeCmd(cxt *command.Context) *cobra.Command {
RunE: command.RunE(describeCmd),
}
cmd.Flags().BoolVarP(
&describeCmd.lookupByKubeName,
&describeCmd.LookupByKubeName,
"kube-name",
"k",
false,
"Whether or not to get the class by its Kubernetes Name (the default is by external name)",
"Whether or not to get the class by its Kubernetes name (the default is by external name)",
)
describeCmd.AddNamespaceFlags(cmd.Flags(), true)
describeCmd.AddScopedFlags(cmd.Flags(), true)

return cmd
}

func (c *describeCmd) Validate(args []string) error {
// Validate checks that the required arguments have been provided
func (c *DescribeCmd) Validate(args []string) error {
if len(args) == 0 {
return fmt.Errorf("a class name or Kubernetes name is required")
return fmt.Errorf("a class external name or Kubernetes name is required")
}

if c.lookupByKubeName {
c.kubeName = args[0]
if c.LookupByKubeName {
c.KubeName = args[0]
} else {
c.name = args[0]
c.Name = args[0]
}

return nil
}

func (c *describeCmd) Run() error {
return c.describe()
}

func (c *describeCmd) describe() error {
// Run determines if we're getting a class by k8s name or
// external name, gets the details of the class, and prints
// the output to the user
func (c *DescribeCmd) Run() error {
var class servicecatalog.Class
var err error
if c.lookupByKubeName {
class, err = c.App.RetrieveClassByID(c.kubeName)
if c.Namespace == "" {
c.Namespace = c.App.CurrentNamespace
}
scopeOpts := servicecatalog.ScopeOptions{
Scope: c.Scope,
Namespace: c.Namespace,
}

if c.LookupByKubeName {
class, err = c.App.RetrieveClassByID(c.KubeName, scopeOpts)
} else {
class, err = c.App.RetrieveClassByName(c.name, servicecatalog.ScopeOptions{
Scope: servicecatalog.ClusterScope,
})
class, err = c.App.RetrieveClassByName(c.Name, scopeOpts)
}
if err != nil {
if strings.Contains(err.Error(), servicecatalog.MultipleClassesFoundError) {
return fmt.Errorf(err.Error() + ", please specify a scope with --scope or an exact Kubernetes name with --kube-name")
}

return err
}

Expand Down
Loading

0 comments on commit bdf851d

Please sign in to comment.