discovery.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/env bash
  2. # Copyright 2018 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. run_RESTMapper_evaluation_tests() {
  19. set -o nounset
  20. set -o errexit
  21. create_and_use_new_namespace
  22. kube::log::status "Testing RESTMapper"
  23. RESTMAPPER_ERROR_FILE="${KUBE_TEMP}/restmapper-error"
  24. ### Non-existent resource type should give a recognizeable error
  25. # Pre-condition: None
  26. # Command
  27. kubectl get "${kube_flags[@]:?}" unknownresourcetype 2>"${RESTMAPPER_ERROR_FILE}" || true
  28. if grep -q "the server doesn't have a resource type" "${RESTMAPPER_ERROR_FILE}"; then
  29. kube::log::status "\"kubectl get unknownresourcetype\" returns error as expected: $(cat "${RESTMAPPER_ERROR_FILE}")"
  30. else
  31. kube::log::status "\"kubectl get unknownresourcetype\" returns unexpected error or non-error: $(cat "${RESTMAPPER_ERROR_FILE}")"
  32. exit 1
  33. fi
  34. rm "${RESTMAPPER_ERROR_FILE}"
  35. # Post-condition: None
  36. set +o nounset
  37. set +o errexit
  38. }
  39. run_assert_short_name_tests() {
  40. set -o nounset
  41. set -o errexit
  42. create_and_use_new_namespace
  43. kube::log::status "Testing assert short name"
  44. kube::log::status "Testing propagation of short names for resources"
  45. output_message=$(kubectl get --raw=/api/v1)
  46. ## test if a short name is exported during discovery
  47. kube::test::if_has_string "${output_message}" '{"name":"configmaps","singularName":"","namespaced":true,"kind":"ConfigMap","verbs":\["create","delete","deletecollection","get","list","patch","update","watch"\],"shortNames":\["cm"\],"storageVersionHash":'
  48. set +o nounset
  49. set +o errexit
  50. }
  51. run_assert_categories_tests() {
  52. set -o nounset
  53. set -o errexit
  54. kube::log::status "Testing propagation of categories for resources"
  55. output_message=$(kubectl get --raw=/api/v1 | grep -o '"name":"pods"[^}]*}')
  56. kube::test::if_has_string "${output_message}" '"categories":\["all"\]'
  57. set +o nounset
  58. set +o errexit
  59. }
  60. run_resource_aliasing_tests() {
  61. set -o nounset
  62. set -o errexit
  63. create_and_use_new_namespace
  64. kube::log::status "Testing resource aliasing"
  65. kubectl create -f test/e2e/testing-manifests/statefulset/cassandra/controller.yaml "${kube_flags[@]}"
  66. kubectl create -f test/e2e/testing-manifests/statefulset/cassandra/service.yaml "${kube_flags[@]}"
  67. object="all -l'app=cassandra'"
  68. request="{{range.items}}{{range .metadata.labels}}{{.}}:{{end}}{{end}}"
  69. # all 4 cassandra's might not be in the request immediately...
  70. # first option with :: suffix is for possible service.kubernetes.io/headless
  71. # label with "" value
  72. kube::test::get_object_assert "$object" "$request" 'cassandra:cassandra:cassandra:cassandra::' || \
  73. kube::test::get_object_assert "$object" "$request" 'cassandra:cassandra:cassandra:cassandra:' || \
  74. kube::test::get_object_assert "$object" "$request" 'cassandra:cassandra:cassandra:' || \
  75. kube::test::get_object_assert "$object" "$request" 'cassandra:cassandra:'
  76. kubectl delete all -l app=cassandra "${kube_flags[@]}"
  77. set +o nounset
  78. set +o errexit
  79. }
  80. run_kubectl_explain_tests() {
  81. set -o nounset
  82. set -o errexit
  83. kube::log::status "Testing kubectl(v1:explain)"
  84. kubectl explain pods
  85. # shortcuts work
  86. kubectl explain po
  87. kubectl explain po.status.message
  88. # cronjob work
  89. kubectl explain cronjob
  90. set +o nounset
  91. set +o errexit
  92. }
  93. run_swagger_tests() {
  94. set -o nounset
  95. set -o errexit
  96. kube::log::status "Testing swagger"
  97. # Verify schema
  98. file="${KUBE_TEMP}/schema.json"
  99. curl -s "http://127.0.0.1:${API_PORT}/openapi/v2" > "${file}"
  100. grep -q "list of returned" "${file}"
  101. grep -q "List of services" "${file}"
  102. grep -q "Watch for changes to the described resources" "${file}"
  103. set +o nounset
  104. set +o errexit
  105. }