old-print.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_kubectl_old_print_tests() {
  19. set -o nounset
  20. set -o errexit
  21. create_and_use_new_namespace
  22. kube::log::status "Testing kubectl get --server-print=false"
  23. ### Test retrieval of all types in discovery
  24. # Pre-condition: no resources exist
  25. output_message=$(kubectl get pods --server-print=false 2>&1 "${kube_flags[@]}")
  26. # Post-condition: Expect text indicating no resources were found
  27. kube::test::if_has_string "${output_message}" 'No resources found.'
  28. ### Test retrieval of pods against server-side printing
  29. kubectl create -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml "${kube_flags[@]}"
  30. # Post-condition: valid-pod POD is created
  31. kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:'
  32. # Compare "old" output with experimental output and ensure both are the same
  33. # remove the last column, as it contains the object's AGE, which could cause a mismatch.
  34. expected_output=$(kubectl get pod "${kube_flags[@]}" | awk 'NF{NF--};1')
  35. actual_output=$(kubectl get pod --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1')
  36. kube::test::if_has_string "${actual_output}" "${expected_output}"
  37. # Test printing objects with --use-openapi-print-columns
  38. actual_output=$(kubectl get namespaces --use-openapi-print-columns --v=7 "${kube_flags[@]}" 2>&1)
  39. # it should request full objects (not server-side printing)
  40. kube::test::if_has_not_string "${actual_output}" 'application/json;as=Table'
  41. kube::test::if_has_string "${actual_output}" 'application/json'
  42. ### Test retrieval of daemonsets against server-side printing
  43. kubectl apply -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
  44. # Post-condition: daemonset is created
  45. kube::test::get_object_assert ds "{{range.items}}{{$id_field}}:{{end}}" 'bind:'
  46. # Compare "old" output with experimental output and ensure both are the same
  47. # remove the last column, as it contains the object's AGE, which could cause a mismatch.
  48. expected_output=$(kubectl get ds "${kube_flags[@]}" | awk 'NF{NF--};1')
  49. actual_output=$(kubectl get ds --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1')
  50. kube::test::if_has_string "${actual_output}" "${expected_output}"
  51. ### Test retrieval of replicationcontrollers against server-side printing
  52. kubectl create -f hack/testdata/frontend-controller.yaml "${kube_flags[@]}"
  53. # Post-condition: frontend replication controller is created
  54. kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'
  55. # Compare "old" output with experimental output and ensure both are the same
  56. # remove the last column, as it contains the object's AGE, which could cause a mismatch.
  57. expected_output=$(kubectl get rc "${kube_flags[@]}" | awk 'NF{NF--};1')
  58. actual_output=$(kubectl get rc --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1')
  59. kube::test::if_has_string "${actual_output}" "${expected_output}"
  60. ### Test retrieval of replicasets against server-side printing
  61. kubectl create -f hack/testdata/frontend-replicaset.yaml "${kube_flags[@]}"
  62. # Post-condition: frontend replica set is created
  63. kube::test::get_object_assert rs "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'
  64. # Compare "old" output with experimental output and ensure both are the same
  65. # remove the last column, as it contains the object's AGE, which could cause a mismatch.
  66. expected_output=$(kubectl get rs "${kube_flags[@]}" | awk 'NF{NF--};1')
  67. actual_output=$(kubectl get rs --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1')
  68. kube::test::if_has_string "${actual_output}" "${expected_output}"
  69. ### Test retrieval of jobs against server-side printing
  70. kubectl run pi --generator=job/v1 "--image=$IMAGE_PERL" --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(20)' "${kube_flags[@]}"
  71. # Post-Condition: assertion object exists
  72. kube::test::get_object_assert jobs "{{range.items}}{{$id_field}}:{{end}}" 'pi:'
  73. # Compare "old" output with experimental output and ensure both are the same
  74. # remove the last column, as it contains the object's AGE, which could cause a mismatch.
  75. expected_output=$(kubectl get jobs/pi "${kube_flags[@]}" | awk 'NF{NF--};1')
  76. actual_output=$(kubectl get jobs/pi --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1')
  77. kube::test::if_has_string "${actual_output}" "${expected_output}"
  78. ### Test retrieval of clusterroles against server-side printing
  79. kubectl create "${kube_flags[@]}" clusterrole sample-role --verb=* --resource=pods
  80. # Post-Condition: assertion object exists
  81. kube::test::get_object_assert clusterrole/sample-role "{{range.rules}}{{range.resources}}{{.}}:{{end}}{{end}}" 'pods:'
  82. # Compare "old" output with experimental output and ensure both are the same
  83. # remove the last column, as it contains the object's AGE, which could cause a mismatch.
  84. expected_output=$(kubectl get clusterroles/sample-role "${kube_flags[@]}" | awk 'NF{NF--};1')
  85. actual_output=$(kubectl get clusterroles/sample-role --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1')
  86. kube::test::if_has_string "${actual_output}" "${expected_output}"
  87. ### Test retrieval of crds against server-side printing
  88. kubectl "${kube_flags_with_token[@]}" create -f - << __EOF__
  89. {
  90. "kind": "CustomResourceDefinition",
  91. "apiVersion": "apiextensions.k8s.io/v1beta1",
  92. "metadata": {
  93. "name": "foos.company.com"
  94. },
  95. "spec": {
  96. "group": "company.com",
  97. "version": "v1",
  98. "scope": "Namespaced",
  99. "names": {
  100. "plural": "foos",
  101. "kind": "Foo"
  102. }
  103. }
  104. }
  105. __EOF__
  106. # Post-Condition: assertion object exists
  107. kube::test::get_object_assert customresourcedefinitions "{{range.items}}{{if eq $id_field \\\"foos.company.com\\\"}}{{$id_field}}:{{end}}{{end}}" 'foos.company.com:'
  108. # Test that we can list this new CustomResource
  109. kube::test::get_object_assert foos "{{range.items}}{{$id_field}}:{{end}}" ''
  110. # Compare "old" output with experimental output and ensure both are the same
  111. expected_output=$(kubectl get foos "${kube_flags[@]}" | awk 'NF{NF--};1')
  112. actual_output=$(kubectl get foos --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1')
  113. kube::test::if_has_string "${actual_output}" "${expected_output}"
  114. # teardown
  115. kubectl delete customresourcedefinitions/foos.company.com "${kube_flags_with_token[@]}"
  116. kubectl delete clusterroles/sample-role "${kube_flags_with_token[@]}"
  117. kubectl delete jobs pi "${kube_flags[@]}"
  118. kubectl delete rs frontend "${kube_flags[@]}"
  119. kubectl delete rc frontend "${kube_flags[@]}"
  120. kubectl delete ds bind "${kube_flags[@]}"
  121. kubectl delete pod valid-pod "${kube_flags[@]}"
  122. set +o nounset
  123. set +o errexit
  124. }