Skip to content

Commit

Permalink
feat: replace weka_cluster_size var by using asg min_size
Browse files Browse the repository at this point in the history
  • Loading branch information
kristina-solovyova committed Dec 21, 2023
1 parent 3a8a9d6 commit 7b56d53
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 32 deletions.
1 change: 0 additions & 1 deletion clients.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module "clients" {
frontend_container_cores_num = var.clients_use_dpdk ? var.client_frontend_cores : 1
instance_type = var.client_instance_type
backends_asg_name = aws_autoscaling_group.autoscaling_group.name
weka_cluster_size = var.cluster_size
alb_dns_name = var.create_alb ? aws_lb.alb[0].dns_name : null
key_pair_name = var.key_pair_name != null ? var.key_pair_name : aws_key_pair.generated_key[0].key_name
assign_public_ip = var.assign_public_ip
Expand Down
2 changes: 1 addition & 1 deletion modules/clients/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ No modules.
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | Id of the subnet | `string` | n/a | yes |
| <a name="input_tags_map"></a> [tags\_map](#input\_tags\_map) | A map of tags to assign the same metadata to all resources in the environment. Format: key:value. | `map(string)` | <pre>{<br> "creator": "tf",<br> "env": "dev"<br>}</pre> | no |
| <a name="input_use_autoscaling_group"></a> [use\_autoscaling\_group](#input\_use\_autoscaling\_group) | Use autoscaling group | `bool` | `false` | no |
| <a name="input_weka_cluster_size"></a> [weka\_cluster\_size](#input\_weka\_cluster\_size) | Number of backends in the weka cluster | `number` | `0` | no |
| <a name="input_weka_cluster_size"></a> [weka\_cluster\_size](#input\_weka\_cluster\_size) | [Deprecated] Number of backends in the weka cluster | `number` | `0` | no |
| <a name="input_weka_volume_size"></a> [weka\_volume\_size](#input\_weka\_volume\_size) | The root volume size in GB | `number` | `48` | no |

## Outputs
Expand Down
8 changes: 1 addition & 7 deletions modules/clients/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ locals {

mount_wekafs_script = templatefile("${path.module}/mount_wekafs.sh", {
frontend_container_cores_num = var.frontend_container_cores_num
weka_cluster_size = var.weka_cluster_size
backends_asg_name = var.backends_asg_name
clients_use_dpdk = var.clients_use_dpdk
region = local.region
Expand Down Expand Up @@ -114,12 +113,7 @@ resource "aws_launch_template" "this" {
}
}
user_data = local.custom_data
lifecycle {
precondition {
condition = var.alb_dns_name == null ? var.weka_cluster_size > 0 : true
error_message = "Please povide weka_cluster size in case of not using ALB"
}
}

depends_on = [aws_placement_group.this]
}

Expand Down
10 changes: 6 additions & 4 deletions modules/clients/mount_wekafs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ if [ -z "${alb_dns_name}" ]; then
# Function to get the private IPs of instances in Auto Scaling Group
get_private_ips() {
instance_ids=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name "${backends_asg_name}" --query "AutoScalingGroups[].Instances[].InstanceId" --output text --region ${region})
cluster_min_size=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name "${backends_asg_name}" --query "AutoScalingGroups[].MinSize" --output text --region ${region})
private_ips=$(aws ec2 describe-instances --instance-ids $instance_ids --query "Reservations[].Instances[].PrivateIpAddress" --output text --region ${region})
private_ips_array=($private_ips)
}

# Retry until the length of the array is not 'weka_cluster_size'
# Retry until the length of the array is not the same as the cluster min size
while true; do
get_private_ips
length=$${#private_ips_array[@]}
# if the length >= weka_cluster_size , break out of the loop
if [ $length -ge ${weka_cluster_size} ]; then
expected_length=$${cluster_min_size}
# if the length >= expected_length , break out of the loop
if [ $length -ge $expected_length ]; then
break
fi
# sleep for a while (optional) and retry
echo "Waiting for all backend instances to be up... $length/${weka_cluster_size}"
echo "Waiting for all backend instances to be up... $length/$expected_length"
sleep 5
done

Expand Down
4 changes: 2 additions & 2 deletions modules/clients/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ variable "subnet_id" {
description = "Id of the subnet"
}

variable "weka_cluster_size" {
variable "weka_cluster_size" { # tflint-ignore: terraform_unused_declarations
type = number
description = "Number of backends in the weka cluster"
description = "[Deprecated] Number of backends in the weka cluster"
default = 0
}

Expand Down
2 changes: 1 addition & 1 deletion modules/protocol_gateways/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ No modules.
| <a name="input_smbw_enabled"></a> [smbw\_enabled](#input\_smbw\_enabled) | Enable SMBW protocol. | `bool` | `false` | no |
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | subnet id | `string` | n/a | yes |
| <a name="input_tags_map"></a> [tags\_map](#input\_tags\_map) | A map of tags to assign the same metadata to all resources in the environment. Format: key:value. | `map(string)` | <pre>{<br> "creator": "tf",<br> "env": "dev"<br>}</pre> | no |
| <a name="input_weka_cluster_size"></a> [weka\_cluster\_size](#input\_weka\_cluster\_size) | Number of backends in the weka cluster | `number` | `0` | no |
| <a name="input_weka_cluster_size"></a> [weka\_cluster\_size](#input\_weka\_cluster\_size) | [Deprecated] Number of backends in the weka cluster | `number` | `0` | no |
| <a name="input_weka_password_id"></a> [weka\_password\_id](#input\_weka\_password\_id) | Weka password id | `string` | n/a | yes |
| <a name="input_weka_token_id"></a> [weka\_token\_id](#input\_weka\_token\_id) | Weka token id | `string` | n/a | yes |
| <a name="input_weka_volume_size"></a> [weka\_volume\_size](#input\_weka\_volume\_size) | The disk size. | `number` | n/a | yes |
Expand Down
10 changes: 6 additions & 4 deletions modules/protocol_gateways/deploy_protocol_gateways.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@ if [ -z "${lb_arn_suffix}" ]; then
# Function to get the private IPs of instances in Auto Scaling Group
get_private_ips() {
instance_ids=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name "${backends_asg_name}" --query "AutoScalingGroups[].Instances[].InstanceId" --output text --region ${region})
cluster_min_size=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name "${backends_asg_name}" --query "AutoScalingGroups[].MinSize" --output text --region ${region})
private_ips=$(aws ec2 describe-instances --instance-ids $instance_ids --query "Reservations[].Instances[].PrivateIpAddress" --output text --region ${region})
private_ips_array=($private_ips)
}

# Retry until the length of the array is not 'weka_cluster_size'
# Retry until the length of the array is not the same as the cluster min size
while true; do
get_private_ips
length=$${#private_ips_array[@]}
# if the length >= weka_cluster_size , break out of the loop
if [ $length -ge ${weka_cluster_size} ]; then
expected_length=$${cluster_min_size}
# if the length >= expected_length , break out of the loop
if [ $length -ge $expected_length ]; then
break
fi
# sleep for a while (optional) and retry
echo "Waiting for all backend instances to be up... $length/${weka_cluster_size}"
echo "Waiting for all backend instances to be up... $length/$expected_length"
sleep 5
done

Expand Down
8 changes: 0 additions & 8 deletions modules/protocol_gateways/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ locals {
subnet_prefixes = data.aws_subnet.selected.cidr_block
frontend_container_cores_num = var.frontend_container_cores_num
secondary_ips_per_nic = var.secondary_ips_per_nic
weka_cluster_size = var.weka_cluster_size
backends_asg_name = var.backends_asg_name
region = local.region
weka_password_id = var.weka_password_id
Expand Down Expand Up @@ -145,13 +144,6 @@ resource "aws_launch_template" "this" {
}
user_data = base64encode(local.custom_data)

lifecycle {
precondition {
condition = var.lb_arn_suffix == null ? var.weka_cluster_size > 0 : true
error_message = "Please povide weka_cluster size in case of not using LB"
}
}

depends_on = [aws_placement_group.this]
}

Expand Down
4 changes: 2 additions & 2 deletions modules/protocol_gateways/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ variable "key_pair_name" {
description = "Ssh key pair name to pass to the instances."
}

variable "weka_cluster_size" {
variable "weka_cluster_size" { # tflint-ignore: terraform_unused_declarations
type = number
description = "Number of backends in the weka cluster"
description = "[Deprecated] Number of backends in the weka cluster"
default = 0
}

Expand Down
2 changes: 0 additions & 2 deletions protocol_gateways.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module "smb_protocol_gateways" {
lb_arn_suffix = var.create_alb ? aws_lb.alb[0].arn_suffix : ""
backends_asg_name = aws_autoscaling_group.autoscaling_group.name
instance_type = var.smb_protocol_gateway_instance_type
weka_cluster_size = var.cluster_size
key_pair_name = var.key_pair_name != null ? var.key_pair_name : aws_key_pair.generated_key[0].key_name
assign_public_ip = var.assign_public_ip
placement_group_name = local.backends_placement_group_name
Expand Down Expand Up @@ -46,7 +45,6 @@ module "nfs_protocol_gateways" {
lb_arn_suffix = var.create_alb ? aws_lb.alb[0].arn_suffix : ""
backends_asg_name = aws_autoscaling_group.autoscaling_group.name
instance_type = var.nfs_protocol_gateway_instance_type
weka_cluster_size = var.cluster_size
key_pair_name = var.key_pair_name != null ? var.key_pair_name : aws_key_pair.generated_key[0].key_name
assign_public_ip = var.assign_public_ip
placement_group_name = local.backends_placement_group_name
Expand Down

0 comments on commit 7b56d53

Please sign in to comment.