MCPcopy Index your code
hub / github.com/cortexlabs/cortex / validateK8sCompute

Function validateK8sCompute

pkg/operator/resources/validations.go:119–152  ·  view source on GitHub ↗
(api *userconfig.API, maxMemMap map[string]kresource.Quantity)

Source from the content-addressed store, hash-verified

117var _neuronDevicePluginMemReserve = kresource.MustParse("100Mi")
118
119func 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
154func getNodeCapacity(instanceType string, maxMemMap map[string]kresource.Quantity) (kresource.Quantity, kresource.Quantity, int64, int64) {
155 instanceMetadata := aws.InstanceMetadatas[config.ClusterConfig.Region][instanceType]

Callers 1

ValidateClusterAPIsFunction · 0.85

Calls 9

NewFunction · 0.92
WrapFunction · 0.92
GetPodComputeRequestFunction · 0.92
HasStringFunction · 0.92
getNodeCapacityFunction · 0.85
GetNodeGroupNamesMethod · 0.80
HasMethod · 0.45

Tested by

no test coverage detected