Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more information to node describe #5139

Merged
merged 1 commit into from
Mar 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions hack/lib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,32 @@ kube::test::get_object_assert() {
return 1
fi
}

kube::test::describe_object_assert() {
local resource=$1
local object=$2
local matches=${@:3}

result=$(eval kubectl describe "${kube_flags[@]}" $resource $object)

for match in ${matches}; do
if [[ ! $(echo "$result" | grep ${match}) ]]; then
echo ${bold}${red}
echo "FAIL!"
echo "Describe $resource $object"
echo " Expected Match: $match"
echo " Not found in:"
echo "$result"
echo ${reset}${red}
caller
echo ${reset}
return 1
fi
done

echo -n ${green}
echo "Successful describe $resource $object:"
echo "$result"
echo -n ${reset}
return 0
}
8 changes: 6 additions & 2 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ CTLRMGR_PID=$!
kube::util::wait_for_url "http://127.0.0.1:${CTLRMGR_PORT}/healthz" "controller-manager: "
kube::util::wait_for_url "http://127.0.0.1:${API_PORT}/api/v1beta1/minions/127.0.0.1" "apiserver(minions): " 0.2 25

# expose kubectl directly for readability
# Expose kubectl directly for readability
PATH="${KUBE_OUTPUT_HOSTBIN}":$PATH

kube_api_versions=(
Expand Down Expand Up @@ -139,7 +139,7 @@ for version in "${kube_api_versions[@]}"; do
rc_replicas_field="spec.replicas"
fi

# passing no arguments to create is an error
# Passing no arguments to create is an error
! kubectl create

###########################
Expand Down Expand Up @@ -502,6 +502,8 @@ __EOF__

kube::test::get_object_assert nodes "{{range.items}}{{.$id_field}}:{{end}}" '127.0.0.1:'

kube::test::describe_object_assert nodes "127.0.0.1" "Name:" "Conditions:" "Addresses:" "Capacity:" "Pods:"

###########
# Minions #
###########
Expand All @@ -513,6 +515,8 @@ __EOF__

# TODO: I should be a MinionList instead of List
kube::test::get_object_assert minions '{{.kind}}' 'List'

kube::test::describe_object_assert minions "127.0.0.1" "Name:" "Conditions:" "Addresses:" "Capacity:" "Pods:"
fi

kube::test::clear_all
Expand Down
33 changes: 22 additions & 11 deletions pkg/kubectl/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func DescriberFor(kind string, c *client.Client) (Describer, bool) {
case "Service":
return &ServiceDescriber{c}, true
case "Minion", "Node":
return &MinionDescriber{c}, true
return &NodeDescriber{c}, true
case "LimitRange":
return &LimitRangeDescriber{c}, true
case "ResourceQuota":
Expand Down Expand Up @@ -283,14 +283,14 @@ func (d *ServiceDescriber) Describe(namespace, name string) (string, error) {
})
}

// MinionDescriber generates information about a minion.
type MinionDescriber struct {
// NodeDescriber generates information about a node.
type NodeDescriber struct {
client.Interface
}

func (d *MinionDescriber) Describe(namespace, name string) (string, error) {
func (d *NodeDescriber) Describe(namespace, name string) (string, error) {
mc := d.Nodes()
minion, err := mc.Get(name)
node, err := mc.Get(name)
if err != nil {
return "", err
}
Expand All @@ -307,13 +307,13 @@ func (d *MinionDescriber) Describe(namespace, name string) (string, error) {
pods = append(pods, pod)
}

events, _ := d.Events(namespace).Search(minion)
events, _ := d.Events(namespace).Search(node)

return tabbedString(func(out io.Writer) error {
fmt.Fprintf(out, "Name:\t%s\n", minion.Name)
if len(minion.Status.Conditions) > 0 {
fmt.Fprintf(out, "Name:\t%s\n", node.Name)
if len(node.Status.Conditions) > 0 {
fmt.Fprint(out, "Conditions:\n Type\tStatus\tLastProbeTime\tLastTransitionTime\tReason\tMessage\n")
for _, c := range minion.Status.Conditions {
for _, c := range node.Status.Conditions {
fmt.Fprintf(out, " %v \t%v \t%s \t%s \t%v \t%v\n",
c.Type,
c.Status,
Expand All @@ -323,12 +323,23 @@ func (d *MinionDescriber) Describe(namespace, name string) (string, error) {
c.Message)
}
}
if len(minion.Spec.Capacity) > 0 {
var addresses []string
for _, address := range node.Status.Addresses {
addresses = append(addresses, address.Address)
}
fmt.Fprintf(out, "Addresses:\t%s\n", strings.Join(addresses, ","))
if len(node.Spec.Capacity) > 0 {
fmt.Fprintf(out, "Capacity:\n")
for resource, value := range minion.Spec.Capacity {
for resource, value := range node.Spec.Capacity {
fmt.Fprintf(out, " %s:\t%s\n", resource, value.String())
}
}
if len(node.Spec.PodCIDR) > 0 {
fmt.Fprintf(out, "PodCIDR:\t%s\n", node.Spec.PodCIDR)
}
if len(node.Spec.ExternalID) > 0 {
fmt.Fprintf(out, "ExternalID:\t%s\n", node.Spec.ExternalID)
}
fmt.Fprintf(out, "Pods:\t(%d in total)\n", len(pods))
for _, pod := range pods {
if pod.Status.Host != name {
Expand Down