Skip to content

Commit

Permalink
Merge pull request #53 from etopeter/Memory-report-showing-error-issu…
Browse files Browse the repository at this point in the history
…e-52

Memory report showing error issue 52
  • Loading branch information
etopeter authored Nov 26, 2019
2 parents 116a1b8 + 4ec567b commit 497f899
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v0.3.2
- Fixed handling of node allocatable memory parsing [Issue #52](https://github.com/etopeter/kubectl-view-utilization/issues/52)

# v0.3.1
- Fixed node view graph not showing for low utilization nodes [Issue #49](https://github.com/etopeter/kubectl-view-utilization/issues/49)

Expand Down
10 changes: 6 additions & 4 deletions kubectl-view-utilization
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Prints cluster resource utilization


PLUGIN_VERSION="v0.3.1"
PLUGIN_VERSION="v0.3.2"
VIEW_UTILIZATION_NAMESPACE=""
VIEW_UTILIZATION_NODE_LABEL=""
VIEW_UTILIZATION_OUTPUT="text"
Expand Down Expand Up @@ -160,9 +160,11 @@ cluster_utilization() {
awkcmd='BEGIN {FS="\t"};
NR==FNR { node[$1]; }
NR==FNR && $2 ~ /[0-9]$/ { alloc_cpu+=$2*1000; };
NR==FNR && $2 ~ /m?$/ { alloc_cpu+=$2; };
NR==FNR && $3 ~ /Ki?$/ { alloc_mem+=$3*1024; next };
NR==FNR && $2 ~ /[0-9]$/ { alloc_cpu+=$2*1000; };
NR==FNR && $2 ~ /m?$/ { alloc_cpu+=$2; };
NR==FNR && $3 ~ /[kK](i)?$/ { alloc_mem+=$3*1024; next };
NR==FNR && $3 ~ /M(i)?$/ { alloc_mem+=$3*1048576; next };
NR==FNR && $3 ~ /[gG](i)?$/ { alloc_mem+=$3*1073741824; next };
# CPU requests
$2 in node && $3 ~ /[0-9]$/ { req_cpu+=$3*1000; };
Expand Down
11 changes: 10 additions & 1 deletion test/mocks/kubectl.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

kubectl() {
local clusters=(cluster-small cluster-medium cluster-big cluster-bug1)
local clusters=(cluster-small cluster-medium cluster-big cluster-bug1 cluster-issue-52)

if [ "${1}" == "config" ] && [ "${2}" == "use-context" ] && [[ "${clusters[*]}" =~ $3 ]]; then
KUBECTL_CONTEXT="${3}"
Expand Down Expand Up @@ -65,6 +65,11 @@ kubectl_get_all_nodes_requests() {
echo "ip-10-1-1-11.us-west-2.compute.internal 4 2702252Ki"
fi

if [ "${KUBECTL_CONTEXT}" == "cluster-issue-52" ]; then
echo "ip-10-1-1-10.us-west-2.compute.internal 1 2250Mi"
echo "ip-10-1-1-11.us-west-2.compute.internal 1 1574Mi"
fi


if [ "${KUBECTL_CONTEXT}" == "cluster-small" ]; then
echo "ip-10-1-1-10.us-west-2.compute.internal 449m 1351126Ki"
Expand Down Expand Up @@ -146,6 +151,10 @@ kubectl_get_all_pods_requests_with_namespaces() {
echo "infra ip-10-1-1-11.us-west-2.compute.internal 0 937500k 0 0Ki"
fi

if [ "${KUBECTL_CONTEXT}" == "cluster-issue-52" ]; then
echo "kube-system ip-10-1-1-10.us-west-2.compute.internal 100m 100Mi 100m 150Mi"
echo "default ip-10-1-1-11.us-west-2.compute.internal 200m 200Mi 250m 250Mi"
fi

if [ "${KUBECTL_CONTEXT}" == "cluster-small" ]; then
echo "default ip-10-1-1-10.us-west-2.compute.internal 10m 0Ki 100m 50Ki"
Expand Down
14 changes: 14 additions & 0 deletions test/utilization.bats
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,18 @@ load mocks/kubectl
[[ "${lines[2]}" == "Memory 455081984 0 0 0 1790902091776 1790447009792 1790447009792" ]]
}

@test "[u29] cluster-issue-52 (original-awk)> kubectl view utilization" {

use_awk original-awk
switch_context cluster-issue-52

run /code/kubectl-view-utilization

[ $status -eq 0 ]
echo "${output}"
[[ "${lines[0]}" == "Resource Requests %Requests Limits %Limits Allocatable Schedulable Free" ]]
[[ "${lines[1]}" == "CPU 300 14 350 17 2002 1702 1652" ]]
[[ "${lines[2]}" == "Memory 314572800 7 419430400 10 4009754624 3695181824 3590324224" ]]
}


0 comments on commit 497f899

Please sign in to comment.