Skip to content

Commit 9f4b191

Browse files
committed
Normalize GKE identifiers in snippets
1 parent 4fa6b0e commit 9f4b191

File tree

1 file changed

+11
-8
lines changed
  • scripts/dev/contexts/funcs

1 file changed

+11
-8
lines changed

scripts/dev/contexts/funcs/gke

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Function to normalize identifier for K8s naming requirements
1+
# Function to normalize identifier to contain only alphanumeric characters.
2+
# It's also cutting the string in the middle if exceeds max_len.
3+
# Example:
4+
# normalize_identifier "mongodb_kubernetes_1.4.0_68c913f767d52d00076a2698" 25 -> mongodb-kubex2d00076a2698
25
normalize_identifier() {
36
local str=$1
47
local max_len=$(($2 - 1))
@@ -9,7 +12,7 @@ normalize_identifier() {
912

1013
# Truncate to ${max_len} chars by cutting from middle
1114
if [[ ${#str} -gt ${max_len} ]]; then
12-
half_idx=$((max_len / 2 - 1))
15+
half_idx=$((max_len / 2))
1316
local start_part="${str:0:${half_idx}}"
1417
local end_part="${str: -${half_idx}}"
1518
str="${start_part}x${end_part}"
@@ -19,12 +22,12 @@ normalize_identifier() {
1922
echo -n "${str}"
2023
}
2124

22-
# for prerelease builds we have:
25+
# for prerelease tag builds we have:
2326
# version_id=mongodb_kubernetes_1.4.0_68c913f767d52d00076a2698-9041 (len=54)
24-
# k8s cluster name prefix is: k8s-mdb-0- (len=10)
25-
# K8S_CLUSTER_PREFIX must be shorter than 30 to make the final
26-
# gke identifier shorter than 40 characters
27+
# k8s cluster name prefix: k8s-mdb-0- (len=10)
28+
# random suffix: -1234 (len=5)
29+
# K8S_CLUSTER_PREFIX must be shorter than 25 to make the final
30+
# gke identifier shorter than 40 characters.
2731
create_k8s_cluster_suffix() {
28-
echo -n "$(normalize_identifier "${K8S_CLUSTER_SUFFIX:-"-${version_id}-${RANDOM}"}" 28)"
32+
echo -n "$(normalize_identifier "${K8S_CLUSTER_SUFFIX:-"-${version_id}-${RANDOM}"}" 25)"
2933
}
30-

0 commit comments

Comments
 (0)