Skip to content

Commit 2c34676

Browse files
committed
change convertValueToFloat64 function name
1 parent 31f7931 commit 2c34676

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

internal/store/node.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package store
1919
import (
2020
"context"
2121
"k8s.io/apimachinery/pkg/api/resource"
22-
"math"
2322
"strings"
2423

2524
basemetrics "k8s.io/component-base/metrics"
@@ -355,7 +354,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
355354
SanitizeLabelName(string(resourceName)),
356355
string(constant.UnitByte),
357356
},
358-
Value: convertFloat64(&val),
357+
Value: convertValueToFloat64(&val),
359358
})
360359
}
361360
if isAttachableVolumeResourceName(resourceName) {
@@ -364,7 +363,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
364363
SanitizeLabelName(string(resourceName)),
365364
string(constant.UnitByte),
366365
},
367-
Value: convertFloat64(&val),
366+
Value: convertValueToFloat64(&val),
368367
})
369368
}
370369
if isExtendedResourceName(resourceName) {
@@ -373,7 +372,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
373372
SanitizeLabelName(string(resourceName)),
374373
string(constant.UnitInteger),
375374
},
376-
Value: convertFloat64(&val),
375+
Value: convertValueToFloat64(&val),
377376
})
378377
}
379378
}
@@ -409,7 +408,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
409408
SanitizeLabelName(string(resourceName)),
410409
string(constant.UnitCore),
411410
},
412-
Value: convertFloat64(&val),
411+
Value: convertValueToFloat64(&val),
413412
})
414413
case v1.ResourceStorage:
415414
fallthrough
@@ -421,15 +420,15 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
421420
SanitizeLabelName(string(resourceName)),
422421
string(constant.UnitByte),
423422
},
424-
Value: convertFloat64(&val),
423+
Value: convertValueToFloat64(&val),
425424
})
426425
case v1.ResourcePods:
427426
ms = append(ms, &metric.Metric{
428427
LabelValues: []string{
429428
SanitizeLabelName(string(resourceName)),
430429
string(constant.UnitInteger),
431430
},
432-
Value: convertFloat64(&val),
431+
Value: convertValueToFloat64(&val),
433432
})
434433
default:
435434
if isHugePageResourceName(resourceName) {
@@ -438,7 +437,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
438437
SanitizeLabelName(string(resourceName)),
439438
string(constant.UnitByte),
440439
},
441-
Value: convertFloat64(&val),
440+
Value: convertValueToFloat64(&val),
442441
})
443442
}
444443
if isAttachableVolumeResourceName(resourceName) {
@@ -447,7 +446,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
447446
SanitizeLabelName(string(resourceName)),
448447
string(constant.UnitByte),
449448
},
450-
Value: convertFloat64(&val),
449+
Value: convertValueToFloat64(&val),
451450
})
452451
}
453452
if isExtendedResourceName(resourceName) {
@@ -456,7 +455,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
456455
SanitizeLabelName(string(resourceName)),
457456
string(constant.UnitInteger),
458457
},
459-
Value: convertFloat64(&val),
458+
Value: convertValueToFloat64(&val),
460459
})
461460
}
462461
}
@@ -533,10 +532,8 @@ func createNodeListWatch(kubeClient clientset.Interface, _ string, _ string) cac
533532
}
534533
}
535534

536-
const maxValue = math.MaxInt64 / 1000
537-
538-
func convertFloat64(q *resource.Quantity) float64 {
539-
if q.Value() > maxValue {
535+
func convertValueToFloat64(q *resource.Quantity) float64 {
536+
if q.Value() > resource.MaxMilliValue {
540537
return float64(q.Value())
541538
}
542539
return float64(q.MilliValue()) / 1000

0 commit comments

Comments
 (0)