@@ -23,6 +23,14 @@ import (
23
23
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/version"
24
24
)
25
25
26
+ type DeployGatewayParams struct {
27
+ SkuName string
28
+ Zones []string
29
+ EnableHTTP2 bool
30
+ AutoscaleMinReplicas int32
31
+ AutoscaleMaxReplicas int32
32
+ }
33
+
26
34
// AzClient is an interface for client to Azure
27
35
type AzClient interface {
28
36
SetAuthorizer (authorizer autorest.Authorizer )
@@ -33,8 +41,8 @@ type AzClient interface {
33
41
WaitForGetAccessOnGateway (maxRetryCount int ) error
34
42
GetGateway () (n.ApplicationGateway , error )
35
43
UpdateGateway (* n.ApplicationGateway ) error
36
- DeployGatewayWithVnet (ResourceGroup , ResourceName , ResourceName , string , string ) error
37
- DeployGatewayWithSubnet (string , string ) error
44
+ DeployGatewayWithVnet (ResourceGroup , ResourceName , ResourceName , string , DeployGatewayParams ) error
45
+ DeployGatewayWithSubnet (string , DeployGatewayParams ) error
38
46
GetSubnet (string ) (n.Subnet , error )
39
47
40
48
GetPublicIP (string ) (n.PublicIPAddress , error )
@@ -308,7 +316,7 @@ func (az *azClient) GetSubnet(subnetID string) (subnet n.Subnet, err error) {
308
316
}
309
317
310
318
// DeployGatewayWithVnet creates Application Gateway within the specifid VNet. Implements AzClient interface.
311
- func (az * azClient ) DeployGatewayWithVnet (resourceGroupName ResourceGroup , vnetName ResourceName , subnetName ResourceName , subnetPrefix , skuName string ) (err error ) {
319
+ func (az * azClient ) DeployGatewayWithVnet (resourceGroupName ResourceGroup , vnetName ResourceName , subnetName ResourceName , subnetPrefix string , params DeployGatewayParams ) (err error ) {
312
320
vnet , err := az .getVnet (resourceGroupName , vnetName )
313
321
if err != nil {
314
322
return
@@ -335,12 +343,12 @@ func (az *azClient) DeployGatewayWithVnet(resourceGroupName ResourceGroup, vnetN
335
343
}
336
344
}
337
345
338
- err = az .DeployGatewayWithSubnet (* subnet .ID , skuName )
346
+ err = az .DeployGatewayWithSubnet (* subnet .ID , params )
339
347
return
340
348
}
341
349
342
350
// DeployGatewayWithSubnet creates Application Gateway within the specifid subnet. Implements AzClient interface.
343
- func (az * azClient ) DeployGatewayWithSubnet (subnetID , skuName string ) (err error ) {
351
+ func (az * azClient ) DeployGatewayWithSubnet (subnetID string , params DeployGatewayParams ) (err error ) {
344
352
klog .Infof ("Deploying Gateway" )
345
353
346
354
// Check if group exists
@@ -352,7 +360,7 @@ func (az *azClient) DeployGatewayWithSubnet(subnetID, skuName string) (err error
352
360
353
361
deploymentName := string (az .appGwName )
354
362
klog .Infof ("Starting ARM template deployment: %s" , deploymentName )
355
- result , err := az .createDeployment (subnetID , skuName )
363
+ result , err := az .createDeployment (subnetID , params )
356
364
if err != nil {
357
365
return
358
366
}
@@ -435,20 +443,20 @@ func (az *azClient) createSubnet(vnet n.VirtualNetwork, subnetName ResourceName,
435
443
}
436
444
437
445
// Create the deployment
438
- func (az * azClient ) createDeployment (subnetID , skuName string ) (deployment r.DeploymentExtended , err error ) {
439
- template := getTemplate ()
446
+ func (az * azClient ) createDeployment (subnetID string , params DeployGatewayParams ) (deployment r.DeploymentExtended , err error ) {
447
+ template := getTemplate (params )
440
448
if err != nil {
441
449
return
442
450
}
443
- params := map [string ]interface {}{
451
+ templateParams := map [string ]interface {}{
444
452
"applicationGatewayName" : map [string ]string {
445
453
"value" : string (az .appGwName ),
446
454
},
447
455
"applicationGatewaySubnetId" : map [string ]string {
448
456
"value" : subnetID ,
449
457
},
450
458
"applicationGatewaySku" : map [string ]string {
451
- "value" : skuName ,
459
+ "value" : params . SkuName ,
452
460
},
453
461
}
454
462
@@ -459,7 +467,7 @@ func (az *azClient) createDeployment(subnetID, skuName string) (deployment r.Dep
459
467
r.Deployment {
460
468
Properties : & r.DeploymentProperties {
461
469
Template : template ,
462
- Parameters : params ,
470
+ Parameters : templateParams ,
463
471
Mode : r .DeploymentModeIncremental ,
464
472
},
465
473
},
@@ -474,7 +482,7 @@ func (az *azClient) createDeployment(subnetID, skuName string) (deployment r.Dep
474
482
return deploymentFuture .Result (az .deploymentsClient )
475
483
}
476
484
477
- func getTemplate () map [string ]interface {} {
485
+ func getTemplate (params DeployGatewayParams ) map [string ]interface {} {
478
486
template := `
479
487
{
480
488
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
@@ -519,7 +527,7 @@ func getTemplate() map[string]interface{} {
519
527
{
520
528
"type": "Microsoft.Network/publicIPAddresses",
521
529
"name": "[variables('applicationGatewayPublicIpName')]",
522
- "apiVersion": "2018-08 -01",
530
+ "apiVersion": "2018-11 -01",
523
531
"location": "[resourceGroup().location]",
524
532
"sku": {
525
533
"name": "Standard"
@@ -531,7 +539,7 @@ func getTemplate() map[string]interface{} {
531
539
{
532
540
"type": "Microsoft.Network/applicationGateways",
533
541
"name": "[parameters('applicationGatewayName')]",
534
- "apiVersion": "2018-08 -01",
542
+ "apiVersion": "2018-11 -01",
535
543
"location": "[resourceGroup().location]",
536
544
"tags": {
537
545
"managed-by-k8s-ingress": "true",
@@ -649,5 +657,32 @@ func getTemplate() map[string]interface{} {
649
657
650
658
contents := make (map [string ]interface {})
651
659
json .Unmarshal ([]byte (template ), & contents )
660
+
661
+ // Apply customizations based on params
662
+ resources := contents ["resources" ].([]interface {})
663
+ appGwResource := resources [1 ].(map [string ]interface {})
664
+ appGwProperties := appGwResource ["properties" ].(map [string ]interface {})
665
+ sku := appGwProperties ["sku" ].(map [string ]interface {})
666
+
667
+ // Handle autoscaling configuration
668
+ if params .AutoscaleMinReplicas > 0 && params .AutoscaleMaxReplicas > 0 {
669
+ // Remove static capacity and add autoscale configuration
670
+ delete (sku , "capacity" )
671
+ appGwProperties ["autoscaleConfiguration" ] = map [string ]interface {}{
672
+ "minCapacity" : params .AutoscaleMinReplicas ,
673
+ "maxCapacity" : params .AutoscaleMaxReplicas ,
674
+ }
675
+ }
676
+
677
+ // Add zones if specified
678
+ if len (params .Zones ) > 0 {
679
+ appGwResource ["zones" ] = params .Zones
680
+ }
681
+
682
+ // Enable HTTP/2 if specified
683
+ if params .EnableHTTP2 {
684
+ appGwProperties ["enableHttp2" ] = true
685
+ }
686
+
652
687
return contents
653
688
}
0 commit comments