github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/tests/suites/ck/ck.sh (about) 1 # Ensure that Charmed Kubernetes deploys successfully, and that we can 2 # create storage on the cluster using kubectl after it's deployed. 3 run_deploy_ck() { 4 echo 5 6 local name model_name file overlay_path overlay_url kube_home 7 name="deploy-ck" 8 model_name="${name}" 9 file="${TEST_DIR}/${model_name}.log" 10 11 ensure "${model_name}" "${file}" 12 13 case "${BOOTSTRAP_PROVIDER:-}" in 14 "ec2") 15 overlay_url="https://raw.githubusercontent.com/charmed-kubernetes/bundle/main/overlays/aws-storage-overlay.yaml" 16 ;; 17 "gce") 18 overlay_url="https://raw.githubusercontent.com/charmed-kubernetes/bundle/main/overlays/gcp-storage-overlay.yaml" 19 ;; 20 "azure") 21 overlay_url="https://raw.githubusercontent.com/charmed-kubernetes/bundle/main/overlays/azure-cloud-overlay.yaml" 22 ;; 23 *) 24 echo "Unexpected bootstrap provider (${BOOTSTRAP_PROVIDER})." 25 exit 1 26 ;; 27 esac 28 29 overlay_path="${TEST_DIR}/overlay.yaml" 30 wget "${overlay_url}" -O "${overlay_path}" 31 juju deploy charmed-kubernetes --overlay "${overlay_path}" --overlay "./tests/suites/ck/overlay.yaml" --trust 32 33 if ! which "kubectl" >/dev/null 2>&1; then 34 sudo snap install kubectl --classic --channel latest/stable 35 fi 36 37 wait_for "active" '.applications["kubernetes-control-plane"] | ."application-status".current' 1800 38 wait_for "active" '.applications["kubernetes-worker"] | ."application-status".current' 39 40 case "${BOOTSTRAP_PROVIDER:-}" in 41 "ec2") 42 wait_for "active" '.applications["aws-integrator"] | ."application-status".current' 43 wait_for "active" '.applications["aws-k8s-storage"] | ."application-status".current' 44 ;; 45 "gce") 46 wait_for "active" '.applications["gcp-integrator"] | ."application-status".current' 47 wait_for "active" '.applications["gcp-k8s-storage"] | ."application-status".current' 48 ;; 49 "azure") 50 wait_for "active" '.applications["azure-integrator"] | ."application-status".current' 51 wait_for "active" '.applications["azure-cloud-provider"] | ."application-status".current' 52 ;; 53 *) 54 echo "Unexpected bootstrap provider (${BOOTSTRAP_PROVIDER})." 55 exit 1 56 ;; 57 esac 58 59 kube_home="${HOME}/.kube" 60 mkdir -p "${kube_home}" 61 juju scp kubernetes-control-plane/0:config "${kube_home}/config" 62 63 kubectl cluster-info 64 kubectl get ns 65 66 # The model teardown could take too long time, so we decided to kill controller to speed up test run time. 67 # But this will not give the chance for integrator charm to do proper cleanup: 68 # - https://github.com/juju-solutions/charm-aws-integrator/blob/master/lib/charms/layer/aws.py#L616 69 # - especially the tag cleanup: https://github.com/juju-solutions/charm-aws-integrator/blob/master/lib/charms/layer/aws.py#L616 70 # This will leave the tags created by the integrater charm on subnets forever. 71 # And on AWS, the maximum number of tags per resource is 50. 72 # Then we will get `Error while granting requests (TagLimitExceeded); check credentials and debug-log` error in next test run. 73 # So we purge the subnet tags here in advance as a workaround. 74 integrator_app_name=$(cat "$overlay_path" | yq '.applications | keys | .[] | select(.== "*integrator")') 75 juju --show-log run "$integrator_app_name/leader" --wait=10m purge-subnet-tags 76 } 77 78 # Ensure that a CAAS workload deploys successfully, 79 # and that we can relate the two applications once it has. 80 run_deploy_caas_workload() { 81 echo 82 83 local name k8s_cloud_name model_name file storage controller_name 84 85 name="deploy-caas-workload" 86 k8s_cloud_name="k8s-cloud" 87 88 case "${BOOTSTRAP_PROVIDER:-}" in 89 "ec2") 90 storage="csi-aws-ebs-default" 91 ;; 92 "gce") 93 storage="gce-pd-csi-driver" 94 ;; 95 "azure") 96 storage="csi-azure-default" 97 ;; 98 *) 99 echo "Unexpected bootstrap provider (${BOOTSTRAP_PROVIDER})." 100 exit 1 101 ;; 102 esac 103 104 model_name="test-${name}" 105 file="${TEST_DIR}/${model_name}.log" 106 107 controller_name=$(juju controllers --format json | jq -r '.controllers | keys[0]') 108 juju add-k8s "${k8s_cloud_name}" --storage "${storage}" --controller "${controller_name}" 2>&1 | OUTPUT "${file}" 109 110 juju_add_model "${model_name}" "${k8s_cloud_name}" "${controller_name}" "${file}" 111 112 juju deploy snappass-test 113 114 wait_for "snappass-test" "$(idle_condition "snappass-test" 0)" 115 116 destroy_model "${model_name}" 117 } 118 119 test_deploy_ck() { 120 if [ "$(skip 'test_deploy_ck')" ]; then 121 echo "==> TEST SKIPPED: Test Deploy CK" 122 return 123 fi 124 125 ( 126 set_verbosity 127 cd .. || exit 128 129 run "run_deploy_ck" 130 run "run_deploy_caas_workload" 131 ) 132 }