import ( "fmt" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" ) func main() { // Create a NodeLister object nodeLister := algorithm.NewNodeLister() // Get the list of nodes nodeList, _ := nodeLister.List() // Iterate over the list of nodes and print their names fmt.Println("List of available nodes:") for _, nodeInfo := range nodeList { fmt.Printf("\t%s\n", nodeInfo.Name) } }
import ( "fmt" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" ) func main() { // Create a NodeLister object nodeLister := algorithm.NewNodeLister() // Get the list of nodes nodeList, _ := nodeLister.List() // Filter the list of nodes based on node labels filteredNodes := []algorithm.NodeInfo{} for _, nodeInfo := range nodeList { if nodeInfo.Labels["disk_type"] == "ssd" { filteredNodes = append(filteredNodes, nodeInfo) } } // Print the filtered list of nodes fmt.Println("List of available nodes (filtered by label 'disk_type=ssd'):") for _, nodeInfo := range filteredNodes { fmt.Printf("\t%s\n", nodeInfo.Name) } }The package library is kubernetes.