예제 #1
0
파일: utils.go 프로젝트: adamschaub/contrib
// GetNodeInfosForMigs finds NodeInfos for all migs used to manage the given nodes. It also returns a mig to sample node mapping.
func GetNodeInfosForMigs(nodes []*kube_api.Node, gceManager *gce.GceManager, kubeClient *kube_client.Client) (map[string]*schedulercache.NodeInfo,
	map[string]*kube_api.Node, error) {
	sampleNodes := make(map[string]*kube_api.Node)
	for _, node := range nodes {
		instanceConfig, err := config.InstanceConfigFromProviderId(node.Spec.ProviderID)
		if err != nil {
			return map[string]*schedulercache.NodeInfo{}, map[string]*kube_api.Node{}, err
		}

		migConfig, err := gceManager.GetMigForInstance(instanceConfig)
		if err != nil {
			return map[string]*schedulercache.NodeInfo{}, map[string]*kube_api.Node{}, err
		}
		url := migConfig.Url()
		sampleNodes[url] = node
	}
	result := make(map[string]*schedulercache.NodeInfo)
	for url, node := range sampleNodes {
		nodeInfo, err := simulator.BuildNodeInfoForNode(node.Name, kubeClient)
		if err != nil {
			return map[string]*schedulercache.NodeInfo{}, map[string]*kube_api.Node{}, err
		}
		result[url] = nodeInfo
	}
	return result, sampleNodes, nil
}
예제 #2
0
파일: utils.go 프로젝트: spxtr/contrib
// GetNodeInfosForGroups finds NodeInfos for all node groups used to manage the given nodes. It also returns a node group to sample node mapping.
// TODO(mwielgus): This returns map keyed by url, while most code (including scheduler) uses node.Name for a key.
func GetNodeInfosForGroups(nodes []*kube_api.Node, cloudProvider cloudprovider.CloudProvider, kubeClient *kube_client.Client) (map[string]*schedulercache.NodeInfo, error) {
	result := make(map[string]*schedulercache.NodeInfo)
	for _, node := range nodes {

		nodeGroup, err := cloudProvider.NodeGroupForNode(node)
		if err != nil {
			return map[string]*schedulercache.NodeInfo{}, err
		}
		if nodeGroup == nil || reflect.ValueOf(nodeGroup).IsNil() {
			continue
		}
		id := nodeGroup.Id()
		if _, found := result[id]; !found {
			nodeInfo, err := simulator.BuildNodeInfoForNode(node, kubeClient)
			if err != nil {
				return map[string]*schedulercache.NodeInfo{}, err
			}
			result[id] = nodeInfo
		}
	}
	return result, nil
}