Skip to content

Commit

Permalink
[PLAT-14204] Azure Provider - Allow the Resource Group for the Networ…
Browse files Browse the repository at this point in the history
…k to be overridden per Region.

Summary:
Added new optional fields for region for Azure - network resource group override and subscription id override.
These fields override that of on provider level.
Added validation for these overrides on both UI and BE level.

Test Plan:
1) Create a region with overriden resource group.
2) Edit a region and add these overrides -> verify everything is saved.
3) Pass incorrect override -> verify validation fails.
4) Create a universe with this region -> verify success

Reviewers: jmak, svarshney, #yba-api-review, sneelakantan

Reviewed By: jmak, svarshney, #yba-api-review, sneelakantan

Subscribers: sneelakantan, yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D36466
  • Loading branch information
yorq committed Jul 30, 2024
1 parent 34e6e7a commit 3104eb7
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.yugabyte.yw.models.helpers.CloudInfoInterface;
import com.yugabyte.yw.models.helpers.provider.AWSCloudInfo;
import com.yugabyte.yw.models.helpers.provider.GCPCloudInfo;
import com.yugabyte.yw.models.helpers.provider.region.AzureRegionCloudInfo;
import com.yugabyte.yw.models.helpers.provider.region.GCPRegionCloudInfo;
import io.swagger.annotations.ApiModel;
import java.util.ArrayList;
Expand Down Expand Up @@ -179,6 +180,10 @@ public static class PerRegionMetadata {
// Default: x86_64
public Architecture architecture;

public String networkRGOverride;

public String resourceGroupOverride;

public static PerRegionMetadata fromRegion(Region region) {
PerRegionMetadata perRegionMetadata = new PerRegionMetadata();
perRegionMetadata.customImageId = region.getYbImage();
Expand All @@ -192,6 +197,11 @@ public static PerRegionMetadata fromRegion(Region region) {
GCPRegionCloudInfo g = CloudInfoInterface.get(region);
perRegionMetadata.instanceTemplate = g.instanceTemplate;
}
if (region.getProviderCloudCode() == CloudType.azu) {
AzureRegionCloudInfo cloudInfo = CloudInfoInterface.get(region);
perRegionMetadata.networkRGOverride = cloudInfo.getAzuNetworkRGOverride();
perRegionMetadata.resourceGroupOverride = cloudInfo.getAzuRGOverride();
}
// perRegionMetadata.vpcCidr = never used
if (region.getZones() == null || region.getZones().size() == 0) {
perRegionMetadata.azToSubnetIds = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.yugabyte.yw.models.Region;
import com.yugabyte.yw.models.helpers.CloudInfoInterface;
import com.yugabyte.yw.models.helpers.provider.AWSCloudInfo;
import com.yugabyte.yw.models.helpers.provider.region.AzureRegionCloudInfo;
import com.yugabyte.yw.models.helpers.provider.region.GCPRegionCloudInfo;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -206,6 +207,11 @@ public Region createRegion(
vnet = queryHelper.getVnetOrFail(region);
}
region.setVnetName(vnet);
if (metadata.networkRGOverride != null || metadata.resourceGroupOverride != null) {
AzureRegionCloudInfo regionCloudInfo = CloudInfoInterface.get(region);
regionCloudInfo.setAzuNetworkRGOverride(metadata.networkRGOverride);
regionCloudInfo.setAzuRGOverride(metadata.resourceGroupOverride);
}
region.update();
if (zoneNets == null || zoneNets.size() == 0) {
zoneInfo = queryHelper.getZones(region.getUuid(), vnet);
Expand Down
7 changes: 7 additions & 0 deletions managed/src/main/java/com/yugabyte/yw/common/DevopsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.yugabyte.yw.common;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
import com.yugabyte.yw.commissioner.Common;
import com.yugabyte.yw.common.config.GlobalConfKeys;
Expand All @@ -25,6 +26,8 @@

@Slf4j
public abstract class DevopsBase {
private static final List<String> REGION_LEVEL_ALLOWED_OVERRIDES =
ImmutableList.of("AZURE_NETWORK_RG", "AZURE_RG");
public static final String YBCLOUD_SCRIPT = "bin/ybcloud.sh";
public static final String PY_WRAPPER = "bin/py_wrapper";

Expand Down Expand Up @@ -83,6 +86,10 @@ protected ShellResponse execCommand(DevopsCommand devopsCommand) {
try {
Map<String, String> envConfig = CloudInfoInterface.fetchEnvVars(region.getProvider());
extraVars.putAll(envConfig);
// In case region has overrides - put values over provider values.
Map<String, String> regionEnvConfig = CloudInfoInterface.fetchEnvVars(region);
regionEnvConfig.keySet().retainAll(REGION_LEVEL_ALLOWED_OVERRIDES);
extraVars.putAll(regionEnvConfig);
} catch (Exception e) {
throw new RuntimeException("Failed to retrieve env variables for the provider!", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ private void validateRegionDetails(
AzureCloudInfo info,
ArrayNode regionArrayJson,
SetMultimap<String, String> validationErrorsMap) {
String baseResourceGroup = resourceGroup;
try {
if (subscriptionID.equals(info.azuNetworkSubscriptionId)) {
AzureCloudInfo cloudinfo =
Expand All @@ -304,11 +305,50 @@ private void validateRegionDetails(
int regionIndex = 0;

for (Region region : provider.getRegions()) {
resourceGroup = baseResourceGroup;
AzureRegionCloudInfo regionInfo = region.getDetails().cloudInfo.azu;
JsonNode regionJson = regionArrayJson.get(regionIndex++);
JsonNode cloudInfoJson = regionJson.get("details").get("cloudInfo").get("azu");
String securityGroup = regionInfo.getSecurityGroupId();

if (regionInfo.getAzuRGOverride() != null) {
resourceGroup = regionInfo.getAzuRGOverride();
AzureCloudInfo.AzureCloudInfoBuilder cloudInfoBuilder =
info.toBuilder().azuRG(resourceGroup);
AZUResourceGroupApiClient client =
new AZUResourceGroupApiClient(cloudInfoBuilder.build());
azure = client.getAzureResourceManager();

if (!azure.resourceGroups().contain(resourceGroup)) {
String resourceGroupOverrideJsonPath =
regionJson.get("azuRGOverride").get("jsonPath").asText();
String err =
String.format(
"Resource group %s not found in Subscription %s",
resourceGroupOverrideJsonPath, subscriptionID);
validationErrorsMap.put(resourceGroupOverrideJsonPath, err);
}
}

if (regionInfo.getAzuNetworkRGOverride() != null) {
resourceGroup = regionInfo.getAzuNetworkRGOverride();
AzureCloudInfo.AzureCloudInfoBuilder cloudInfoBuilder =
info.toBuilder().azuRG(resourceGroup);
AZUResourceGroupApiClient client =
new AZUResourceGroupApiClient(cloudInfoBuilder.build());
azure = client.getAzureResourceManager();

if (!azure.resourceGroups().contain(resourceGroup)) {
String networkGroupOverrideJsonPath =
regionJson.get("azuNetworkRGOverride").get("jsonPath").asText();
String err =
String.format(
"Resource group %s not found in Subscription %s",
resourceGroup, subscriptionID);
validationErrorsMap.put(networkGroupOverrideJsonPath, err);
}
}

// verify security group exists
if (securityGroup != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

@Data
@EqualsAndHashCode(callSuper = false)
Expand All @@ -24,6 +25,14 @@ public class AzureRegionCloudInfo implements CloudInfoInterface {
@JsonAlias("sg_id")
public String securityGroupId;

@ApiModelProperty
@JsonAlias("azuNetworkRGOverride")
public String azuNetworkRGOverride;

@JsonAlias("azuRGOverride")
@ApiModelProperty
public String azuRGOverride;

@ApiModelProperty(
value =
"<b style=\"color:#ff0000\">Deprecated since YBA version 2.20.0.</b> Use"
Expand All @@ -45,6 +54,19 @@ public Map<String, String> getEnvVars() {
if (ybImage != null) {
envVars.put("ybImage", ybImage);
}
if (!StringUtils.isEmpty(azuNetworkRGOverride)) {
// This will override that setting on provider level.
envVars.put("AZURE_NETWORK_RG", azuNetworkRGOverride);
}
if (!StringUtils.isEmpty(azuRGOverride)) {
// This will override that setting on provider level.
envVars.put("AZURE_RG", azuRGOverride);
if (StringUtils.isEmpty(azuNetworkRGOverride)) {
// Setting this for network rg too, because otherwise it could take network resource group
// from provider level which will be confusing.
envVars.put("AZURE_NETWORK_RG", azuRGOverride);
}
}

return envVars;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ properties:
vnet:
description: Azure vnet
type: string
azu_network_rg_override:
description: Azure network resource group overriden at region level
type: string
rg_override:
description: Azure resource group overriden at region level
type: string
22 changes: 6 additions & 16 deletions managed/src/main/resources/swagger-strict.json
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,12 @@
},
"AzureRegionCloudInfo" : {
"properties" : {
"azuNetworkRGOverride" : {
"type" : "string"
},
"azuRGOverride" : {
"type" : "string"
},
"securityGroupId" : {
"type" : "string"
},
Expand Down Expand Up @@ -19341,14 +19347,6 @@
"in" : "query",
"name" : "request",
"required" : false
}, {
"description" : "XCluster Replication Edit Form Data",
"in" : "body",
"name" : "xcluster_replication_edit_form_data",
"required" : true,
"schema" : {
"$ref" : "#/definitions/XClusterConfigEditFormData"
}
} ],
"responses" : {
"200" : {
Expand Down Expand Up @@ -19503,14 +19501,6 @@
"in" : "query",
"name" : "request",
"required" : false
}, {
"description" : "XCluster Replication Edit Form Data",
"in" : "body",
"name" : "xcluster_replication_edit_form_data",
"required" : true,
"schema" : {
"$ref" : "#/definitions/XClusterConfigEditFormData"
}
} ],
"responses" : {
"200" : {
Expand Down
22 changes: 6 additions & 16 deletions managed/src/main/resources/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,12 @@
},
"AzureRegionCloudInfo" : {
"properties" : {
"azuNetworkRGOverride" : {
"type" : "string"
},
"azuRGOverride" : {
"type" : "string"
},
"securityGroupId" : {
"type" : "string"
},
Expand Down Expand Up @@ -19803,14 +19809,6 @@
"in" : "query",
"name" : "request",
"required" : false
}, {
"description" : "XCluster Replication Edit Form Data",
"in" : "body",
"name" : "xcluster_replication_edit_form_data",
"required" : true,
"schema" : {
"$ref" : "#/definitions/XClusterConfigEditFormData"
}
} ],
"responses" : {
"200" : {
Expand Down Expand Up @@ -19965,14 +19963,6 @@
"in" : "query",
"name" : "request",
"required" : false
}, {
"description" : "XCluster Replication Edit Form Data",
"in" : "body",
"name" : "xcluster_replication_edit_form_data",
"required" : true,
"schema" : {
"$ref" : "#/definitions/XClusterConfigEditFormData"
}
} ],
"responses" : {
"200" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,12 @@ const constructProviderPayload = async (
}),
...(regionFormValues.ybImage && {
ybImage: regionFormValues.ybImage
}),
...(regionFormValues.azuNetworkRGOverride && {
azuNetworkRGOverride: regionFormValues.azuNetworkRGOverride
}),
...(regionFormValues.azuRGOverride && {
azuRGOverride: regionFormValues.azuRGOverride
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,8 @@ const constructDefaultFormValues = (
vnet: region.details.cloudInfo.azu.vnet,
securityGroupId: region.details.cloudInfo.azu.securityGroupId,
ybImage: region.details.cloudInfo.azu.ybImage ?? '',
azuNetworkRGOverride: region.details.cloudInfo.azu.azuNetworkRGOverride ?? '',
azuRGOverride: region.details.cloudInfo.azu.azuRGOverride ?? '',
zones: region.zones
})),
sshKeypairManagement: getLatestAccessKey(providerConfig.allAccessKeys)?.keyInfo.managementState,
Expand Down Expand Up @@ -978,6 +980,12 @@ const constructProviderPayload = async (
}),
...(regionFormValues.ybImage && {
ybImage: regionFormValues.ybImage
}),
...(regionFormValues.azuNetworkRGOverride && {
azuNetworkRGOverride: regionFormValues.azuNetworkRGOverride
}),
...(regionFormValues.azuRGOverride && {
azuRGOverride: regionFormValues.azuRGOverride
})
}
}
Expand Down
Loading

0 comments on commit 3104eb7

Please sign in to comment.