Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update function_app_dist-setting workflow to make changes on PR #169

Open
wants to merge 27 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4edab29
chore: init dev branch: update dist to dev
assafgi Jun 26, 2023
f19729c
feat: add frontend option
Jun 20, 2023
a9f26cd
terraform-docs: automated action
github-actions[bot] Jun 27, 2023
1778167
chore: update function_app_version
denise89p Jun 27, 2023
4990813
feat: add create client module
Jun 27, 2023
9537f5b
terraform-docs: automated action
github-actions[bot] Jul 4, 2023
7515a2e
fix: add condition on create client ips
Jul 5, 2023
5f552a4
chore: move status, state and report protocols to go cloud lib
assafgi Jul 4, 2023
b92f073
terraform-docs: automated action
github-actions[bot] Jul 5, 2023
7d39537
chore: support using provided placement group id
assafgi Jul 20, 2023
f74bfa9
fix: clients vmss nics setup
assafgi Jul 20, 2023
1f8621b
terraform-docs: automated action
github-actions[bot] Jul 20, 2023
7ecf9c8
chore: improve output: move to json automation readable format
assafgi Jul 25, 2023
a708fc6
terraform-docs: automated action
github-actions[bot] Jul 25, 2023
73504df
chore: move to EP1 sku service plan
assafgi Jul 26, 2023
f0aea72
chore: allow using existing subnet delegation
assafgi Jul 26, 2023
d10155f
terraform-docs: automated action
github-actions[bot] Jul 26, 2023
04cd9d1
feat: change blob permission according to creation or using existing …
Jul 5, 2023
547228d
terraform-docs: automated action
github-actions[bot] Jul 27, 2023
5856474
feat: add protocol gateways, nfs setup
kristina-solovyova Jul 28, 2023
ec1b65b
terraform-docs: automated action
github-actions[bot] Jul 28, 2023
b1192b5
fix: deletion protection reporting
assafgi Jul 28, 2023
0adf90d
fix: remove protect call from deploy script due to authorization not …
assafgi Aug 1, 2023
be73d9a
terraform-docs: automated action
github-actions[bot] Aug 1, 2023
0c7868c
chore: update function_app_version
assafgi Aug 3, 2023
d099383
feat: update function_app_dist-setting workflow to make changes on PR
kristina-solovyova Aug 3, 2023
c0d38ea
terraform-docs: automated action
github-actions[bot] Aug 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Push to main branch
name: Update function_app_dist

on:
push:
pull_request:
branches:
- main
- dev

jobs:
update_function_app_dist:
Expand All @@ -16,8 +17,13 @@ jobs:
uses: actions/checkout@v2

- name: Update function_app_dist default to 'release'
if: github.event.pull_request.base.ref == 'main'
run: sed -i 's/^\( *default =\) "dev"/\1 "release"/' variables.tf

