@@ -232,6 +232,19 @@ func (lm labelMap) addNumericLabel(labelName string, valueToAdd int64) {
232232 lm [labelName ] = strconv .FormatInt (value , 10 )
233233}
234234
235+ // Stores a long string to labels so that it's possibly split into multiple
236+ // keys: foobar="<something very long>", foobar2="<equally long>", foobar3="The end."
237+ func (lm labelMap ) addSplittableString (labelBase , fullValue string ) {
238+ splitList := pluginutils .SplitAtLastAlphaNum (fullValue , labelMaxLength , labelControlChar )
239+
240+ lm [labelBase ] = splitList [0 ]
241+
242+ for i := 1 ; i < len (splitList ); i ++ {
243+ nextLabel := labelBase + strconv .FormatInt (int64 (i + 1 ), 10 )
244+ lm [nextLabel ] = splitList [i ]
245+ }
246+ }
247+
235248// this returns pci groups label value, groups separated by "_", gpus separated by ".".
236249// Example for two groups with 4 gpus: "0.1.2.3_4.5.6.7".
237250func (l * labeler ) createPCIGroupLabel (gpuNumList []string ) string {
@@ -327,24 +340,13 @@ func (l *labeler) createLabels() error {
327340 strings .Join (gpuNameList , "." ), labelMaxLength , labelControlChar )[0 ]
328341
329342 // add gpu num list label(s) (example: "0.1.2", which is short form of "card0.card1.card2")
330- allGPUs := strings .Join (gpuNumList , "." )
331- gpuNumLists := pluginutils .SplitAtLastAlphaNum (allGPUs , labelMaxLength , labelControlChar )
332-
333- l .labels [labelNamespace + gpuNumListLabelName ] = gpuNumLists [0 ]
334- for i := 1 ; i < len (gpuNumLists ); i ++ {
335- l .labels [labelNamespace + gpuNumListLabelName + strconv .FormatInt (int64 (i + 1 ), 10 )] = gpuNumLists [i ]
336- }
343+ l .labels .addSplittableString (labelNamespace + gpuNumListLabelName , strings .Join (gpuNumList , "." ))
337344
338345 if len (numaMapping ) > 0 {
339346 // add numa node mapping to labels: gpu.intel.com/numa-gpu-map="0-0.1.2.3_1-4.5.6.7"
340347 numaMappingLabel := createNumaNodeMappingLabel (numaMapping )
341348
342- numaMappingLabelList := pluginutils .SplitAtLastAlphaNum (numaMappingLabel , labelMaxLength , labelControlChar )
343-
344- l .labels [labelNamespace + numaMappingName ] = numaMappingLabelList [0 ]
345- for i := 1 ; i < len (numaMappingLabelList ); i ++ {
346- l .labels [labelNamespace + numaMappingName + strconv .FormatInt (int64 (i + 1 ), 10 )] = numaMappingLabelList [i ]
347- }
349+ l .labels .addSplittableString (labelNamespace + numaMappingName , numaMappingLabel )
348350 }
349351
350352 // all GPUs get default number of millicores (1000)
@@ -353,12 +355,7 @@ func (l *labeler) createLabels() error {
353355 // aa pci-group label(s), (two group example: "1.2.3.4_5.6.7.8")
354356 allPCIGroups := l .createPCIGroupLabel (gpuNumList )
355357 if allPCIGroups != "" {
356- pciGroups := pluginutils .SplitAtLastAlphaNum (allPCIGroups , labelMaxLength , labelControlChar )
357-
358- l .labels [labelNamespace + pciGroupLabelName ] = pciGroups [0 ]
359- for i := 1 ; i < len (gpuNumLists ); i ++ {
360- l .labels [labelNamespace + pciGroupLabelName + strconv .FormatInt (int64 (i + 1 ), 10 )] = pciGroups [i ]
361- }
358+ l .labels .addSplittableString (labelNamespace + pciGroupLabelName , allPCIGroups )
362359 }
363360 }
364361
0 commit comments