Skip to content

Commit

Permalink
Fix namespace handling for plan command (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz authored and kensipe committed Oct 10, 2019
1 parent 2c15fe3 commit 1ce4224
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/kudoctl/cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewPlanStatusCmd() *cobra.Command {
Short: "Shows the status of all plans to an particular instance.",
Example: planStatuExample,
RunE: func(cmd *cobra.Command, args []string) error {
return plan.RunStatus(cmd, args, options, &Settings)
return plan.RunStatus(cmd, options, &Settings)
},
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/kudoctl/cmd/plan/plan_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (

// Options are the configurable options for plans
type Options struct {
Instance string
Namespace string
Instance string
}

var (
Expand All @@ -37,12 +36,14 @@ func RunHistory(cmd *cobra.Command, options *Options, settings *env.Settings) er
}

func planHistory(options *Options, settings *env.Settings) error {
namespace := settings.Namespace

kc, err := kudo.NewClient(settings.Namespace, settings.KubeConfig)
if err != nil {
fmt.Printf("Unable to create kudo client to talk to kubernetes API server %w", err)
return err
}
instance, err := kc.GetInstance(options.Instance, options.Namespace)
instance, err := kc.GetInstance(options.Instance, namespace)
if errors.IsNotFound(err) {
fmt.Printf("Instance %s/%s does not exist", instance.Namespace, instance.Name)
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/kudoctl/cmd/plan/plan_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var DefaultStatusOptions = &Options{}

// RunStatus runs the plan status command
func RunStatus(cmd *cobra.Command, args []string, options *Options, settings *env.Settings) error {
func RunStatus(cmd *cobra.Command, options *Options, settings *env.Settings) error {

instanceFlag, err := cmd.Flags().GetString("instance")
if err != nil || instanceFlag == "" {
Expand All @@ -34,6 +34,7 @@ func RunStatus(cmd *cobra.Command, args []string, options *Options, settings *en
}

func planStatus(options *Options, settings *env.Settings) error {
namespace := settings.Namespace

tree := treeprint.New()

Expand All @@ -54,7 +55,7 @@ func planStatus(options *Options, settings *env.Settings) error {
Resource: "instances",
}

instObj, err := dynamicClient.Resource(instancesGVR).Namespace(options.Namespace).Get(options.Instance, metav1.GetOptions{})
instObj, err := dynamicClient.Resource(instancesGVR).Namespace(namespace).Get(options.Instance, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -80,7 +81,7 @@ func planStatus(options *Options, settings *env.Settings) error {
}

// List all of the Virtual Services.
operatorObj, err := dynamicClient.Resource(operatorGVR).Namespace(options.Namespace).Get(operatorVersionNameOfInstance, metav1.GetOptions{})
operatorObj, err := dynamicClient.Resource(operatorGVR).Namespace(namespace).Get(operatorVersionNameOfInstance, metav1.GetOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -137,7 +138,7 @@ func planStatus(options *Options, settings *env.Settings) error {
}
}

fmt.Printf("Plan(s) for \"%s\" in namespace \"%s\":\n", instance.Name, options.Namespace)
fmt.Printf("Plan(s) for \"%s\" in namespace \"%s\":\n", instance.Name, namespace)
fmt.Println(tree.String())

return nil
Expand Down

0 comments on commit 1ce4224

Please sign in to comment.