- name: Update function_app_dist default to 'dev'
if: github.event.pull_request.base.ref == 'dev'
run: sed -i 's/^\( *default =\) "release"/\1 "dev"/' variables.tf

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand Down
84 changes: 71 additions & 13 deletions README.md

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions blob.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "azurerm_storage_account" "deployment_sa" {
count = var.deployment_storage_account_name == "" ? 1 : 0
name = "${local.alphanumeric_prefix_name}${local.alphanumeric_cluster_name}deployment"
location = data.azurerm_resource_group.rg.location
resource_group_name = var.rg_name
Expand All @@ -12,16 +13,17 @@ resource "azurerm_storage_account" "deployment_sa" {
}

resource "azurerm_storage_container" "deployment" {
count = var.deployment_container_name == "" ? 1 : 0
name = "${local.alphanumeric_prefix_name}${local.alphanumeric_cluster_name}-deployment"
storage_account_name = azurerm_storage_account.deployment_sa.name
storage_account_name = local.deployment_storage_account_name
container_access_type = "private"
depends_on = [azurerm_storage_account.deployment_sa]
}

resource "azurerm_storage_blob" "state" {
name = "state"
storage_account_name = azurerm_storage_account.deployment_sa.name
storage_container_name = azurerm_storage_container.deployment.name
storage_account_name = local.deployment_storage_account_name
storage_container_name = local.deployment_container_name
type = "Block"
source_content = "{\"initial_size\":${var.cluster_size}, \"desired_size\":${var.cluster_size}, \"instances\":[], \"clusterized\":false}"
depends_on = [azurerm_storage_container.deployment]
Expand All @@ -30,3 +32,15 @@ resource "azurerm_storage_blob" "state" {
ignore_changes = all
}
}

data azurerm_storage_account "deployment_blob" {
count = var.deployment_storage_account_name != "" ? 1 : 0
name = var.deployment_storage_account_name
resource_group_name = var.rg_name
}

data "azurerm_storage_account" "obs_sa" {
count = var.obs_name != "" ? 1 : 0
name = var.obs_name
resource_group_name = var.rg_name
}
49 changes: 49 additions & 0 deletions clients.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resource "null_resource" "get-backend-ip" {
count = var.clients_number > 0 ? 1 : 0
triggers = {
always_run = timestamp()
}
provisioner "local-exec" {
command = "az vmss nic list -g ${var.rg_name} --vmss-name ${azurerm_linux_virtual_machine_scale_set.vmss.name} --subscription ${var.subscription_id} --query \"[].ipConfigurations[]\" | jq -r '.[] | select(.name==\"ipconfig0\")'.privateIPAddress > ${path.root}/backend_ips"
}
depends_on = [azurerm_linux_virtual_machine_scale_set.vmss]
}

data "local_file" "backend_ips" {
count = var.clients_number > 0 ? 1 : 0
filename = "${path.root}/backend_ips"
depends_on = [null_resource.get-backend-ip]
}

module "clients" {
count = var.clients_number > 0 ? 1 : 0
source = "./modules/clients"
rg_name = var.rg_name
clients_name = "${var.prefix}-${var.cluster_name}-client"
clients_number = var.clients_number
mount_clients_dpdk = var.mount_clients_dpdk
subnet_name = var.subnet_name
apt_repo_url = var.apt_repo_url
vnet_name = var.vnet_name
nics = var.mount_clients_dpdk ? var.client_nics_num : 1
instance_type = var.client_instance_type
backend_ips = [replace(join(" ",[data.local_file.backend_ips[0].content]), "\n", " ")]
ssh_public_key = var.ssh_public_key == null ? tls_private_key.ssh_key[0].public_key_openssh : var.ssh_public_key
ppg_id = local.placement_group_id
assign_public_ip = var.private_network ? false : true
vnet_rg_name = var.vnet_rg_name
source_image_id = var.source_image_id
sg_id = var.sg_id
depends_on = [azurerm_proximity_placement_group.ppg]
}

resource "null_resource" "clean" {
count = var.clients_number > 0 ? 1 : 0
triggers = {
always_run = timestamp()
}
provisioner "local-exec" {
command = "rm -f ${path.root}/backend_ips"
}
depends_on = [module.clients]
}
2 changes: 1 addition & 1 deletion examples/existing_private_network/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "get-cluster-helpers-commands" {
value = module.deploy-weka.cluster_helpers_commands
value = module.deploy-weka
}
2 changes: 1 addition & 1 deletion examples/existing_private_network_with_peering/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "get-cluster-helpers-commands" {
value = module.deploy-weka.cluster_helpers_commands
value = module.deploy-weka
}
1 change: 1 addition & 0 deletions examples/public_network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ No resources.
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix for all resources | `string` | n/a | yes |
| <a name="input_rg_name"></a> [rg\_name](#input\_rg\_name) | Name of existing resource group | `string` | n/a | yes |
| <a name="input_set_obs_integration"></a> [set\_obs\_integration](#input\_set\_obs\_integration) | Should be true to enable OBS integration with weka cluster | `bool` | n/a | yes |
| <a name="input_sg_ssh_range"></a> [sg\_ssh\_range](#input\_sg\_ssh\_range) | A list of IP addresses that can use ssh connection with a public network deployment. | `list(string)` | `[]` | no |
| <a name="input_subnet_delegation"></a> [subnet\_delegation](#input\_subnet\_delegation) | Subnet delegation enables you to designate a specific subnet for an Azure PaaS service | `string` | n/a | yes |
| <a name="input_subnet_prefixes"></a> [subnet\_prefixes](#input\_subnet\_prefixes) | Address prefixes to use for the subnet | `string` | n/a | yes |
| <a name="input_subscription_id"></a> [subscription\_id](#input\_subscription\_id) | Subscription id for deployment | `string` | n/a | yes |
Expand Down
1 change: 1 addition & 0 deletions examples/public_network/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module "create-network" {
rg_name = var.rg_name
address_space = var.address_space
subnet_prefixes = var.subnet_prefixes
sg_ssh_range = var.sg_ssh_range
}

module "deploy-weka" {
Expand Down
2 changes: 1 addition & 1 deletion examples/public_network/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "get-cluster-helpers-commands" {
value = module.deploy-weka.cluster_helpers_commands
value = module.deploy-weka
}
8 changes: 7 additions & 1 deletion examples/public_network/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ variable "tiering_ssd_percent" {
variable "cluster_size" {
type = number
description = "Weka cluster size"
}
}

variable "sg_ssh_range" {
type = list(string)
description = "A list of IP addresses that can use ssh connection with a public network deployment."
default = []
}
3 changes: 2 additions & 1 deletion examples/public_network/vars.auto.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ cluster_name = "poc"
instance_type = "Standard_L8s_v3"
set_obs_integration = true
tiering_ssd_percent = 20
cluster_size = 6
cluster_size = 6
sg_ssh_range = ["0.0.0.0/0"]
1 change: 1 addition & 0 deletions examples/public_network_with_existing_obs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ No resources.
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix for all resources | `string` | n/a | yes |
| <a name="input_rg_name"></a> [rg\_name](#input\_rg\_name) | Name of existing resource group | `string` | n/a | yes |
| <a name="input_set_obs_integration"></a> [set\_obs\_integration](#input\_set\_obs\_integration) | Should be true to enable OBS integration with weka cluster | `bool` | n/a | yes |
| <a name="input_sg_ssh_range"></a> [sg\_ssh\_range](#input\_sg\_ssh\_range) | A list of IP addresses that can use ssh connection with a public network deployment. | `list(string)` | `[]` | no |
| <a name="input_subnet_delegation"></a> [subnet\_delegation](#input\_subnet\_delegation) | Subnet delegation enables you to designate a specific subnet for an Azure PaaS service | `string` | n/a | yes |
| <a name="input_subnet_prefixes"></a> [subnet\_prefixes](#input\_subnet\_prefixes) | Address prefixes to use for the subnet | `string` | n/a | yes |
| <a name="input_subscription_id"></a> [subscription\_id](#input\_subscription\_id) | Subscription id for deployment | `string` | n/a | yes |
Expand Down
1 change: 1 addition & 0 deletions examples/public_network_with_existing_obs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module "create-network" {
rg_name = var.rg_name
address_space = var.address_space
subnet_prefixes = var.subnet_prefixes
sg_ssh_range = var.sg_ssh_range
}

module "deploy-weka" {
Expand Down
2 changes: 1 addition & 1 deletion examples/public_network_with_existing_obs/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "get-cluster-helpers-commands" {
value = module.deploy-weka.cluster_helpers_commands
value = module.deploy-weka
}
8 changes: 7 additions & 1 deletion examples/public_network_with_existing_obs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ variable "blob_obs_access_key" {
type = string
description = "Access key of existing blob obs container"
sensitive = true
}
}

variable "sg_ssh_range" {
type = list(string)
description = "A list of IP addresses that can use ssh connection with a public network deployment."
default = []
}
3 changes: 2 additions & 1 deletion examples/public_network_with_existing_obs/vars.auto.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ obs_name = "obs-blob"
obs_container_name = "obs-container"
blob_obs_access_key = ""
tiering_ssd_percent = 20
cluster_size = 6
cluster_size = 6
sg_ssh_range = ["0.0.0.0/0"]
67 changes: 28 additions & 39 deletions function-app/code/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/weka/go-cloud-lib/lib/types"
"github.com/weka/go-cloud-lib/logging"
"github.com/weka/go-cloud-lib/protocol"
reportLib "github.com/weka/go-cloud-lib/report"
)

type InvokeRequest struct {
Expand All @@ -34,14 +35,13 @@ type InvokeResponse struct {
ReturnValue interface{}
}

type ClusterState struct {
InitialSize int `json:"initial_size"`
DesiredSize int `json:"desired_size"`
Progress map[string][]string `json:"progress"`
Errors map[string][]string `json:"errors"`
Instances []string `json:"instances"`
Clusterized bool `json:"clusterized"`
}
const FindDrivesScript = `
import json
import sys
for d in json.load(sys.stdin)['disks']:
if d['isRotational']: continue
print(d['devPath'])
`

func leaseContainer(ctx context.Context, subscriptionId, resourceGroupName, storageAccountName, containerName string, leaseIdIn *string, action armstorage.LeaseContainerRequestAction) (leaseIdOut *string, err error) {
logger := logging.LoggerFromCtx(ctx)
Expand Down Expand Up @@ -129,7 +129,7 @@ func ReadBlobObject(ctx context.Context, stateStorageName, containerName, blobNa

}

func ReadState(ctx context.Context, stateStorageName, containerName string) (state ClusterState, err error) {
func ReadState(ctx context.Context, stateStorageName, containerName string) (state protocol.ClusterState, err error) {
logger := logging.LoggerFromCtx(ctx)

stateAsByteArray, err := ReadBlobObject(ctx, stateStorageName, containerName, "state")
Expand Down Expand Up @@ -166,7 +166,7 @@ func WriteBlobObject(ctx context.Context, stateStorageName, containerName, blobN

}

func WriteState(ctx context.Context, stateStorageName, containerName string, state ClusterState) (err error) {
func WriteState(ctx context.Context, stateStorageName, containerName string, state protocol.ClusterState) (err error) {
logger := logging.LoggerFromCtx(ctx)

stateAsByteArray, err := json.Marshal(state)
Expand All @@ -191,7 +191,7 @@ func (e *ShutdownRequired) Error() string {
return e.Message
}

func AddInstanceToState(ctx context.Context, subscriptionId, resourceGroupName, stateStorageName, stateContainerName, newInstance string) (state ClusterState, err error) {
func AddInstanceToState(ctx context.Context, subscriptionId, resourceGroupName, stateStorageName, stateContainerName, newInstance string) (state protocol.ClusterState, err error) {
logger := logging.LoggerFromCtx(ctx)

leaseId, err := LockContainer(ctx, subscriptionId, resourceGroupName, stateStorageName, stateContainerName)
Expand Down Expand Up @@ -229,7 +229,7 @@ func AddInstanceToState(ctx context.Context, subscriptionId, resourceGroupName,
return
}

func UpdateClusterized(ctx context.Context, subscriptionId, resourceGroupName, stateStorageName, stateContainerName string) (state ClusterState, err error) {
func UpdateClusterized(ctx context.Context, subscriptionId, resourceGroupName, stateStorageName, stateContainerName string) (state protocol.ClusterState, err error) {
logger := logging.LoggerFromCtx(ctx)

leaseId, err := LockContainer(ctx, subscriptionId, resourceGroupName, stateStorageName, stateContainerName)
Expand Down Expand Up @@ -835,12 +835,19 @@ func RetrySetDeletionProtectionAndReport(

if protectionErr, ok := err.(*azcore.ResponseError); ok && protectionErr.ErrorCode == "AuthorizationFailed" {
counter++
// deletion protection invoked by terminate function
if maxAttempts == 0 {
msg := fmt.Sprintf("Deletion protection set authorization isn't ready, will retry on next scale down workflow")
ReportMsg(ctx, hostName, subscriptionId, resourceGroupName, stateContainerName, stateStorageName, "debug", msg)
return
}

if counter > maxAttempts {
break
}
msg := fmt.Sprintf("Setting deletion protection authorization error, going to sleep for %dM", sleepInterval)
msg := fmt.Sprintf("Deletion protection set authorization isn't ready, going to sleep for %s", sleepInterval)
logger.Info().Msg(msg)
ReportMsg(ctx, hostName, subscriptionId, resourceGroupName, stateContainerName, stateStorageName, "progress", msg)
ReportMsg(ctx, hostName, subscriptionId, resourceGroupName, stateContainerName, stateStorageName, "debug", msg)
time.Sleep(sleepInterval)
} else {
break
Expand All @@ -854,7 +861,7 @@ func RetrySetDeletionProtectionAndReport(
}

func ReportMsg(ctx context.Context, hostName, subscriptionId, resourceGroupName, stateContainerName, stateStorageName, reportType, message string) {
reportObj := Report{Type: reportType, Hostname: hostName, Message: message}
reportObj := protocol.Report{Type: reportType, Hostname: hostName, Message: message}
_ = UpdateStateReporting(ctx, subscriptionId, resourceGroupName, stateContainerName, stateStorageName, reportObj)
}

Expand Down Expand Up @@ -944,13 +951,7 @@ func TerminateScaleSetInstances(ctx context.Context, subscriptionId, resourceGro
return
}

type Report struct {
Type string `json:"type"`
Message string `json:"message"`
Hostname string `json:"hostname"`
}

func UpdateStateReporting(ctx context.Context, subscriptionId, resourceGroupName, stateContainerName, stateStorageName string, report Report) (err error) {
func UpdateStateReporting(ctx context.Context, subscriptionId, resourceGroupName, stateContainerName, stateStorageName string, report protocol.Report) (err error) {
logger := logging.LoggerFromCtx(ctx)

leaseId, err := LockContainer(ctx, subscriptionId, resourceGroupName, stateStorageName, stateContainerName)
Expand All @@ -970,31 +971,19 @@ func UpdateStateReporting(ctx context.Context, subscriptionId, resourceGroupName
return
}

func UpdateStateReportingWithoutLocking(ctx context.Context, stateContainerName, stateStorageName string, report Report) (err error) {
func UpdateStateReportingWithoutLocking(ctx context.Context, stateContainerName, stateStorageName string, report protocol.Report) (err error) {
state, err := ReadState(ctx, stateStorageName, stateContainerName)
if err != nil {
return
}
currentTime := time.Now().UTC().Format("15:04:05") + " UTC"
switch report.Type {
case "error":
if state.Errors == nil {
state.Errors = make(map[string][]string)
}
state.Errors[report.Hostname] = append(state.Errors[report.Hostname], fmt.Sprintf("%s: %s", currentTime, report.Message))
case "progress":
if state.Progress == nil {
state.Progress = make(map[string][]string)
}
state.Progress[report.Hostname] = append(state.Progress[report.Hostname], fmt.Sprintf("%s: %s", currentTime, report.Message))
default:
err = fmt.Errorf("invalid type: %s", report.Type)
err = reportLib.UpdateReport(report, &state)
if err != nil {
err = fmt.Errorf("failed updating state report")
return
}

err = WriteState(ctx, stateStorageName, stateContainerName, state)
if err != nil {
err = fmt.Errorf("failed updating state errors")
err = fmt.Errorf("failed updating state report")
return
}
return
Expand Down
Loading