Skip to content

Commit

Permalink
rollouts: add namespace flag to CLI commands (#3890)
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Mar 21, 2023
1 parent 0a89c06 commit fd920eb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion commands/alpha/alphacmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func GetCommand(ctx context.Context, name, version string) *cobra.Command {
wasm.NewCommand(ctx, version),
live.GetCommand(ctx, "", version),
license.NewCommand(ctx, version),
rollouts.NewCommand(ctx),
rollouts.NewCommand(ctx, version),
)

return alpha
Expand Down
19 changes: 12 additions & 7 deletions commands/alpha/rollouts/advance/advance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/rolloutsclient"
"github.com/GoogleContainerTools/kpt/rollouts/api/v1alpha1"
"github.com/spf13/cobra"
k8scmdutil "k8s.io/kubectl/pkg/cmd/util"
)

func newRunner(ctx context.Context) *runner {
func newRunner(ctx context.Context, f k8scmdutil.Factory) *runner {
r := &runner{
ctx: ctx,
ctx: ctx,
factory: f,
}
c := &cobra.Command{
Use: "advance rollout-name wave-name",
Expand All @@ -38,13 +40,14 @@ func newRunner(ctx context.Context) *runner {
return r
}

func NewCommand(ctx context.Context) *cobra.Command {
return newRunner(ctx).Command
func NewCommand(ctx context.Context, f k8scmdutil.Factory) *cobra.Command {
return newRunner(ctx, f).Command
}

type runner struct {
ctx context.Context
Command *cobra.Command
factory k8scmdutil.Factory
}

func (r *runner) runE(cmd *cobra.Command, args []string) error {
Expand All @@ -65,9 +68,11 @@ func (r *runner) runE(cmd *cobra.Command, args []string) error {
rolloutName := args[0]
waveName := args[1]

// TODO(droot): plumb the namespace value from commandline flags
ns := "default"
rollout, err := rlc.Get(r.ctx, ns, rolloutName)
namespace, _, err := r.factory.ToRawKubeConfigLoader().Namespace()
if err != nil {
return err
}
rollout, err := rlc.Get(r.ctx, namespace, rolloutName)
if err != nil {
fmt.Printf("%s\n", err)
return err
Expand Down
17 changes: 12 additions & 5 deletions commands/alpha/rollouts/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ import (
rolloutsapi "github.com/GoogleContainerTools/kpt/rollouts/api/v1alpha1"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
k8scmdutil "k8s.io/kubectl/pkg/cmd/util"
)

func NewCommand(ctx context.Context) *cobra.Command {
return newRunner(ctx).Command
func NewCommand(ctx context.Context, f k8scmdutil.Factory) *cobra.Command {
return newRunner(ctx, f).Command
}

func newRunner(ctx context.Context) *runner {
func newRunner(ctx context.Context, f k8scmdutil.Factory) *runner {
r := &runner{
ctx: ctx,
ctx: ctx,
factory: f,
}
c := &cobra.Command{
Use: "get",
Expand All @@ -46,6 +48,7 @@ func newRunner(ctx context.Context) *runner {
type runner struct {
ctx context.Context
Command *cobra.Command
factory k8scmdutil.Factory
}

func (r *runner) runE(cmd *cobra.Command, args []string) error {
Expand All @@ -55,7 +58,11 @@ func (r *runner) runE(cmd *cobra.Command, args []string) error {
return err
}

rollouts, err := rlc.List(r.ctx, "")
namespace, _, err := r.factory.ToRawKubeConfigLoader().Namespace()
if err != nil {
return err
}
rollouts, err := rlc.List(r.ctx, namespace)
if err != nil {
fmt.Printf("%s\n", err)
return err
Expand Down
11 changes: 7 additions & 4 deletions commands/alpha/rollouts/rolloutscmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/advance"
"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/get"
"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/status"
"github.com/GoogleContainerTools/kpt/commands/util"
"github.com/spf13/cobra"
)

func NewCommand(ctx context.Context) *cobra.Command {
func NewCommand(ctx context.Context, version string) *cobra.Command {
rolloutsCmd := &cobra.Command{
Use: "rollouts",
Short: "rollouts",
Expand All @@ -40,10 +41,12 @@ func NewCommand(ctx context.Context) *cobra.Command {
},
}

f := util.NewFactory(rolloutsCmd, version)

rolloutsCmd.AddCommand(
advance.NewCommand(ctx),
get.NewCommand(ctx),
status.NewCommand(ctx),
advance.NewCommand(ctx, f),
get.NewCommand(ctx, f),
status.NewCommand(ctx, f),
)
return rolloutsCmd
}
21 changes: 14 additions & 7 deletions commands/alpha/rollouts/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import (
"github.com/GoogleContainerTools/kpt/commands/alpha/rollouts/rolloutsclient"
rolloutsapi "github.com/GoogleContainerTools/kpt/rollouts/api/v1alpha1"
"github.com/spf13/cobra"
k8scmdutil "k8s.io/kubectl/pkg/cmd/util"

"github.com/jedib0t/go-pretty/v6/table"
)

func newRunner(ctx context.Context) *runner {
func newRunner(ctx context.Context, f k8scmdutil.Factory) *runner {
r := &runner{
ctx: ctx,
ctx: ctx,
factory: f,
}
c := &cobra.Command{
Use: "status",
Expand All @@ -40,13 +42,14 @@ func newRunner(ctx context.Context) *runner {
return r
}

func NewCommand(ctx context.Context) *cobra.Command {
return newRunner(ctx).Command
func NewCommand(ctx context.Context, f k8scmdutil.Factory) *cobra.Command {
return newRunner(ctx, f).Command
}

type runner struct {
ctx context.Context
Command *cobra.Command
factory k8scmdutil.Factory
}

func (r *runner) runE(cmd *cobra.Command, args []string) error {
Expand All @@ -60,9 +63,13 @@ func (r *runner) runE(cmd *cobra.Command, args []string) error {
fmt.Printf("must provide rollout name")
return nil
}
// TODO(droot): plumb the namespace value from the commandline args
ns := "default"
rollout, err := rlc.Get(r.ctx, ns, args[0])

namespace, _, err := r.factory.ToRawKubeConfigLoader().Namespace()
if err != nil {
return err
}

rollout, err := rlc.Get(r.ctx, namespace, args[0])
if err != nil {
fmt.Printf("%s\n", err)
return err
Expand Down

0 comments on commit fd920eb

Please sign in to comment.