Skip to content

Commit

Permalink
Merge pull request #35 from etopeter/node-schedulable-only
Browse files Browse the repository at this point in the history
Node schedulable only
  • Loading branch information
etopeter authored Aug 9, 2019
2 parents e24e21d + 6882cd8 commit d623b75
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# v0.2.2
- Fix for unschedulable nodes showing in utilization. [Issue #34](https://github.com/etopeter/kubectl-view-utilization/issues/34)
4 changes: 2 additions & 2 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.2.1"
PLUGIN_VERSION="v0.2.2"
VIEW_UTILIZATION_NAMESPACE=""
VIEW_UTILIZATION_NODE_LABEL=""
VIEW_UTILIZATION_OUTPUT="text"
Expand Down Expand Up @@ -116,7 +116,7 @@ get_node_data() {
fi

# shellcheck disable=SC2086
kubectl get nodes $node_label -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}"
kubectl get nodes $node_label --field-selector=spec.unschedulable=false -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}"
}


Expand Down
6 changes: 3 additions & 3 deletions test/kubectl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ load mocks/kubectl

switch_context cluster-small

run kubectl get nodes -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}"
run kubectl get nodes --field-selector=spec.unschedulable=false -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}"

[ $status -eq 0 ]
[[ "${lines[0]}" == "ip-10-1-1-10.us-west-2.compute.internal 449m 1351126Ki" ]]
Expand All @@ -19,7 +19,7 @@ load mocks/kubectl

switch_context cluster-medium

run kubectl get nodes -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}"
run kubectl get nodes --field-selector=spec.unschedulable=false -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}"

[ $status -eq 0 ]
[[ "${lines[0]}" == "ip-10-1-1-10.us-west-2.compute.internal 940m 2702252Ki" ]]
Expand All @@ -30,7 +30,7 @@ load mocks/kubectl

switch_context cluster-big

run kubectl get nodes -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}"
run kubectl get nodes --field-selector=spec.unschedulable=false -o=jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}"

[ $status -eq 0 ]
[[ "${lines[2]}" == "ip-10-1-1-14.us-west-2.compute.internal 4 15850212Ki" ]]
Expand Down
4 changes: 2 additions & 2 deletions test/mocks/kubectl.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ kubectl() {
fi

# get all nodes requests
if [ "${1}" == "get" ] && [ "${2}" == "nodes" ] && [ "${3}" == "-o=jsonpath={range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}" ]; then
if [ "${1}" == "get" ] && [ "${2}" == "nodes" ] && [ "${3}" == "--field-selector=spec.unschedulable=false" ] && [ "${4}" == "-o=jsonpath={range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}" ]; then
kubectl_get_all_nodes_requests
fi

# get master nodes requests
if [ "${1}" == "get" ] && [ "${2}" == "nodes" ] && [ "${3}" == "-l" ] && [ "${4}" == "node-role.kubernetes.io/master=true" ] && [ "${5}" == "-o=jsonpath={range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}" ]; then
if [ "${1}" == "get" ] && [ "${2}" == "nodes" ] && [ "${3}" == "-l" ] && [ "${4}" == "node-role.kubernetes.io/master=true" ] && [ "${5}" == "--field-selector=spec.unschedulable=false" ] && [ "${6}" == "-o=jsonpath={range .items[*]}{.metadata.name}{'\t'}{.status.allocatable.cpu}{'\t'}{.status.allocatable.memory}{'\n'}{end}" ]; then
kubectl_get_master_nodes_requests
fi

Expand Down

0 comments on commit d623b75

Please sign in to comment.