(api *userconfig.API, maxMemMap map[string]kresource.Quantity)
| 117 | var _neuronDevicePluginMemReserve = kresource.MustParse("100Mi") |
| 118 | |
| 119 | func validateK8sCompute(api *userconfig.API, maxMemMap map[string]kresource.Quantity) error { |
| 120 | clusterNodeGroupNames := strset.New(config.ClusterConfig.GetNodeGroupNames()...) |
| 121 | for _, ngName := range api.NodeGroups { |
| 122 | if !clusterNodeGroupNames.Has(ngName) { |
| 123 | return errors.Wrap(ErrorInvalidNodeGroupSelector(ngName, config.ClusterConfig.GetNodeGroupNames()), userconfig.NodeGroupsKey) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | compute := userconfig.GetPodComputeRequest(api) |
| 128 | |
| 129 | for _, ng := range config.ClusterConfig.NodeGroups { |
| 130 | if api.NodeGroups != nil && !slices.HasString(api.NodeGroups, ng.Name) { |
| 131 | continue |
| 132 | } |
| 133 | |
| 134 | nodeCPU, nodeMem, nodeGPU, nodeInf := getNodeCapacity(ng.InstanceType, maxMemMap) |
| 135 | |
| 136 | if compute.CPU != nil && nodeCPU.Cmp(compute.CPU.Quantity) < 0 { |
| 137 | continue |
| 138 | } else if compute.Mem != nil && nodeMem.Cmp(compute.Mem.Quantity) < 0 { |
| 139 | continue |
| 140 | } else if compute.GPU > nodeGPU { |
| 141 | continue |
| 142 | } else if compute.Inf > nodeInf { |
| 143 | continue |
| 144 | } |
| 145 | |
| 146 | // we found a node group that has capacity |
| 147 | return nil |
| 148 | } |
| 149 | |
| 150 | // no nodegroups have capacity |
| 151 | return ErrorNoAvailableNodeComputeLimit(api, compute, maxMemMap) |
| 152 | } |
| 153 | |
| 154 | func getNodeCapacity(instanceType string, maxMemMap map[string]kresource.Quantity) (kresource.Quantity, kresource.Quantity, int64, int64) { |
| 155 | instanceMetadata := aws.InstanceMetadatas[config.ClusterConfig.Region][instanceType] |
no test coverage detected