Skip to content

Commit 68d8db9

Browse files
committed
Add product-name support for Node Labeller
Change-Id: I87995f28c0d059a04844158c1089a26b9ebd8cae
1 parent d156d24 commit 68d8db9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cmd/k8s-node-labeller/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ var labelGenerators = map[string]func(map[string]map[string]int) map[string]stri
115115
}
116116
return results
117117
},
118+
"product-name": func(gpus map[string]map[string]int) map[string]string {
119+
counts := map[string]int{}
120+
replacer := strings.NewReplacer(" ", "_")
121+
122+
for _, v := range gpus {
123+
prodnamePath := fmt.Sprintf("/sys/class/drm/card%d/device/product_name", v["card"])
124+
b, err := ioutil.ReadFile(prodnamePath)
125+
if err != nil {
126+
log.Error(err, prodnamePath)
127+
continue
128+
}
129+
prodName := strings.TrimSpace(string(b))
130+
counts[prodName]++
131+
}
132+
133+
pfx := createLabelPrefix("product-name", true)
134+
results := make(map[string]string, len(counts))
135+
for k, v := range counts {
136+
results[fmt.Sprintf("%s.%s", pfx, replacer.Replace(k))] = strconv.Itoa(v)
137+
}
138+
return results
139+
},
118140
"vram": func(gpus map[string]map[string]int) map[string]string {
119141
const bytePerMB = int64(1024 * 1024)
120142
counts := map[string]int{}

0 commit comments

Comments
 (0)