Skip to content

Commit 1887ab3

Browse files
fix: obs and private endpoints creation for disabled storage network access
1 parent bd711aa commit 1887ab3

File tree

4 files changed

+56
-33
lines changed

4 files changed

+56
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ proxy_url = VALUE
463463
| <a name="input_function_app_storage_account_prefix"></a> [function\_app\_storage\_account\_prefix](#input\_function\_app\_storage\_account\_prefix) | Weka storage account name prefix | `string` | `"weka"` | no |
464464
| <a name="input_function_app_subnet_delegation_cidr"></a> [function\_app\_subnet\_delegation\_cidr](#input\_function\_app\_subnet\_delegation\_cidr) | Subnet delegation enables you to designate a specific subnet for an Azure PaaS service. | `string` | `"10.0.1.0/25"` | no |
465465
| <a name="input_function_app_subnet_delegation_id"></a> [function\_app\_subnet\_delegation\_id](#input\_function\_app\_subnet\_delegation\_id) | Required to specify if subnet\_name were used to specify pre-defined subnets for weka. Function subnet delegation requires an additional subnet, and in the case of pre-defined networking this one also should be pre-defined | `string` | `""` | no |
466-
| <a name="input_function_app_version"></a> [function\_app\_version](#input\_function\_app\_version) | Function app code version (hash) | `string` | `"0154dfe987a700e0af9f3921aae63884"` | no |
466+
| <a name="input_function_app_version"></a> [function\_app\_version](#input\_function\_app\_version) | Function app code version (hash) | `string` | `"4eab432cb4789f37479cce953c636d10"` | no |
467467
| <a name="input_get_weka_io_token"></a> [get\_weka\_io\_token](#input\_get\_weka\_io\_token) | The token to download the Weka release from get.weka.io. | `string` | `""` | no |
468468
| <a name="input_hotspare"></a> [hotspare](#input\_hotspare) | Number of hotspares to set on weka cluster. Refer to https://docs.weka.io/overview/ssd-capacity-management#hot-spare | `number` | `1` | no |
469469
| <a name="input_install_cluster_dpdk"></a> [install\_cluster\_dpdk](#input\_install\_cluster\_dpdk) | Install weka cluster with DPDK | `bool` | `true` | no |

function-app/code/functions/clusterize/clusterize.go

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type ClusterizationParams struct {
4848
KeyVaultUri string
4949
SubnetId string
5050
PrivateDNSZoneId string
51+
// if network access is disabled and private endpoints do not exist, create them with obs
52+
CreateBlobPrivateEndpoint bool
5153

5254
StateParams common.BlobObjParams
5355
InstallDpdk bool
@@ -79,28 +81,45 @@ func GetShutdownScript() string {
7981
return dedent.Dedent(s)
8082
}
8183

82-
func CreateWekaObs(ctx context.Context, p *ClusterizationParams) (err error) {
84+
func PrepareWekaObs(ctx context.Context, p *ClusterizationParams) (err error) {
8385
logger := logging.LoggerFromCtx(ctx)
8486

85-
if p.Obs.NetworkAccess == "Disabled" && p.PrivateDNSZoneId == "" {
87+
if !p.Cluster.SetObs {
88+
return
89+
}
90+
91+
noExistingObs := p.Obs.AccessKey == ""
92+
93+
if p.Obs.NetworkAccess == "Disabled" && noExistingObs && !p.CreateBlobPrivateEndpoint {
94+
ignoredErr := fmt.Errorf("private endpoint creation is required for obs when public access is disabled")
95+
logger.Error().Err(ignoredErr).Send()
96+
97+
common.ReportMsg(ctx, p.Vm.Name, p.StateParams, "error", ignoredErr.Error())
98+
p.Cluster.SetObs = false
99+
return nil
100+
}
101+
102+
if p.Obs.NetworkAccess == "Disabled" && p.CreateBlobPrivateEndpoint && p.PrivateDNSZoneId == "" {
86103
ignoredErr := fmt.Errorf("private dns zone id is required for private endpoint creation when public access is disabled")
87104
logger.Error().Err(ignoredErr).Send()
88105

89-
logger.Info().Msg("Skipping OBS creation")
106+
common.ReportMsg(ctx, p.Vm.Name, p.StateParams, "error", ignoredErr.Error())
90107
p.Cluster.SetObs = false
91108
return nil
92109
}
93110

94-
p.Obs.AccessKey, err = common.CreateStorageAccount(
95-
ctx, p.SubscriptionId, p.ResourceGroupName, p.Location, p.Obs,
96-
)
97-
if err != nil {
98-
err = fmt.Errorf("failed to create storage account: %w", err)
99-
logger.Error().Err(err).Send()
100-
return
111+
if noExistingObs {
112+
p.Obs.AccessKey, err = common.CreateStorageAccount(
113+
ctx, p.SubscriptionId, p.ResourceGroupName, p.Location, p.Obs,
114+
)
115+
if err != nil {
116+
err = fmt.Errorf("failed to create storage account: %w", err)
117+
logger.Error().Err(err).Send()
118+
return
119+
}
101120
}
102121

103-
if p.Obs.NetworkAccess == "Disabled" {
122+
if p.Obs.NetworkAccess == "Disabled" && p.CreateBlobPrivateEndpoint {
104123
endpointName := fmt.Sprintf("%s-pe", p.Obs.Name)
105124
logger.Info().Msgf("public access is disabled for the storage account, creating private endpoint %s", endpointName)
106125

@@ -112,11 +131,13 @@ func CreateWekaObs(ctx context.Context, p *ClusterizationParams) (err error) {
112131
}
113132
}
114133

115-
err = common.CreateContainer(ctx, p.Obs.Name, p.Obs.ContainerName)
116-
if err != nil {
117-
err = fmt.Errorf("failed to create container: %w", err)
118-
logger.Error().Err(err).Send()
119-
return
134+
if noExistingObs {
135+
err = common.CreateContainer(ctx, p.Obs.Name, p.Obs.ContainerName)
136+
if err != nil {
137+
err = fmt.Errorf("failed to create container: %w", err)
138+
logger.Error().Err(err).Send()
139+
return
140+
}
120141
}
121142
return
122143
}
@@ -127,11 +148,10 @@ func HandleLastClusterVm(ctx context.Context, state protocol.ClusterState, p Clu
127148

128149
vmScaleSetName := common.GetVmScaleSetName(p.Prefix, p.Cluster.ClusterName)
129150

130-
if p.Cluster.SetObs && p.Obs.AccessKey == "" {
131-
err = CreateWekaObs(ctx, &p)
132-
if err != nil {
133-
return
134-
}
151+
err = PrepareWekaObs(ctx, &p)
152+
if err != nil {
153+
logger.Error().Err(err).Send()
154+
return
135155
}
136156

137157
logger.Info().Msg("setting weka admin password in secrets manager")
@@ -386,6 +406,7 @@ func Handler(w http.ResponseWriter, r *http.Request) {
386406
keyVaultUri := os.Getenv("KEY_VAULT_URI")
387407
subnetId := os.Getenv("SUBNET_ID")
388408
blobPrivateDnsZoneId := os.Getenv("BLOB_PRIVATE_DNS_ZONE_ID")
409+
createblobPrivateEndpoint, _ := strconv.ParseBool(os.Getenv("CREATE_BLOB_PRIVATE_ENDPOINT"))
389410
// data protection-related vars
390411
stripeWidth, _ := strconv.Atoi(os.Getenv("STRIPE_WIDTH"))
391412
protectionLevel, _ := strconv.Atoi(os.Getenv("PROTECTION_LEVEL"))
@@ -441,16 +462,17 @@ func Handler(w http.ResponseWriter, r *http.Request) {
441462
}
442463

443464
params := ClusterizationParams{
444-
SubscriptionId: subscriptionId,
445-
ResourceGroupName: resourceGroupName,
446-
Location: location,
447-
Prefix: prefix,
448-
KeyVaultUri: keyVaultUri,
449-
SubnetId: subnetId,
450-
PrivateDNSZoneId: blobPrivateDnsZoneId,
451-
StateParams: common.BlobObjParams{StorageName: stateStorageName, ContainerName: stateContainerName, BlobName: stateBlobName},
452-
Vm: vm,
453-
InstallDpdk: installDpdk,
465+
SubscriptionId: subscriptionId,
466+
ResourceGroupName: resourceGroupName,
467+
Location: location,
468+
Prefix: prefix,
469+
KeyVaultUri: keyVaultUri,
470+
SubnetId: subnetId,
471+
PrivateDNSZoneId: blobPrivateDnsZoneId,
472+
CreateBlobPrivateEndpoint: createblobPrivateEndpoint,
473+
StateParams: common.BlobObjParams{StorageName: stateStorageName, ContainerName: stateContainerName, BlobName: stateBlobName},
474+
Vm: vm,
475+
InstallDpdk: installDpdk,
454476
Cluster: clusterize.ClusterParams{
455477
ClusterizationTarget: clusterizationTarget,
456478
ClusterName: clusterName,

functions.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ locals {
140140
"SUBNET" = local.subnet_range
141141
"SUBNET_ID" = data.azurerm_subnet.subnet.id
142142
"BLOB_PRIVATE_DNS_ZONE_ID" = var.create_storage_account_private_links ? azurerm_private_dns_zone.blob[0].id : local.sa_public_access_disabled ? data.azurerm_private_dns_zone.blob[0].id : ""
143+
"CREATE_BLOB_PRIVATE_ENDPOINT" = var.create_storage_account_private_links && local.sa_public_access_disabled
143144
FUNCTION_APP_NAME = local.function_app_name
144145
PROXY_URL = var.proxy_url
145146
WEKA_HOME_URL = var.weka_home_url

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ variable "function_app_storage_account_container_prefix" {
393393
variable "function_app_version" {
394394
type = string
395395
description = "Function app code version (hash)"
396-
default = "0154dfe987a700e0af9f3921aae63884"
396+
default = "4eab432cb4789f37479cce953c636d10"
397397
}
398398

399399
variable "function_app_dist" {

0 commit comments

Comments
 (0)