fix(kubernetes): better management of units (#3419)

This commit is contained in:
qgarnier 2022-01-25 13:31:25 +01:00 committed by GitHub
parent 09cc171a10
commit f549e1afef
1 changed files with 10 additions and 6 deletions

View File

@ -210,7 +210,7 @@ sub manage_selection {
$self->{nodes}->{$node->{metadata}->{name}} = { $self->{nodes}->{$node->{metadata}->{name}} = {
display => $node->{metadata}->{name}, display => $node->{metadata}->{name},
pods_allocatable => $node->{status}->{allocatable}->{pods}, pods_allocatable => $node->{status}->{allocatable}->{pods},
cpu_allocatable => $self->to_bytes(value => $node->{status}->{allocatable}->{cpu}), cpu_allocatable => $self->to_core(value => $node->{status}->{allocatable}->{cpu}),
memory_allocatable => $self->to_bytes(value => $node->{status}->{capacity}->{memory}), memory_allocatable => $self->to_bytes(value => $node->{status}->{capacity}->{memory}),
} }
} }
@ -239,14 +239,18 @@ sub to_bytes {
my $value = $options{value}; my $value = $options{value};
if ($value =~ /(\d+)Ki$/) { if ($value =~ /(\d+)m$/) {
$value = $1 / 1000;
} elsif ($value =~ /(\d+)Ki?$/) {
$value = $1 * 1024; $value = $1 * 1024;
} elsif ($value =~ /(\d+)Mi$/) { } elsif ($value =~ /(\d+)Mi?$/) {
$value = $1 * 1024 * 1024; $value = $1 * 1024 * 1024;
} elsif ($value =~ /(\d+)Gi$/) { } elsif ($value =~ /(\d+)Gi?$/) {
$value = $1 * 1024 * 1024 * 1024; $value = $1 * 1024 * 1024 * 1024;
} elsif ($value =~ /(\d+)Ti$/) { } elsif ($value =~ /(\d+)Ti?$/) {
$value = $1 * 1024 * 1024 * 1024 * 1024; $value = $1 * 1024 * 1024 * 1024 * 1024;
} elsif ($value =~ /(\d+)Pi?$/) {
$value = $1 * 1024 * 1024 * 1024 * 1024 * 1024;
} }
return $value; return $value;