-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
226 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
get_current_cm_key_value() { | ||
local name=$1 | ||
local namespace=$2 | ||
local key=$3 | ||
|
||
kubectl get configmaps "$name" -n "$namespace" -o jsonpath="{.data.$key}" | tr -d '[]' | ||
} | ||
|
||
update_cm_key_value() { | ||
local name=$1 | ||
local namespace=$2 | ||
local key=$3 | ||
local new_value=$4 | ||
|
||
kubectl patch configmap "$name" -n "$namespace" --type strategic -p "{\"data\":{\"$key\":\"$new_value\"}}" | ||
} | ||
|
||
get_cm_key_new_value() { | ||
local cur=$1 | ||
local replicas=$2 | ||
|
||
if [[ -z "$cur" ]]; then | ||
echo "[$replicas]" | ||
else | ||
IFS=',' read -ra array <<< "$cur" | ||
last=${array[-1]} | ||
if [[ "$last" == "$replicas" ]]; then | ||
echo "[$cur]" | ||
else | ||
echo "[$cur,$replicas]" | ||
fi | ||
fi | ||
} | ||
|
||
update_configmap() { | ||
local name="$MINIO_COMPONENT_NAME-minio-configuration" | ||
local namespace="$CLUSTER_NAMESPACE" | ||
local key="MINIO_REPLICAS_HISTORY" | ||
local replicas="$MINIO_COMP_REPLICAS" | ||
|
||
cur=$(get_current_cm_key_value "$name" "$namespace" "$key") | ||
new=$(get_cm_key_new_value "$cur" "$replicas") | ||
|
||
update_cm_key_value "$name" "$namespace" "$key" "$new" | ||
echo "ConfigMap $name updated successfully with $key=$new" | ||
} | ||
|
||
# This is magic for shellspec ut framework. | ||
# Sometime, functions are defined in a single shell script. | ||
# You will want to test it. but you do not want to run the script. | ||
# When included from shellspec, __SOURCED__ variable defined and script | ||
# end here. The script path is assigned to the __SOURCED__ variable. | ||
${__SOURCED__:+false} : || return 0 | ||
|
||
# main | ||
update_configmap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/bin/bash | ||
|
||
replicas_history_file="/minio-config/MINIO_REPLICAS_HISTORY" | ||
bucket_dir="/data" | ||
|
||
init_buckets() { | ||
local buckets=$1 | ||
IFS=',' read -ra BUCKET_ARRAY <<< "$buckets" | ||
for bucket in "${BUCKET_ARRAY[@]}"; do | ||
directory="$bucket_dir/$bucket" | ||
if mkdir -p "$directory"; then | ||
echo "Successfully init bucket: $directory" | ||
else | ||
echo "Failed to init bucket: $directory" | ||
fi | ||
done | ||
} | ||
|
||
read_replicas_history() { | ||
local file=$1 | ||
content=$(cat "$file") | ||
content=$(echo "$content" | tr -d '[]') | ||
IFS=',' read -r -a replicas <<< "$content" | ||
echo "${replicas[@]}" | ||
} | ||
|
||
generate_server_pool() { | ||
local replicas=("$@") | ||
local server="" | ||
for ((i=0; i < ${#replicas[@]}; i++)); do | ||
if [ $i -eq 0 ]; then | ||
cur=${replicas[i]} | ||
server+=" $HTTP_PROTOCOL://$MINIO_COMPONENT_NAME-{0...$((cur-1))}.$MINIO_COMPONENT_NAME-headless.$CLUSTER_NAMESPACE.svc.$CLUSTER_DOMAIN/data" | ||
else | ||
prev=${replicas[i-1]} | ||
cur=${replicas[i]} | ||
server+=" $HTTP_PROTOCOL://$MINIO_COMPONENT_NAME-{$((prev))...$((cur-1))}.$MINIO_COMPONENT_NAME-headless.$CLUSTER_NAMESPACE.svc.$CLUSTER_DOMAIN/data" | ||
fi | ||
done | ||
echo "$server" | ||
} | ||
|
||
startup() { | ||
if [ ! -f "$replicas_history_file" ]; then | ||
echo "minio config don't existed" | ||
exit 1 | ||
fi | ||
|
||
buckets="$MINIO_BUCKETS" | ||
if [ -n "$buckets" ]; then | ||
init_buckets "$buckets" | ||
fi | ||
|
||
mapfile -t replicas < <(read_replicas_history "$replicas_history_file") | ||
server=$(generate_server_pool "${replicas[@]}") | ||
echo "the minio server pool is $server" | ||
|
||
cmd="/usr/bin/docker-entrypoint.sh minio server $server -S $CERTS_PATH --address :$MINIO_API_PORT --console-address :$MINIO_CONSOLE_PORT" | ||
echo "Starting minio server with command: $cmd" | ||
eval "$cmd" | ||
} | ||
|
||
# This is magic for shellspec ut framework. | ||
# Sometime, functions are defined in a single shell script. | ||
# You will want to test it. but you do not want to run the script. | ||
# When included from shellspec, __SOURCED__ variable defined and script | ||
# end here. The script path is assigned to the __SOURCED__ variable. | ||
${__SOURCED__:+false} : || return 0 | ||
|
||
# main | ||
startup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.