Skip to content

Commit

Permalink
feat(provider/azure): Enable dns label (#3722)
Browse files Browse the repository at this point in the history
* feat(provider/azure): Enable dns label

* feat(provider/azure): Enable dns label

* feat(provider/azure): Enable dns label
  • Loading branch information
Neil Ye authored and louisjimenez committed Jun 4, 2019
1 parent bf873b9 commit 926de75
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,11 @@ class AzureNetworkClient extends AzureBaseClient {
dnsName
}

Boolean checkDnsNameAvailability(String dnsName) {
def isAvailable = azure.trafficManagerProfiles().checkDnsNameAvailability(dnsName)
isAvailable
}

/***
* The namespace for the Azure Resource Provider
* @return namespace of the resource provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ class UpsertAzureAppGatewayAtomicOperation implements AtomicOperation<Map> {
try {
task.updateStatus(BASE_PHASE, "Beginning load balancer deployment")

// Check dns name conflict
if(description.dnsName){
if(description.dnsName.isBlank()){
throw new RuntimeException("Specified dns name $description.dnsName cannot be blank")
}

def isDnsNameAvailable = description.credentials.networkClient.checkDnsNameAvailability(description.dnsName)
if(!isDnsNameAvailable){
throw new RuntimeException("Specified dns name $description.dnsName has conflict")
}
}

description.name = description.loadBalancerName
resourceGroupName = AzureUtilities.getResourceGroupName(description.appName, description.region)
virtualNetworkName = AzureUtilities.getVirtualNetworkName(resourceGroupName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AzureLoadBalancerDescription extends AzureResourceOpsDescription {
String subnet
String securityGroup
String dnsName
String publicIpName
String cluster
List<String> serverGroups
String trafficEnabledSG
Expand Down Expand Up @@ -95,6 +96,7 @@ class AzureLoadBalancerDescription extends AzureResourceOpsDescription {
description.tags.putAll(azureLoadBalancer.tags)
description.region = azureLoadBalancer.location()
description.internal = azureLoadBalancer.tags?.internal != null
description.publicIpName = AzureUtilities.getNameFromResourceId(azureLoadBalancer?.frontendIPConfigurations().first().publicIPAddress().id())

// Each load balancer backend address pool corresponds to a server group (except the "default_LB_BAP")
description.serverGroups = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,25 @@ class UpsertAzureLoadBalancerAtomicOperation implements AtomicOperation<Map> {

task.updateStatus(BASE_PHASE, "Beginning load balancer deployment")

if(description.dnsName) {
if(description.dnsName.isBlank()){
throw new RuntimeException("Specified dns name $description.dnsName cannot be blank")
}

// Check dns name conflict
def isDnsNameAvailable = description.credentials.networkClient.checkDnsNameAvailability(description.dnsName)
if (!isDnsNameAvailable) {
throw new RuntimeException("Specified dns name $description.dnsName has conflict")
}
}

description.name = description.loadBalancerName
def loadBalancerDescription = description.credentials.networkClient.getLoadBalancer(resourceGroupName, description.name)

if(loadBalancerDescription) {
description.serverGroups = loadBalancerDescription.serverGroups
description.trafficEnabledSG = loadBalancerDescription.trafficEnabledSG
description.publicIpName = loadBalancerDescription.publicIpName
}
Deployment deployment = description.credentials.resourceManagerClient.createResourceFromTemplate(
AzureLoadBalancerResourceTemplate.getTemplate(description),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ class AzureAppGatewayResourceTemplate {
AppGatewayTemplate(AzureAppGatewayDescription description) {
parameters = new AppGatewayTemplateParameters()
variables = new AppGatewayTemplateVariables(description)
if (!description.publicIpName) {
// this is not an edit operation of an existing application gateway; we must create a PublicIp resource in this case
resources.add(new PublicIpResource())
ApplicationGatewayResource appGateway = new ApplicationGatewayResource(description)

if(description.dnsName){
def publicIp = new PublicIpResource(properties: new PublicIPPropertiesWithDns())
resources.add(publicIp)
appGateway.addDependency(publicIp)
} else {
if (!description.publicIpName) {
def publicIp = new PublicIpResource()
resources.add(publicIp)
appGateway.addDependency(publicIp)
}
}
resources.add(new ApplicationGatewayResource(description))

resources.add(appGateway)
}
}

Expand Down Expand Up @@ -98,7 +108,7 @@ class AzureAppGatewayResourceTemplate {
} else {
publicIPAddressName = AzureUtilities.PUBLICIP_NAME_PREFIX + description.name.toLowerCase()
}
dnsNameForLBIP = DnsSettings.getUniqueDNSName(description.name)
dnsNameForLBIP = description.dnsName ?: DnsSettings.getUniqueDNSName(description.name)
appGwSubnetID = description.subnetResourceId
if (description.trafficEnabledSG) {
// This is an edit operation; preserve the current backend address pool as the active rule
Expand Down Expand Up @@ -130,9 +140,6 @@ class AzureAppGatewayResourceTemplate {
if (description.vnet) tags.vnet = description.vnet
if (description.subnet) tags.subnet = description.subnet
if (description.vnet) tags.vnetResourceGroup = description.vnetResourceGroup
if (!description.publicIpName) {
this.dependsOn.add("[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]")
}
properties = new ApplicationGatewayResourceProperties(description)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ class AzureLoadBalancerResourceTemplate {
LoadBalancerTemplate(AzureLoadBalancerDescription description){
parameters = new LoadBalancerParameters()
variables = new LoadBalancerTemplateVariables(description)
LoadBalancer lb = new LoadBalancer(description)

def publicIp = new PublicIpResource(properties: new PublicIPPropertiesWithDns())
publicIp.sku = new Sku("Standard")
publicIp.properties.publicIPAllocationMethod = "Static"
resources.add(publicIp)

LoadBalancer lb = new LoadBalancer(description)
lb.addDependency(resources[0])
if(description.dnsName){
resources.add(publicIp)
lb.addDependency(publicIp)
} else {
if (!description.publicIpName) {
resources.add(publicIp)
lb.addDependency(publicIp)
}
}

resources.add(lb)
}
}
Expand All @@ -76,10 +84,15 @@ class AzureLoadBalancerResourceTemplate {

loadBalancerName = description.loadBalancerName.toLowerCase()
virtualNetworkName = AzureUtilities.VNET_NAME_PREFIX + resourceGroupName.toLowerCase()
publicIPAddressName = AzureUtilities.PUBLICIP_NAME_PREFIX + description.loadBalancerName.toLowerCase()
if (description.publicIpName) {
// reuse the existing public IP (this is an edit operation)
publicIPAddressName = description.publicIpName
} else {
publicIPAddressName = AzureUtilities.PUBLICIP_NAME_PREFIX + description.loadBalancerName.toLowerCase()
}
loadBalancerFrontEnd = AzureUtilities.LBFRONTEND_NAME_PREFIX + description.loadBalancerName.toLowerCase()
loadBalancerBackEnd = description.trafficEnabledSG ? description.trafficEnabledSG : DEFAULT_BACKEND_POOL
dnsNameForLBIP = DnsSettings.getUniqueDNSName(description.loadBalancerName.toLowerCase())
dnsNameForLBIP = description.dnsName ?: DnsSettings.getUniqueDNSName(description.loadBalancerName.toLowerCase())
ipConfigName = AzureUtilities.IPCONFIG_NAME_PREFIX + description.loadBalancerName.toLowerCase()
}
}
Expand Down Expand Up @@ -259,6 +272,7 @@ class AzureLoadBalancerResourceTemplate {
String protocol
Integer frontendPort
Integer backendPort
Integer idleTimeoutInMinutes
IdRef probe
LoadDistribution loadDistribution

Expand All @@ -268,6 +282,7 @@ class AzureLoadBalancerResourceTemplate {
protocol = rule.protocol.toString().toLowerCase()
frontendPort = rule.externalPort
backendPort = rule.backendPort
idleTimeoutInMinutes = rule.idleTimeout
probe = new IdRef("[concat(variables('loadBalancerID'),'/probes/" + rule.probeName + "')]")
switch(rule.persistence) {
case "None":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class AzureAppGatewayResourceTemplateSpec extends Specification {
"subnet" : "subnet-testappgw-lb1-d1",
"vnetResourceGroup" : null
},
"dependsOn" : [ "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]" ],
"dependsOn" : [ "[concat('Microsoft.Network/publicIPAddresses/',variables('publicIPAddressName'))]" ],
"properties" : {
"sku" : {
"name" : "Standard_Small",
Expand Down Expand Up @@ -348,7 +348,7 @@ class AzureAppGatewayResourceTemplateSpec extends Specification {
"subnet" : "subnet-testappgw-lb1-d1",
"vnetResourceGroup" : null
},
"dependsOn" : [ "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]" ],
"dependsOn" : [ "[concat('Microsoft.Network/publicIPAddresses/',variables('publicIPAddressName'))]" ],
"properties" : {
"sku" : {
"name" : "Standard_Small",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AzureLoadBalancerResourceTemplateSpec extends Specification {

def 'should generate correct LoadBalancer create template'(){
String template = AzureLoadBalancerResourceTemplate.getTemplate(description)

expect: template.replaceAll('"createdTime" : "\\d+"', '"createdTime" : "1234567890"').replace('\r', '') == expectedFullTemplate
}

Expand Down Expand Up @@ -158,6 +157,7 @@ class AzureLoadBalancerResourceTemplateSpec extends Specification {
"protocol" : "tcp",
"frontendPort" : 80,
"backendPort" : 80,
"idleTimeoutInMinutes" : 4,
"probe" : {
"id" : "[concat(variables('loadBalancerID'),'/probes/healthcheck1')]"
},
Expand Down

0 comments on commit 926de75

Please sign in to comment.