You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.2 KiB

  1. #!/bin/bash
  2. set -euxo pipefail
  3. echo "CI_JOB_NAME is $CI_JOB_NAME"
  4. if [[ "$CI_JOB_NAME" =~ "upgrade" ]]; then
  5. if [ "${UPGRADE_TEST}" == "false" ]; then
  6. echo "Job name contains 'upgrade', but UPGRADE_TEST='false'"
  7. exit 1
  8. fi
  9. else
  10. if [ "${UPGRADE_TEST}" != "false" ]; then
  11. echo "UPGRADE_TEST!='false', but job names does not contain 'upgrade'"
  12. exit 1
  13. fi
  14. fi
  15. # Check out latest tag if testing upgrade
  16. if [ "${UPGRADE_TEST}" != "false" ]; then
  17. git fetch --all && git checkout "$KUBESPRAY_VERSION"
  18. # Checkout the current tests/ directory ; even when testing old version,
  19. # we want the up-to-date test setup/provisionning
  20. git checkout "${CI_COMMIT_SHA}" -- tests/
  21. fi
  22. export ANSIBLE_REMOTE_USER=$SSH_USER
  23. export ANSIBLE_BECOME=true
  24. export ANSIBLE_BECOME_USER=root
  25. export ANSIBLE_INVENTORY=${CI_PROJECT_DIR}/inventory/sample/
  26. make -C tests INVENTORY_DIR=${ANSIBLE_INVENTORY} create-${CI_PLATFORM} -s
  27. # Test collection build and install by installing our collection, emptying our repository, adding
  28. # cluster.yml, reset.yml, and remote-node.yml files that simply point to our collection's playbooks, and then
  29. # running the same tests as before
  30. if [[ "${CI_JOB_NAME}" =~ "collection" ]]; then
  31. # Build and install collection
  32. ansible-galaxy collection build
  33. ansible-galaxy collection install kubernetes_sigs-kubespray-$(grep "^version:" galaxy.yml | awk '{print $2}').tar.gz
  34. # Simply remove all of our files and directories except for our tests directory
  35. # to be absolutely certain that none of our playbooks or roles
  36. # are interfering with our collection
  37. find -mindepth 1 -maxdepth 1 ! -regex './\(tests\|inventory\)' -exec rm -rfv {} +
  38. cat > cluster.yml <<EOF
  39. - name: Install Kubernetes
  40. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.cluster
  41. EOF
  42. cat > upgrade-cluster.yml <<EOF
  43. - name: Install Kubernetes
  44. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.upgrade-cluster
  45. EOF
  46. cat > reset.yml <<EOF
  47. - name: Remove Kubernetes
  48. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.reset
  49. EOF
  50. cat > remove-node.yml <<EOF
  51. - name: Remove node from Kubernetes
  52. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.remove_node
  53. EOF
  54. fi
  55. ansible-playbook tests/cloud_playbooks/wait-for-ssh.yml
  56. run_playbook () {
  57. playbook=$1
  58. shift
  59. # We can set --limit here and still pass it as supplemental args because `--limit` is a 'last one wins' option
  60. ansible-playbook \
  61. -e @tests/common_vars.yml \
  62. -e @tests/files/${CI_JOB_NAME}.yml \
  63. -e local_release_dir=${PWD}/downloads \
  64. "$@" \
  65. ${playbook}
  66. }
  67. ## START KUBESPRAY
  68. # Create cluster
  69. run_playbook cluster.yml
  70. # Repeat deployment if testing upgrade
  71. if [ "${UPGRADE_TEST}" != "false" ]; then
  72. git checkout "${CI_COMMIT_SHA}"
  73. case "${UPGRADE_TEST}" in
  74. "basic")
  75. run_playbook cluster.yml
  76. ;;
  77. "graceful")
  78. run_playbook upgrade-cluster.yml
  79. ;;
  80. *)
  81. ;;
  82. esac
  83. fi
  84. # Test control plane recovery
  85. if [ "${RECOVER_CONTROL_PLANE_TEST}" != "false" ]; then
  86. run_playbook reset.yml --limit "${RECOVER_CONTROL_PLANE_TEST_GROUPS}" -e reset_confirmation=yes
  87. run_playbook recover-control-plane.yml -e etcd_retries=10 --limit "etcd:kube_control_plane"
  88. fi
  89. # Tests Cases
  90. ## Test Control Plane API
  91. run_playbook tests/testcases/010_check-apiserver.yml
  92. run_playbook tests/testcases/015_check-nodes-ready.yml
  93. ## Test that all nodes are Ready
  94. if [[ ! ( "$CI_JOB_NAME" =~ "macvlan" ) ]]; then
  95. run_playbook tests/testcases/020_check-pods-running.yml
  96. run_playbook tests/testcases/030_check-network.yml
  97. if [[ ! ( "$CI_JOB_NAME" =~ "hardening" ) ]]; then
  98. # TODO: We need to remove this condition by finding alternative container
  99. # image instead of netchecker which doesn't work at hardening environments.
  100. run_playbook tests/testcases/040_check-network-adv.yml
  101. fi
  102. fi
  103. ## Kubernetes conformance tests
  104. run_playbook tests/testcases/100_check-k8s-conformance.yml
  105. # Test node removal procedure
  106. if [ "${REMOVE_NODE_CHECK}" = "true" ]; then
  107. run_playbook remove-node.yml -e skip_confirmation=yes -e node=${REMOVE_NODE_NAME}
  108. fi
  109. # Clean up at the end, this is to allow stage1 tests to include cleanup test
  110. if [ "${RESET_CHECK}" = "true" ]; then
  111. run_playbook reset.yml -e reset_confirmation=yes
  112. fi