util.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env bash
  2. # Copyright 2017 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. # This script contains the helper functions that each provider hosting
  16. # Kubermark must implement to use test/kubemark/start-kubemark.sh and
  17. # test/kubemark/stop-kubemark.sh scripts.
  18. # This function should authenticate docker to be able to read/write to
  19. # the right container registry (needed for pushing kubemark image).
  20. function authenticate-docker {
  21. echo "Configuring registry authentication" 1>&2
  22. }
  23. # This function should get master IP address (creating one if needed).
  24. # ENV vars that should be defined by the end of this function:
  25. # - MASTER_IP
  26. #
  27. # Recommended for this function to include retrying logic in case of failures.
  28. function get-or-create-master-ip {
  29. echo "MASTER_IP: $MASTER_IP" 1>&2
  30. }
  31. # This function should create a machine instance for the master along
  32. # with any/all of the following resources:
  33. # - Attach a PD to the master (optionally 1 more for storing events)
  34. # - A public IP address for the master ($MASTER_IP)
  35. # - A network firewall rule allowing all TCP traffic on port 443 in master
  36. # Note: This step is compulsory in order for kubemark to work
  37. #
  38. # ENV vars that should be defined by the end of this function:
  39. # - MASTER_NAME
  40. #
  41. # Recommended for this function to include retrying logic for the above
  42. # operations in case of failures.
  43. function create-master-instance-with-resources {
  44. echo "MASTER_IP: $MASTER_IP" 1>&2
  45. echo "MASTER_NAME: $MASTER_NAME" 1>&2
  46. }
  47. # This function should execute the command('$1') on the master machine
  48. # (possibly through SSH), retrying in case of failure. The allowed number of
  49. # retries would be '$2' (if not provided, default to single try).
  50. function execute-cmd-on-master-with-retries() {
  51. echo "Executing command on the master" 1>&2
  52. }
  53. # This function should act as an scp for the kubemark cluster, which copies
  54. # the files given by the first n-1 arguments to the remote location given
  55. # by the n^th argument.
  56. #
  57. # Recommended for this function to include retrying logic in case of failures.
  58. function copy-files() {
  59. echo "Copying files" 1>&2
  60. }
  61. # This function should delete the master instance along with all the
  62. # resources that have been allocated inside the function
  63. # 'create-master-instance-with-resources' above.
  64. #
  65. # Recommended for this function to include retrying logic in case of failures.
  66. function delete-master-instance-and-resources {
  67. echo "Deleting master instance and its allocated resources" 1>&2
  68. }
  69. # Common colors used throughout the kubemark scripts
  70. if [[ -z "${color_start-}" ]]; then
  71. declare -r color_start="\033["
  72. # shellcheck disable=SC2034
  73. declare -r color_red="${color_start}0;31m"
  74. # shellcheck disable=SC2034
  75. declare -r color_yellow="${color_start}0;33m"
  76. # shellcheck disable=SC2034
  77. declare -r color_green="${color_start}0;32m"
  78. # shellcheck disable=SC2034
  79. declare -r color_blue="${color_start}1;34m"
  80. # shellcheck disable=SC2034
  81. declare -r color_cyan="${color_start}1;36m"
  82. # shellcheck disable=SC2034
  83. declare -r color_norm="${color_start}0m"
  84. fi