Skip to content

Commit

Permalink
Merge pull request #2148 from carlory/fix-karmadactl-get
Browse files Browse the repository at this point in the history
allow to read namespace from the context field of karmada config when use the karmadactl get command
  • Loading branch information
karmada-bot authored Jul 11, 2022
2 parents d2bd9d9 + 796383d commit a50e31d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/karmadactl/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewCmdGet(karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command
SilenceUsage: true,
Example: getExample(parentCommand),
RunE: func(cmd *cobra.Command, args []string) error {
if err := o.Complete(); err != nil {
if err := o.Complete(karmadaConfig); err != nil {
return err
}
if err := o.Validate(cmd); err != nil {
Expand All @@ -87,7 +87,7 @@ func NewCmdGet(karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command
o.GlobalCommandOptions.AddFlags(cmd.Flags())
o.PrintFlags.AddFlags(cmd)

cmd.Flags().StringVarP(&o.Namespace, "namespace", "n", "default", "-n=namespace or -n namespace")
cmd.Flags().StringVarP(&o.Namespace, "namespace", "n", o.Namespace, "-n=namespace or -n namespace")
cmd.Flags().StringVarP(&o.LabelSelector, "labels", "l", "", "-l=label or -l label")
cmd.Flags().StringSliceVarP(&o.Clusters, "clusters", "C", []string{}, "-C=member1,member2")
cmd.Flags().StringVar(&o.ClusterNamespace, "cluster-namespace", options.DefaultKarmadaClusterNamespace, "Namespace in the control plane where member cluster secrets are stored.")
Expand Down Expand Up @@ -152,9 +152,17 @@ func NewCommandGetOptions(parent string, streams genericclioptions.IOStreams) *C
}

// Complete takes the command arguments and infers any remaining options.
func (g *CommandGetOptions) Complete() error {
func (g *CommandGetOptions) Complete(karmadaConfig KarmadaConfig) error {
newScheme := gclient.NewSchema()

if g.Namespace == "" {
namespace, _, err := karmadaConfig.GetClientConfig(g.KarmadaContext, g.KubeConfig).Namespace()
if err != nil {
return err
}
g.Namespace = namespace
}

templateArg := ""
if g.PrintFlags.TemplateFlags != nil && g.PrintFlags.TemplateFlags.TemplateArgument != nil {
templateArg = *g.PrintFlags.TemplateFlags.TemplateArgument
Expand Down

0 comments on commit a50e31d

Please sign in to comment.