From b6a401e889538bc6b7c16bfed0b1791dc29b7121 Mon Sep 17 00:00:00 2001 From: Dimitar Georgievski Date: Mon, 17 Jun 2024 16:39:21 +0000 Subject: [PATCH] 1. porchctl repo add - add namespace columng when `-A` flag specified 2. porchctl repo reg - use current kubeconfig context namespace if it is not provided. 3. Use kubeconfig context namespace if flag not provided 4. fixed author's email address to comply with EasyCLA --- pkg/cli/commands/repo/get/command.go | 7 +++++++ pkg/cli/commands/repo/reg/command.go | 11 +++++++++++ pkg/cli/commands/repo/unreg/command.go | 10 ++++++++++ 3 files changed, 28 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..69ab4305 100644 --- a/pkg/cli/commands/repo/reg/command.go +++ b/pkg/cli/commands/repo/reg/command.go @@ -88,6 +88,17 @@ type runner struct { func (r *runner) preRunE(_ *cobra.Command, _ []string) error { const op errors.Op = command + ".preRunE" + + // todo if namespace flag missing, use kubeconfig + 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..7a54b8a2 100644 --- a/pkg/cli/commands/repo/unreg/command.go +++ b/pkg/cli/commands/repo/unreg/command.go @@ -71,6 +71,16 @@ 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)