k8s.io/perf-tests/clusterloader2@v0.0.0-20240304094227-64bdb12da87e/run-e2e.sh (about) 1 #!/bin/bash 2 3 # Copyright 2018 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 CLUSTERLOADER_ROOT=$(dirname "${BASH_SOURCE[0]}") 22 export KUBECONFIG="${KUBECONFIG:-${HOME}/.kube/config}" 23 # "${HOME}/.kube/config" always (both in kubemark and non-kubemark) points to "real"/root cluster. 24 # TODO: eventually we need to move to use cloud-provider-gcp to bring up cluster which have pdcsi by default 25 export CSI_DRIVER_KUBECONFIG="${HOME}/.kube/config" 26 export KUBEMARK_ROOT_KUBECONFIG="${KUBEMARK_ROOT_KUBECONFIG:-${HOME}/.kube/config}" 27 28 export AZUREDISK_CSI_DRIVER_VERSION="${AZUREDISK_CSI_DRIVER_VERSION:-master}" 29 export AZUREDISK_CSI_DRIVER_INSTALL_URL="${AZUREDISK_CSI_DRIVER_INSTALL_URL:-https://raw.githubusercontent.com/kubernetes-sigs/azuredisk-csi-driver/${AZUREDISK_CSI_DRIVER_VERSION}/deploy/install-driver.sh}" 30 export WINDOWS_USE_HOST_PROCESS_CONTAINERS=true 31 32 # Deploy the GCE PD CSI Driver if required 33 if [[ "${DEPLOY_GCI_DRIVER:-false}" == "true" ]]; then 34 if [[ -n "${E2E_GOOGLE_APPLICATION_CREDENTIALS:-}" ]]; then 35 kubectl --kubeconfig "${CSI_DRIVER_KUBECONFIG}" apply -f "${CLUSTERLOADER_ROOT}"/drivers/gcp-csi-driver-stable.yaml 36 kubectl --kubeconfig "${CSI_DRIVER_KUBECONFIG}" create secret generic cloud-sa --from-file=cloud-sa.json="${E2E_GOOGLE_APPLICATION_CREDENTIALS:-}" -n gce-pd-csi-driver 37 else 38 echo "Env var E2E_GOOGLE_APPLICATION_CREDENTIALS is unset." 39 echo "Falling back to using Application Default Credentials for GCE PD CSI driver deployment." 40 if [[ ! -x "$(command -v yq)" ]]; then 41 echo "yq must be installed to set up GCE PD CSI Driver with Application Default Credentials." 42 echo "Please install this tool from https://github.com/mikefarah/yq." 43 exit 1 44 fi 45 # Running yq to patch GCE PD CSI Driver manifests so that it runs using 46 # Application Default Credentials instead of creating service account 47 # keys, hence avoiding security risks. See 48 # https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/pull/610 49 # for more details. 50 tmpfile="$(mktemp /tmp/gcp-csi-driver-stable.XXXXXX.yaml)" 51 yq eval ' 52 with(select(.metadata.name == "csi-gce-pd-controller" and .kind == "Deployment").spec.template.spec; 53 del(.volumes[] | select(.name == "cloud-sa-volume")) | 54 with(.containers[] | select(.name == "gce-pd-driver"); 55 del(.env[] | select(.name == "GOOGLE_APPLICATION_CREDENTIALS")) | 56 del(.volumeMounts[] | select(.name == "cloud-sa-volume")) 57 ) 58 )' "${CLUSTERLOADER_ROOT}"/drivers/gcp-csi-driver-stable.yaml > "${tmpfile}" 59 kubectl --kubeconfig "${CSI_DRIVER_KUBECONFIG}" apply -f "${tmpfile}" 60 rm "${tmpfile}" 61 fi 62 kubectl --kubeconfig "${CSI_DRIVER_KUBECONFIG}" wait -n gce-pd-csi-driver deployment csi-gce-pd-controller --for condition=available --timeout=300s 63 64 # make sure there's a default storage class 65 names=( $(kubectl --kubeconfig "${CSI_DRIVER_KUBECONFIG}" get sc -o name) ) 66 i=0 67 for name in "${names[@]}" 68 do 69 if [[ $(kubectl --kubeconfig "${CSI_DRIVER_KUBECONFIG}" get $name -o jsonpath='{.metadata.annotations.storageclass\.kubernetes\.io/is-default-class}') = true ]]; then 70 ((i+=1)) 71 fi 72 done 73 if [[ $i < 1 ]]; then 74 kubectl --kubeconfig "${CSI_DRIVER_KUBECONFIG}" patch storageclass csi-gce-pd -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' 75 fi 76 fi 77 78 if [[ "${DEPLOY_AZURE_CSI_DRIVER:-false}" == "true" ]]; then 79 curl -skSL ${AZUREDISK_CSI_DRIVER_INSTALL_URL} | bash -s ${AZUREDISK_CSI_DRIVER_VERSION} snapshot -- 80 fi 81 82 # Create a dedicated service account for cluster-loader. 83 cluster_loader_sa_exists=$(kubectl --kubeconfig "${KUBECONFIG}" get serviceaccount cluster-loader --ignore-not-found | wc -l) 84 if [[ "$cluster_loader_sa_exists" -eq 0 ]]; then 85 kubectl --kubeconfig "${KUBECONFIG}" create serviceaccount cluster-loader 86 fi 87 cluster_loader_crb_exists=$(kubectl --kubeconfig "${KUBECONFIG}" get clusterrolebinding cluster-loader --ignore-not-found | wc -l) 88 if [[ "$cluster_loader_crb_exists" -eq 0 ]]; then 89 kubectl --kubeconfig "${KUBECONFIG}" create clusterrolebinding cluster-loader --clusterrole=cluster-admin --serviceaccount=default:cluster-loader 90 fi 91 cluster_loader_secret_exists=$(kubectl --kubeconfig "${KUBECONFIG}" get secret cluster-loader --ignore-not-found | wc -l) 92 if [[ "$cluster_loader_secret_exists" -eq 0 ]]; then 93 cat << EOF | kubectl --kubeconfig "${KUBECONFIG}" create -f - 94 apiVersion: v1 95 kind: Secret 96 metadata: 97 name: cluster-loader 98 namespace: default 99 annotations: 100 kubernetes.io/service-account.name: cluster-loader 101 type: kubernetes.io/service-account-token 102 EOF 103 fi 104 105 106 # Create a kubeconfig to use the above service account. 107 kubeconfig=$(mktemp) 108 server=$(kubectl --kubeconfig "${KUBECONFIG}" config view -o jsonpath='{.clusters[0].cluster.server}') 109 ca=$(kubectl --kubeconfig "${KUBECONFIG}" get secret cluster-loader -o jsonpath='{.data.ca\.crt}') 110 token=$(kubectl --kubeconfig "${KUBECONFIG}" get secret cluster-loader -o jsonpath='{.data.token}' | base64 --decode) 111 echo " 112 apiVersion: v1 113 kind: Config 114 clusters: 115 - name: default-cluster 116 cluster: 117 certificate-authority-data: ${ca} 118 server: ${server} 119 contexts: 120 - name: default-context 121 context: 122 cluster: default-cluster 123 namespace: default 124 user: default-user 125 current-context: default-context 126 users: 127 - name: default-user 128 user: 129 token: ${token} 130 " > "${kubeconfig}" 131 export KUBECONFIG=${kubeconfig} 132 133 cd "${CLUSTERLOADER_ROOT}"/ && go build -o clusterloader './cmd/' 134 ./clusterloader --alsologtostderr --v="${CL2_VERBOSITY:-2}" "$@"