@@ -19,7 +19,6 @@ package store
19
19
import (
20
20
"context"
21
21
"k8s.io/apimachinery/pkg/api/resource"
22
- "math"
23
22
"strings"
24
23
25
24
basemetrics "k8s.io/component-base/metrics"
@@ -355,7 +354,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
355
354
SanitizeLabelName (string (resourceName )),
356
355
string (constant .UnitByte ),
357
356
},
358
- Value : convertFloat64 (& val ),
357
+ Value : convertValueToFloat64 (& val ),
359
358
})
360
359
}
361
360
if isAttachableVolumeResourceName (resourceName ) {
@@ -364,7 +363,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
364
363
SanitizeLabelName (string (resourceName )),
365
364
string (constant .UnitByte ),
366
365
},
367
- Value : convertFloat64 (& val ),
366
+ Value : convertValueToFloat64 (& val ),
368
367
})
369
368
}
370
369
if isExtendedResourceName (resourceName ) {
@@ -373,7 +372,7 @@ func createNodeStatusAllocatableFamilyGenerator() generator.FamilyGenerator {
373
372
SanitizeLabelName (string (resourceName )),
374
373
string (constant .UnitInteger ),
375
374
},
376
- Value : convertFloat64 (& val ),
375
+ Value : convertValueToFloat64 (& val ),
377
376
})
378
377
}
379
378
}
@@ -409,7 +408,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
409
408
SanitizeLabelName (string (resourceName )),
410
409
string (constant .UnitCore ),
411
410
},
412
- Value : convertFloat64 (& val ),
411
+ Value : convertValueToFloat64 (& val ),
413
412
})
414
413
case v1 .ResourceStorage :
415
414
fallthrough
@@ -421,15 +420,15 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
421
420
SanitizeLabelName (string (resourceName )),
422
421
string (constant .UnitByte ),
423
422
},
424
- Value : convertFloat64 (& val ),
423
+ Value : convertValueToFloat64 (& val ),
425
424
})
426
425
case v1 .ResourcePods :
427
426
ms = append (ms , & metric.Metric {
428
427
LabelValues : []string {
429
428
SanitizeLabelName (string (resourceName )),
430
429
string (constant .UnitInteger ),
431
430
},
432
- Value : convertFloat64 (& val ),
431
+ Value : convertValueToFloat64 (& val ),
433
432
})
434
433
default :
435
434
if isHugePageResourceName (resourceName ) {
@@ -438,7 +437,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
438
437
SanitizeLabelName (string (resourceName )),
439
438
string (constant .UnitByte ),
440
439
},
441
- Value : convertFloat64 (& val ),
440
+ Value : convertValueToFloat64 (& val ),
442
441
})
443
442
}
444
443
if isAttachableVolumeResourceName (resourceName ) {
@@ -447,7 +446,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
447
446
SanitizeLabelName (string (resourceName )),
448
447
string (constant .UnitByte ),
449
448
},
450
- Value : convertFloat64 (& val ),
449
+ Value : convertValueToFloat64 (& val ),
451
450
})
452
451
}
453
452
if isExtendedResourceName (resourceName ) {
@@ -456,7 +455,7 @@ func createNodeStatusCapacityFamilyGenerator() generator.FamilyGenerator {
456
455
SanitizeLabelName (string (resourceName )),
457
456
string (constant .UnitInteger ),
458
457
},
459
- Value : convertFloat64 (& val ),
458
+ Value : convertValueToFloat64 (& val ),
460
459
})
461
460
}
462
461
}
@@ -533,10 +532,8 @@ func createNodeListWatch(kubeClient clientset.Interface, _ string, _ string) cac
533
532
}
534
533
}
535
534
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 {
540
537
return float64 (q .Value ())
541
538
}
542
539
return float64 (q .MilliValue ()) / 1000
0 commit comments