Skip to content

Commit

Permalink
kubectl describe <kind> work with no arguments
Browse files Browse the repository at this point in the history
Add describe_resource_assert to test describe <kind> with no object arg
  • Loading branch information
feihujiang committed Aug 10, 2015
1 parent 2bfa9a1 commit 73b694e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/man/man1/kubectl-describe.1
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ $ kubectl describe pods/nginx
// Describe a pod using the data in pod.json.
$ kubectl describe \-f pod.json

// Describe all pods
$ kubectl describe pods

// Describe pods by label name=myLabel
$ kubectl describe po \-l name=myLabel

Expand Down
5 changes: 4 additions & 1 deletion docs/user-guide/kubectl/kubectl_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ $ kubectl describe pods/nginx
// Describe a pod using the data in pod.json.
$ kubectl describe -f pod.json
// Describe all pods
$ kubectl describe pods
// Describe pods by label name=myLabel
$ kubectl describe po -l name=myLabel
Expand Down Expand Up @@ -118,7 +121,7 @@ $ kubectl describe pods frontend

* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager

###### Auto generated by spf13/cobra at 2015-08-07 07:32:08.128980687 +0000 UTC
###### Auto generated by spf13/cobra at 2015-08-10 06:08:06.262721462 +0000 UTC

<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_describe.md?pixel)]()
Expand Down
28 changes: 28 additions & 0 deletions hack/lib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,31 @@ kube::test::describe_object_assert() {
echo -n ${reset}
return 0
}

kube::test::describe_resource_assert() {
local resource=$1
local matches=${@:2}

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

for match in ${matches}; do
if [[ ! $(echo "$result" | grep ${match}) ]]; then
echo ${bold}${red}
echo "FAIL!"
echo "Describe $resource"
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:"
echo "$result"
echo -n ${reset}
return 0
}
8 changes: 8 additions & 0 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ runTests() {
kube::test::get_object_assert 'pods/valid-pod' "{{$id_field}}" 'valid-pod'
# Describe command should print detailed information
kube::test::describe_object_assert pods 'valid-pod' "Name:" "Image(s):" "Node:" "Labels:" "Status:" "Replication Controllers"
# Describe command (resource only) should print detailed information
kube::test::describe_resource_assert pods "Name:" "Image(s):" "Node:" "Labels:" "Status:" "Replication Controllers"

### Dump current valid-pod POD
output_pod=$(kubectl get pod valid-pod -o yaml --output-version=v1 "${kube_flags[@]}")
Expand Down Expand Up @@ -493,6 +495,8 @@ runTests() {
kube::test::get_object_assert services "{{range.items}}{{$id_field}}:{{end}}" 'kubernetes:redis-master:'
# Describe command should print detailed information
kube::test::describe_object_assert services 'redis-master' "Name:" "Labels:" "Selector:" "IP:" "Port:" "Endpoints:" "Session Affinity:"
# Describe command (resource only) should print detailed information
kube::test::describe_resource_assert services "Name:" "Labels:" "Selector:" "IP:" "Port:" "Endpoints:" "Session Affinity:"

### Dump current redis-master service
output_service=$(kubectl get service redis-master -o json --output-version=v1 "${kube_flags[@]}")
Expand Down Expand Up @@ -592,6 +596,8 @@ __EOF__
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'
# Describe command should print detailed information
kube::test::describe_object_assert rc 'frontend' "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"
# Describe command (resource only) should print detailed information
kube::test::describe_resource_assert rc "Name:" "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"

### Scale replication controller frontend with current-replicas and replicas
# Pre-condition: 3 replicas
Expand Down Expand Up @@ -740,6 +746,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:" "Labels:" "CreationTimestamp:" "Conditions:" "Addresses:" "Capacity:" "Pods:"
# Describe command (resource only) should print detailed information
kube::test::describe_resource_assert nodes "Name:" "Labels:" "CreationTimestamp:" "Conditions:" "Addresses:" "Capacity:" "Pods:"

### kubectl patch update can mark node unschedulable
# Pre-condition: node is schedulable
Expand Down
5 changes: 4 additions & 1 deletion pkg/kubectl/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ $ kubectl describe pods/nginx
// Describe a pod using the data in pod.json.
$ kubectl describe -f pod.json
// Describe all pods
$ kubectl describe pods
// Describe pods by label name=myLabel
$ kubectl describe po -l name=myLabel
Expand Down Expand Up @@ -100,7 +103,7 @@ func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
NamespaceParam(cmdNamespace).DefaultNamespace().
FilenameParam(enforceNamespace, filenames...).
SelectorParam(selector).
ResourceTypeOrNameArgs(false, args...).
ResourceTypeOrNameArgs(true, args...).
Flatten().
Do()
err = r.Err()
Expand Down
19 changes: 19 additions & 0 deletions pkg/kubectl/cmd/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,22 @@ func TestDescribeObject(t *testing.T) {
t.Errorf("unexpected output: %s", buf.String())
}
}

func TestDescribeListObjects(t *testing.T) {
pods, _, _ := testData()
f, tf, codec := NewAPIFactory()
d := &testDescriber{Output: "test output"}
tf.Describer = d
tf.Client = &client.FakeRESTClient{
Codec: codec,
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, pods)},
}

tf.Namespace = "test"
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdDescribe(f, buf)
cmd.Run(cmd, []string{"pods"})
if buf.String() != fmt.Sprintf("%s\n\n%s\n\n", d.Output, d.Output) {
t.Errorf("unexpected output: %s", buf.String())
}
}

0 comments on commit 73b694e

Please sign in to comment.