mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
kubectl describe <kind> work with no arguments
Add describe_resource_assert to test describe <kind> with no object arg
This commit is contained in:
parent
2bfa9a1f98
commit
73b694e6c1
@ -159,6 +159,9 @@ $ kubectl describe pods/nginx
|
|||||||
// Describe a pod using the data in pod.json.
|
// Describe a pod using the data in pod.json.
|
||||||
$ kubectl describe \-f pod.json
|
$ kubectl describe \-f pod.json
|
||||||
|
|
||||||
|
// Describe all pods
|
||||||
|
$ kubectl describe pods
|
||||||
|
|
||||||
// Describe pods by label name=myLabel
|
// Describe pods by label name=myLabel
|
||||||
$ kubectl describe po \-l name=myLabel
|
$ kubectl describe po \-l name=myLabel
|
||||||
|
|
||||||
|
@ -69,6 +69,9 @@ $ kubectl describe pods/nginx
|
|||||||
// Describe a pod using the data in pod.json.
|
// Describe a pod using the data in pod.json.
|
||||||
$ kubectl describe -f pod.json
|
$ kubectl describe -f pod.json
|
||||||
|
|
||||||
|
// Describe all pods
|
||||||
|
$ kubectl describe pods
|
||||||
|
|
||||||
// Describe pods by label name=myLabel
|
// Describe pods by label name=myLabel
|
||||||
$ kubectl describe po -l name=myLabel
|
$ kubectl describe po -l name=myLabel
|
||||||
|
|
||||||
@ -118,7 +121,7 @@ $ kubectl describe pods frontend
|
|||||||
|
|
||||||
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
|
* [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 -->
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||||
[]()
|
[]()
|
||||||
|
@ -79,3 +79,31 @@ kube::test::describe_object_assert() {
|
|||||||
echo -n ${reset}
|
echo -n ${reset}
|
||||||
return 0
|
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
|
||||||
|
}
|
||||||
|
@ -236,6 +236,8 @@ runTests() {
|
|||||||
kube::test::get_object_assert 'pods/valid-pod' "{{$id_field}}" 'valid-pod'
|
kube::test::get_object_assert 'pods/valid-pod' "{{$id_field}}" 'valid-pod'
|
||||||
# Describe command should print detailed information
|
# Describe command should print detailed information
|
||||||
kube::test::describe_object_assert pods 'valid-pod' "Name:" "Image(s):" "Node:" "Labels:" "Status:" "Replication Controllers"
|
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
|
### Dump current valid-pod POD
|
||||||
output_pod=$(kubectl get pod valid-pod -o yaml --output-version=v1 "${kube_flags[@]}")
|
output_pod=$(kubectl get pod valid-pod -o yaml --output-version=v1 "${kube_flags[@]}")
|
||||||
@ -493,6 +495,8 @@ runTests() {
|
|||||||
kube::test::get_object_assert services "{{range.items}}{{$id_field}}:{{end}}" 'kubernetes:redis-master:'
|
kube::test::get_object_assert services "{{range.items}}{{$id_field}}:{{end}}" 'kubernetes:redis-master:'
|
||||||
# Describe command should print detailed information
|
# Describe command should print detailed information
|
||||||
kube::test::describe_object_assert services 'redis-master' "Name:" "Labels:" "Selector:" "IP:" "Port:" "Endpoints:" "Session Affinity:"
|
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
|
### Dump current redis-master service
|
||||||
output_service=$(kubectl get service redis-master -o json --output-version=v1 "${kube_flags[@]}")
|
output_service=$(kubectl get service redis-master -o json --output-version=v1 "${kube_flags[@]}")
|
||||||
@ -592,6 +596,8 @@ __EOF__
|
|||||||
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'
|
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'
|
||||||
# Describe command should print detailed information
|
# Describe command should print detailed information
|
||||||
kube::test::describe_object_assert rc 'frontend' "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"
|
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
|
### Scale replication controller frontend with current-replicas and replicas
|
||||||
# Pre-condition: 3 replicas
|
# Pre-condition: 3 replicas
|
||||||
@ -740,6 +746,8 @@ __EOF__
|
|||||||
kube::test::get_object_assert nodes "{{range.items}}{{$id_field}}:{{end}}" '127.0.0.1:'
|
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:"
|
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
|
### kubectl patch update can mark node unschedulable
|
||||||
# Pre-condition: node is schedulable
|
# Pre-condition: node is schedulable
|
||||||
|
@ -56,6 +56,9 @@ $ kubectl describe pods/nginx
|
|||||||
// Describe a pod using the data in pod.json.
|
// Describe a pod using the data in pod.json.
|
||||||
$ kubectl describe -f pod.json
|
$ kubectl describe -f pod.json
|
||||||
|
|
||||||
|
// Describe all pods
|
||||||
|
$ kubectl describe pods
|
||||||
|
|
||||||
// Describe pods by label name=myLabel
|
// Describe pods by label name=myLabel
|
||||||
$ kubectl describe po -l name=myLabel
|
$ kubectl describe po -l name=myLabel
|
||||||
|
|
||||||
@ -100,7 +103,7 @@ func RunDescribe(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
|
|||||||
NamespaceParam(cmdNamespace).DefaultNamespace().
|
NamespaceParam(cmdNamespace).DefaultNamespace().
|
||||||
FilenameParam(enforceNamespace, filenames...).
|
FilenameParam(enforceNamespace, filenames...).
|
||||||
SelectorParam(selector).
|
SelectorParam(selector).
|
||||||
ResourceTypeOrNameArgs(false, args...).
|
ResourceTypeOrNameArgs(true, args...).
|
||||||
Flatten().
|
Flatten().
|
||||||
Do()
|
Do()
|
||||||
err = r.Err()
|
err = r.Err()
|
||||||
|
@ -81,3 +81,22 @@ func TestDescribeObject(t *testing.T) {
|
|||||||
t.Errorf("unexpected output: %s", buf.String())
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user