Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions scripts/dev/contexts/funcs/gke
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Function to normalize identifier to contain only alphanumeric characters.
# It's also cutting the string in the middle if exceeds max_len.
# Example:
# normalize_identifier "mongodb_kubernetes_1.4.0_68c913f767d52d00076a2698" 25 -> mongodb-kubex2d00076a2698
normalize_identifier() {
local str=$1
local max_len=$(($2 - 1))

# Convert to lowercase and replace invalid characters with hyphens
str=$(echo -n "${str}" | tr '[:upper:]_' '[:lower:]-' | sed 's/[^a-z0-9-]/-/g')
# Ensure it ends with alphanumeric

# Truncate to ${max_len} chars by cutting from middle
if [[ ${#str} -gt ${max_len} ]]; then
half_idx=$((max_len / 2))
local start_part="${str:0:${half_idx}}"
local end_part="${str: -${half_idx}}"
str="${start_part}x${end_part}"
fi

[[ ${str} =~ -$ ]] && str="${str}0"
echo -n "${str}"
}

# for prerelease tag builds we have:
# version_id=mongodb_kubernetes_1.4.0_68c913f767d52d00076a2698-9041 (len=54)
# k8s cluster name prefix: k8s-mdb-0- (len=10)
# random suffix: -1234 (len=5)
# K8S_CLUSTER_PREFIX must be shorter than 25 to make the final
# gke identifier shorter than 40 characters.
create_k8s_cluster_suffix() {
echo -n "$(normalize_identifier "${K8S_CLUSTER_SUFFIX:-"-${version_id}-${RANDOM}"}" 25)"
}
5 changes: 4 additions & 1 deletion scripts/dev/contexts/prerelease_gke_code_snippets
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ script_name=$(readlink -f "${BASH_SOURCE[0]}")
script_dir=$(dirname "${script_name}")

source "${script_dir}/root-context"
source "${script_dir}/funcs/gke"
K8S_CLUSTER_SUFFIX="$(create_k8s_cluster_suffix)"
export K8S_CLUSTER_SUFFIX

export MDB_GKE_PROJECT="scratch-kubernetes-team"
export K8S_CLUSTER_SUFFIX="${K8S_CLUSTER_SUFFIX:-"-${version_id}-${RANDOM}"}"

export CODE_SNIPPETS_COMMIT_OUTPUT=true

# we reset evg host to use a default ~/.kube/config for GKE instead of the one from evg host
Expand Down
5 changes: 4 additions & 1 deletion scripts/dev/contexts/private_gke_code_snippets
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ script_dir=$(dirname "${script_name}")
source "${script_dir}/root-context"
source "${script_dir}/variables/om80"

source "${script_dir}/funcs/gke"
K8S_CLUSTER_SUFFIX="$(create_k8s_cluster_suffix)"
export K8S_CLUSTER_SUFFIX

export KUBE_ENVIRONMENT_NAME=multi

export MDB_GKE_PROJECT="scratch-kubernetes-team"
export K8S_CLUSTER_SUFFIX="${K8S_CLUSTER_SUFFIX:-"-${version_id}-${RANDOM}"}"

# we reset evg host to use a default ~/.kube/config for GKE instead of the one from evg host
export EVG_HOST_NAME=""
Expand Down
6 changes: 4 additions & 2 deletions scripts/dev/contexts/public_gke_code_snippets
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ script_dir=$(dirname "${script_name}")

source "${script_dir}/root-context"

source "${script_dir}/funcs/gke"
K8S_CLUSTER_SUFFIX="$(create_k8s_cluster_suffix)"
export K8S_CLUSTER_SUFFIX

export KUBE_ENVIRONMENT_NAME=multi

export MDB_GKE_PROJECT="scratch-kubernetes-team"
# shellcheck disable=SC2154
export K8S_CLUSTER_SUFFIX="${K8S_CLUSTER_SUFFIX:-"-${version_id}-${RANDOM}"}"

# we reset evg host to use a default ~/.kube/config for GKE instead of the one from evg host
export EVG_HOST_NAME=""
Expand Down
2 changes: 1 addition & 1 deletion scripts/evergreen/setup_gcloud_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -Eeou pipefail
source scripts/dev/set_env_context.sh

curl -s --retry 3 -LO "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz"
tar xvf google-cloud-cli-linux-x86_64.tar.gz -C "${workdir}"
tar xf google-cloud-cli-linux-x86_64.tar.gz -C "${workdir}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this saves >10k lines from persisting to the job log

"${workdir}"/google-cloud-sdk/install.sh --quiet
source "${workdir}/google-cloud-sdk/path.bash.inc"

Expand Down
Loading