@@ -342,27 +342,6 @@ func (l *labeler) createPCIGroupLabel(gpuNumList []string) string {
342342 return labelValue
343343}
344344
345- // split returns the given string cut to chunks of size up to maxLength size.
346- // maxLength refers to the max length of the strings in the returned slice.
347- // If the whole input string fits under maxLength, it is not split.
348- // split("foo_bar", 4) returns []string{"foo_", "bar"}.
349- func split (str string , maxLength uint ) []string {
350- remainingString := str
351- results := []string {}
352-
353- for len (remainingString ) >= 0 {
354- if uint (len (remainingString )) <= maxLength {
355- results = append (results , remainingString )
356- return results
357- }
358-
359- results = append (results , remainingString [:maxLength ])
360- remainingString = remainingString [maxLength :]
361- }
362-
363- return results
364- }
365-
366345// createLabels is the main function of plugin labeler, it creates label-value pairs for the gpus.
367346func (l * labeler ) createLabels () error {
368347 gpuNameList , err := l .scan ()
@@ -412,11 +391,11 @@ func (l *labeler) createLabels() error {
412391
413392 if gpuCount > 0 {
414393 // add gpu list label (example: "card0.card1.card2") - deprecated
415- l .labels [labelNamespace + gpuListLabelName ] = split (strings .Join (gpuNameList , "." ), labelMaxLength )[0 ]
394+ l .labels [labelNamespace + gpuListLabelName ] = pluginutils . Split (strings .Join (gpuNameList , "." ), labelMaxLength )[0 ]
416395
417396 // add gpu num list label(s) (example: "0.1.2", which is short form of "card0.card1.card2")
418397 allGPUs := strings .Join (gpuNumList , "." )
419- gpuNumLists := split (allGPUs , labelMaxLength )
398+ gpuNumLists := pluginutils . Split (allGPUs , labelMaxLength )
420399
421400 l .labels [labelNamespace + gpuNumListLabelName ] = gpuNumLists [0 ]
422401 for i := 1 ; i < len (gpuNumLists ); i ++ {
@@ -427,7 +406,7 @@ func (l *labeler) createLabels() error {
427406 // add numa node mapping to labels: gpu.intel.com/numa-gpu-map="0-0.1.2.3_1-4.5.6.7"
428407 numaMappingLabel := createNumaNodeMappingLabel (numaMapping )
429408
430- numaMappingLabelList := split (numaMappingLabel , labelMaxLength )
409+ numaMappingLabelList := pluginutils . Split (numaMappingLabel , labelMaxLength )
431410
432411 l .labels [labelNamespace + numaMappingName ] = numaMappingLabelList [0 ]
433412 for i := 1 ; i < len (numaMappingLabelList ); i ++ {
@@ -441,7 +420,7 @@ func (l *labeler) createLabels() error {
441420 // aa pci-group label(s), (two group example: "1.2.3.4_5.6.7.8")
442421 allPCIGroups := l .createPCIGroupLabel (gpuNumList )
443422 if allPCIGroups != "" {
444- pciGroups := split (allPCIGroups , labelMaxLength )
423+ pciGroups := pluginutils . Split (allPCIGroups , labelMaxLength )
445424
446425 l .labels [labelNamespace + pciGroupLabelName ] = pciGroups [0 ]
447426 for i := 1 ; i < len (gpuNumLists ); i ++ {
0 commit comments