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
2
5
normalize_identifier() {
3
6
local str=$1
4
7
local max_len=$(($2 - 1))
@@ -9,7 +12,7 @@ normalize_identifier() {
9
12
10
13
# Truncate to ${max_len} chars by cutting from middle
11
14
if [[ ${#str} -gt ${max_len} ]]; then
12
- half_idx=$((max_len / 2 - 1 ))
15
+ half_idx=$((max_len / 2))
13
16
local start_part="${str:0:${half_idx}}"
14
17
local end_part="${str: -${half_idx}}"
15
18
str="${start_part}x${end_part}"
@@ -19,12 +22,12 @@ normalize_identifier() {
19
22
echo -n "${str}"
20
23
}
21
24
22
- # for prerelease builds we have:
25
+ # for prerelease tag builds we have:
23
26
# 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.
27
31
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 )"
29
33
}
30
-
0 commit comments