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

Function getMemoryCapacityFromNodes

pkg/operator/operator/memory_capacity.go:32–74  ·  view source on GitHub ↗
(primaryInstances []string)

Source from the content-addressed store, hash-verified

30const _configKeyPrefix = "memory-capacity-"
31
32func getMemoryCapacityFromNodes(primaryInstances []string) (map[string]*kresource.Quantity, error) {
33 opts := kmeta.ListOptions{
34 LabelSelector: klabels.SelectorFromSet(map[string]string{
35 "workload": "true",
36 }).String(),
37 }
38 nodes, err := config.K8s.ListNodes(&opts)
39 if err != nil {
40 return nil, err
41 }
42
43 minMemMap := map[string]*kresource.Quantity{}
44 for _, primaryInstance := range primaryInstances {
45 minMemMap[primaryInstance] = nil
46 }
47
48 for _, node := range nodes {
49 isPrimaryInstance := false
50 var primaryInstanceType string
51 for k, v := range node.Labels {
52 if k == "node.kubernetes.io/instance-type" && slices.HasString(primaryInstances, v) {
53 isPrimaryInstance = true
54 primaryInstanceType = v
55 break
56 }
57 }
58 if !isPrimaryInstance {
59 continue
60 }
61
62 curMem := node.Status.Capacity.Memory()
63
64 if curMem == nil || curMem.IsZero() {
65 continue
66 }
67
68 if minMemMap[primaryInstanceType] == nil || minMemMap[primaryInstanceType].Cmp(*curMem) > 0 {
69 minMemMap[primaryInstanceType] = curMem
70 }
71 }
72
73 return minMemMap, nil
74}
75
76func getMemoryCapacityFromConfigMap() (map[string]*kresource.Quantity, error) {
77 configMapData, _, err := config.K8s.GetConfigMapData(_memConfigMapName)

Callers 1

Calls 3

HasStringFunction · 0.92
ListNodesMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected