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

feat: Added label filters for node & capacity subcommands #31

Merged
merged 1 commit into from
Feb 18, 2024
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
5 changes: 3 additions & 2 deletions pkg/cmd/nodes/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ func NewCmdNodeCapacityInfo() *cobra.Command {
// showNodeCapacities driver function for 'node capacity' command
func showNodeCapacities(cmd *cobra.Command, args []string) error {
var nodeCapacityInfo []pkg.NodeCapacities

nodes, err := utils.Cfg.Clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
labels, _ = cmd.Flags().GetString("labels")

nodes, err := utils.Cfg.Clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: labels})
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cmd/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
showNodeProviderInfo bool
showNodeTopologyInfo bool
sortByHeader string
labels string
)

// NewCmdNodeInfo initializes the 'node' command
Expand All @@ -39,6 +40,7 @@ func NewCmdNodeInfo() *cobra.Command {
cmd.Flags().BoolVarP(&showNodeProviderInfo, "show-providers", "p", false, "Shows cloud provider name for a node")
cmd.Flags().BoolVarP(&showNodeTopologyInfo, "show-topology", "T", false, "Shows node topology info like region & zones for a node")
cmd.PersistentFlags().StringVarP(&sortByHeader, "sort-by", "", "name", "Sorts output using a valid Column name. Defaults to 'name' if the column name is not valid")
cmd.PersistentFlags().StringVarP(&labels, "labels", "l", "", "Filter based on node labels")

// additional sub-commands
cmd.AddCommand(NewCmdNodeCapacityInfo())
Expand All @@ -56,7 +58,7 @@ func showNodeInfo(cmd *cobra.Command, args []string) error {
ShowNodeTopologyInfo: showNodeTopologyInfo,
}

nodes, err := utils.Cfg.Clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := utils.Cfg.Clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: labels})
if err != nil {
return err
}
Expand Down
Loading