Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollouts: add namespace flag to CLI commands #3890

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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