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 Mar 14, 2019
1 parent f8870a5 commit 87f9279
Show file tree
Hide file tree
Showing 14 changed files with 817 additions and 463 deletions.
65 changes: 42 additions & 23 deletions cmd/svcat/class/describe_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@ 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 {
*command.Context
lookupByKubeName bool
kubeName string
name string
// DescribeCmd contains the information needed to describe a specific class
type DescribeCmd struct {
*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{
Namespaced: command.NewNamespaced(cxt),
Scoped: command.NewScoped(),
}
cmd := &cobra.Command{
Use: "class NAME",
Aliases: []string{"classes", "cl"},
Expand All @@ -47,44 +54,56 @@ 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.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 87f9279

Please sign in to comment.