Skip to content

Commit

Permalink
Use namespace flag for namespace selection
Browse files Browse the repository at this point in the history
  • Loading branch information
akrzos committed Jan 2, 2021
1 parent 1753097 commit 9261277
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ var namespaceCmd = &cobra.Command{
return errors.Wrap(err, "failed to create clientset")
}

namespaces, err := clientset.CoreV1().Namespaces().List(metav1.ListOptions{})
nsFlag, _ := cmd.Flags().GetString("namespace")
nsListOptions := metav1.ListOptions{}

if nsFlag != "" {
nsFieldSelector, err := fields.ParseSelector("metadata.name=" + nsFlag)
if err != nil {
return errors.Wrap(err, "failed to create fieldSelector")
}
nsListOptions = metav1.ListOptions{FieldSelector: nsFieldSelector.String()}
}

namespaces, err := clientset.CoreV1().Namespaces().List(nsListOptions)
if err != nil {
return errors.Wrap(err, "failed to list namespaces")
}
Expand Down

0 comments on commit 9261277

Please sign in to comment.