Skip to content

Commit c75ef76

Browse files
author
Denise Perez
committed
feat: add support s3 protocol
1 parent b89bc07 commit c75ef76

File tree

9 files changed

+308
-133
lines changed

9 files changed

+308
-133
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,30 @@ nfs_setup_protocol = false
220220
nfs_setup_protocol = true
221221
```
222222

223+
## S3 Protocol Gateways
224+
We support creating S3 protocol gateways that will be mounted automatically to the cluster.
225+
<br>In order to create you need to provide the number of protocol gateways instances you want (by default the number is 0),
226+
227+
*The amount of S3 protocol gateways should be at least 3.*
228+
</br>
229+
for example:
230+
```hcl
231+
s3_protocol_gateways_number = 3
232+
```
233+
This will automatically create 3 instances.
234+
<br>In addition you can supply these optional variables:
235+
```hcl
236+
s3_protocol_gateway_instance_type = "Standard_D8_v5"
237+
s3_protocol_gateway_nics_num = 2
238+
s3_protocol_gateway_disk_size = 48
239+
s3_protocol_gateway_frontend_cores_num = 1
240+
```
241+
242+
<br>In order to create stateless clients, need to set variable:
243+
```hcl
244+
s3_setup_protocol = true
245+
```
246+
223247
## SMB Protocol Gateways
224248
We support creating SMB protocol gateways that will be mounted automatically to the cluster.
225249
<br>In order to create you need to provide the number of protocol gateways instances you want (by default the number is 0),

modules/protocol_gateways/main.tf

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,25 @@ locals {
147147
key_vault_url = var.key_vault_url
148148
})
149149

150-
protocol_script = var.protocol == "NFS" ? local.setup_nfs_protocol_script : local.setup_smb_protocol_script
150+
setup_s3_protocol_script = file("${path.module}/setup_s3.sh")
151+
152+
setup_validation_script = templatefile("${path.module}/setup_validation.sh", {
153+
gateways_number = var.gateways_number
154+
gateways_name = var.gateways_name
155+
report_function_url = format("https://%s.azurewebsites.net/api/report", var.function_app_name)
156+
vault_function_app_key_name = var.vault_function_app_key_name
157+
key_vault_url = var.key_vault_url
158+
})
151159

152-
setup_protocol_script = var.setup_protocol ? local.protocol_script : ""
160+
smb_protocol_script = var.protocol == "SMB" ? local.setup_smb_protocol_script : ""
161+
s3_protocol_script = var.protocol == "S3" ? local.setup_s3_protocol_script : ""
162+
nfs_protocol_script = var.protocol == "NFS" ? local.setup_nfs_protocol_script : ""
163+
validation_script = var.setup_protocol && (var.protocol == "SMB" || var.protocol == "S3") ? local.setup_validation_script : ""
164+
165+
setup_protocol_script = var.setup_protocol ? compact([local.nfs_protocol_script, local.smb_protocol_script, local.s3_protocol_script]) : []
166+
167+
custom_data_parts = concat([local.init_script, local.deploy_script, local.validation_script], local.setup_protocol_script)
153168

154-
custom_data_parts = [
155-
local.init_script, local.deploy_script, local.setup_protocol_script
156-
]
157169
custom_data = join("\n", local.custom_data_parts)
158170

159171
gw_identity_id = var.vm_identity_name == "" ? azurerm_user_assigned_identity.this[0].id : data.azurerm_user_assigned_identity.this[0].id
@@ -199,7 +211,7 @@ resource "azurerm_linux_virtual_machine" "this" {
199211
lifecycle {
200212
ignore_changes = [tags, custom_data]
201213
precondition {
202-
condition = var.protocol == "NFS" ? var.gateways_number >= 1 : var.gateways_number >= 3 && var.gateways_number <= 8
214+
condition = var.protocol == "NFS" || var.protocol == "S3" ? var.gateways_number >= 1 : var.gateways_number >= 3 && var.gateways_number <= 8
203215
error_message = "The amount of protocol gateways should be at least 1 for NFS and at least 3 and at most 8 for SMB."
204216
}
205217
precondition {

modules/protocol_gateways/setup_s3.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
echo "$(date -u): running s3 script"
2+
3+
wait_for_weka_fs || exit 1
4+
create_config_fs || exit 1
5+
6+
# wait for weka s3 cluster to be ready in case it was created by another host
7+
not_ready_hosts=$(weka s3 cluster status | grep 'Not Ready' | wc -l)
8+
all_hosts=$(weka s3 cluster status | grep 'Host' | wc -l)
9+
10+
function check_cluster_status() {
11+
if (( all_hosts > 0 && not_ready_hosts == 0 && all_hosts == cluster_size )); then
12+
echo "$(date -u): s3 cluster is already created"
13+
weka s3 cluster status
14+
exit 0
15+
fi
16+
}
17+
18+
echo "$(date -u): weka S3 cluster does not exist, creating it"
19+
# get all protocol gateways frontend container ids separated by comma
20+
all_container_ids_str=$(echo "$all_container_ids" | tr '\n' ',' | sed 's/,$//')
21+
22+
function retry_create_s3_cluster {
23+
retry_max=60
24+
retry_sleep=30
25+
count=$retry_max
26+
msg="S3 cluster is created"
27+
check_cluster_status
28+
while [ $count -gt 0 ]; do
29+
weka s3 cluster create $filesystem_name .config_fs --container $all_container_ids_str --port 9000 && break
30+
count=$(($count - 1))
31+
echo "Retrying create S3 cluster in $retry_sleep seconds..."
32+
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"progress\", \"message\": \"$msg\"}"
33+
sleep $retry_sleep
34+
check_cluster_status && break
35+
done
36+
[ $count -eq 0 ] && {
37+
echo "create S3 cluster command failed after $retry_max attempts"
38+
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"create S3 cluster command failed after $retry_max attempts\"}"
39+
echo "$(date -u): create S3 cluster failed"
40+
return 1
41+
}
42+
return 0
43+
}
44+
45+
if [[ $(weka s3 cluster status) ]]; then
46+
check_cluster_status
47+
if (( all_hosts > 0 && not_ready_hosts == 0 && all_hosts < cluster_size )); then
48+
echo "$(date -u): S3 cluster already exists, adding current container to it"
49+
weka s3 cluster containers add $container_id
50+
sleep 10s
51+
weka s3 cluster status
52+
exit 0
53+
fi
54+
else
55+
echo "$(date -u): weka S3 cluster does not exist, creating it"
56+
retry_create_s3_cluster
57+
echo "$(date -u): Successfully create S3 cluster..."
58+
weka s3 cluster status
59+
weka s3 cluster containers list
60+
echo "$(date -u): S3 cluster is created successfully"
61+
fi
62+
63+
weka s3 cluster status
64+
65+
echo "$(date -u): done running S3 script successfully"

modules/protocol_gateways/setup_smb.sh

Lines changed: 0 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,11 @@
11
echo "$(date -u): running smb script"
22
weka local ps
33

4-
# get token for key vault access
5-
access_token=$(curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fvault.azure.net' -H Metadata:true | jq -r '.access_token')
6-
# get key vault secret
7-
function_app_key=$(curl "${key_vault_url}secrets/${vault_function_app_key_name}?api-version=2016-10-01" -H "Authorization: Bearer $access_token" | jq -r '.value')
8-
9-
function report {
10-
local json_data=$1
11-
curl ${report_function_url}?code="$function_app_key" -H 'Content-Type:application/json' -d "$json_data"
12-
}
13-
14-
function wait_for_weka_fs(){
15-
filesystem_name="default"
16-
max_retries=30 # 30 * 10 = 5 minutes
17-
for (( i=0; i < max_retries; i++ )); do
18-
if [ "$(weka fs | grep -c $filesystem_name)" -ge 1 ]; then
19-
echo "$(date -u): weka filesystem $filesystem_name is up"
20-
break
21-
fi
22-
echo "$(date -u): waiting for weka filesystem $filesystem_name to be up"
23-
sleep 10
24-
done
25-
if (( i > max_retries )); then
26-
err_msg="timeout: weka filesystem $filesystem_name is not up after $max_retries attempts."
27-
echo "$(date -u): $err_msg"
28-
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}"
29-
return 1
30-
fi
31-
}
32-
33-
function create_config_fs(){
34-
filesystem_name=".config_fs"
35-
size="10GB"
36-
37-
if [ "$(weka fs | grep -c $filesystem_name)" -ge 1 ]; then
38-
echo "$(date -u): weka filesystem $filesystem_name exists"
39-
return 0
40-
fi
41-
42-
echo "$(date -u): trying to create filesystem $filesystem_name"
43-
output=$(weka fs create $filesystem_name default $size 2>&1)
44-
# possiible outputs:
45-
# FSId: 1 (means success)
46-
# error: The given filesystem ".config_fs" already exists.
47-
# error: Not enough available drive capacity for filesystem. requested "10.00 GB", but only "0 B" are free
48-
if [ $? -eq 0 ]; then
49-
echo "$(date -u): weka filesystem $filesystem_name is created"
50-
return 0
51-
fi
52-
53-
if [[ $output == *"already exists"* ]]; then
54-
echo "$(date -u): weka filesystem $filesystem_name already exists"
55-
break
56-
elif [[ $output == *"Not enough available drive capacity for filesystem"* ]]; then
57-
err_msg="Not enough available drive capacity for filesystem $filesystem_name for size $size"
58-
echo "$(date -u): $err_msg"
59-
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}"
60-
return 1
61-
else
62-
echo "$(date -u): output: $output"
63-
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"cannot create weka filesystem $filesystem_name\"}"
64-
return 1
65-
fi
66-
}
67-
684
if [[ ${smbw_enabled} == true ]]; then
695
wait_for_weka_fs || exit 1
706
create_config_fs || exit 1
717
fi
728

73-
# make sure weka cluster is already up
74-
max_retries=60
75-
for (( i=0; i < max_retries; i++ )); do
76-
if [ $(weka status | grep 'status: OK' | wc -l) -ge 1 ]; then
77-
echo "$(date -u): weka cluster is up"
78-
break
79-
fi
80-
echo "$(date -u): waiting for weka cluster to be up"
81-
sleep 30
82-
done
83-
if (( i > max_retries )); then
84-
err_msg="timeout: weka cluster is not up after $max_retries attempts."
85-
echo "$(date -u): $err_msg"
86-
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}"
87-
exit 1
88-
fi
89-
90-
cluster_size="${gateways_number}"
91-
92-
current_mngmnt_ip=$(weka local resources | grep 'Management IPs' | awk '{print $NF}')
93-
# get container id
94-
for ((i=0; i<20; i++)); do
95-
container_id=$(weka cluster container | grep frontend0 | grep ${gateways_name} | grep $current_mngmnt_ip | grep UP | awk '{print $1}')
96-
if [ -n "$container_id" ]; then
97-
echo "$(date -u): frontend0 container id: $container_id"
98-
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"progress\", \"message\": \"frontend0 container $container_id is up\"}"
99-
break
100-
fi
101-
echo "$(date -u): waiting for frontend0 container to be up"
102-
sleep 5
103-
done
104-
105-
if [ -z "$container_id" ]; then
106-
err_msg="Failed to get the frontend0 container ID."
107-
echo "$(date -u): $err_msg"
108-
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}"
109-
exit 1
110-
fi
111-
112-
# wait for all containers to be ready
113-
max_retries=60
114-
for (( retry=1; retry<=max_retries; retry++ )); do
115-
# get all UP gateway container ids
116-
all_container_ids=$(weka cluster container | grep frontend0 | grep ${gateways_name} | grep UP | awk '{print $1}')
117-
# if number of all_container_ids < cluster_size, do nothing
118-
all_container_ids_number=$(echo "$all_container_ids" | wc -l)
119-
if (( all_container_ids_number < cluster_size )); then
120-
echo "$(date -u): not all containers are ready - do retry $retry of $max_retries"
121-
sleep 20
122-
else
123-
echo "$(date -u): all containers are ready"
124-
break
125-
fi
126-
done
127-
128-
if (( retry > max_retries )); then
129-
err_msg="timeout: not all containers are ready after $max_retries attempts."
130-
echo "$(date -u): $err_msg"
131-
report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"$err_msg\"}"
132-
exit 1
133-
fi
1349

13510
# wait for weka smb cluster to be ready in case it was created by another host
13611
weka smb cluster wait

0 commit comments

Comments
 (0)