From 0f4dcc1b33f77f3f15f5dfd37d354a9a4f97e99e Mon Sep 17 00:00:00 2001 From: Dimitar Georgievski Date: Tue, 25 Jun 2024 17:58:33 +0000 Subject: [PATCH] Command fixes: - repo get: Output namespace column when -A/--all flag specified. - repo reg: Use kubeconfig context namespace if -n/--namespace flag not provided. - repo unreg: Use kubeconfig context namespace if -n/--namespace flag not provided. --- pkg/cli/commands/repo/get/command.go | 7 +++++++ pkg/cli/commands/repo/reg/command.go | 9 +++++++++ pkg/cli/commands/repo/unreg/command.go | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/pkg/cli/commands/repo/get/command.go b/pkg/cli/commands/repo/get/command.go index d72aeabe..70c23450 100644 --- a/pkg/cli/commands/repo/get/command.go +++ b/pkg/cli/commands/repo/get/command.go @@ -79,6 +79,13 @@ func (r *runner) preRunE(cmd *cobra.Command, _ []string) error { } else { r.requestTable = true } + + allNamespacesFlag := cmd.Flags().Lookup("all-namespaces").Value.String() + if strings.Contains(allNamespacesFlag, "true") { + r.printFlags.HumanReadableFlags.WithNamespace = true + } else { + r.printFlags.HumanReadableFlags.WithNamespace = false + } return nil } diff --git a/pkg/cli/commands/repo/reg/command.go b/pkg/cli/commands/repo/reg/command.go index 7121e205..79e5220a 100644 --- a/pkg/cli/commands/repo/reg/command.go +++ b/pkg/cli/commands/repo/reg/command.go @@ -88,6 +88,15 @@ type runner struct { func (r *runner) preRunE(_ *cobra.Command, _ []string) error { const op errors.Op = command + ".preRunE" + if *r.cfg.Namespace == "" { + // Get the namespace from kubeconfig + namespace, _, err := r.cfg.ToRawKubeConfigLoader().Namespace() + if err != nil { + return fmt.Errorf("error getting namespace: %w", err) + } + r.cfg.Namespace = &namespace + } + client, err := porch.CreateClientWithFlags(r.cfg) if err != nil { return errors.E(op, err) diff --git a/pkg/cli/commands/repo/unreg/command.go b/pkg/cli/commands/repo/unreg/command.go index a853248a..f94fcc44 100644 --- a/pkg/cli/commands/repo/unreg/command.go +++ b/pkg/cli/commands/repo/unreg/command.go @@ -71,6 +71,15 @@ type runner struct { func (r *runner) preRunE(_ *cobra.Command, _ []string) error { const op errors.Op = command + ".preRunE" + if *r.cfg.Namespace == "" { + // Get the namespace from kubeconfig + namespace, _, err := r.cfg.ToRawKubeConfigLoader().Namespace() + if err != nil { + return fmt.Errorf("error getting namespace: %w", err) + } + r.cfg.Namespace = &namespace + } + client, err := porch.CreateClientWithFlags(r.cfg) if err != nil { return errors.E(op, err)