Skip to content

Commit 5350f65

Browse files
feat: Add new app gateway deployment parameters
Allows a user to specify: - zones - enable http2 - autoscaling min and max replicas
1 parent 6beb952 commit 5350f65

File tree

7 files changed

+369
-18
lines changed

7 files changed

+369
-18
lines changed

cmd/appgw-ingress/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,18 @@ func main() {
167167
// Instead we perform a simple GET request to check both that the Application Gateway exists as well as implicitly make sure that AGIC has read access to it.
168168
err = azClient.WaitForGetAccessOnGateway(maxRetryCount)
169169
if err != nil {
170+
deployParams := azure.DeployGatewayParams{
171+
SkuName: env.AppGwSkuName,
172+
Zones: env.AppGwZones,
173+
EnableHTTP2: env.AppGwEnableHTTP2,
174+
AutoscaleMinReplicas: env.AppGwAutoscaleMinReplicas,
175+
AutoscaleMaxReplicas: env.AppGwAutoscaleMaxReplicas,
176+
}
170177
if controllererrors.IsErrorCode(err, controllererrors.ErrorApplicationGatewayNotFound) && env.EnableDeployAppGateway {
171178
if env.AppGwSubnetID != "" {
172-
err = azClient.DeployGatewayWithSubnet(env.AppGwSubnetID, env.AppGwSkuName)
179+
err = azClient.DeployGatewayWithSubnet(env.AppGwSubnetID, deployParams)
173180
} else if cpConfig != nil {
174-
err = azClient.DeployGatewayWithVnet(azure.ResourceGroup(cpConfig.VNetResourceGroup), azure.ResourceName(cpConfig.VNetName), azure.ResourceName(env.AppGwSubnetName), env.AppGwSubnetPrefix, env.AppGwSkuName)
181+
err = azClient.DeployGatewayWithVnet(azure.ResourceGroup(cpConfig.VNetResourceGroup), azure.ResourceName(cpConfig.VNetName), azure.ResourceName(env.AppGwSubnetName), env.AppGwSubnetPrefix, deployParams)
175182
}
176183

177184
if err != nil {

helm/ingress-azure/templates/configmap.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ data:
2424
{{- if .Values.appgw.usePrivateIP }}
2525
USE_PRIVATE_IP: {{ .Values.appgw.usePrivateIP | quote }}
2626
{{- end }}
27+
{{- if .Values.appgw.autoscaleMinReplicas }}
28+
APPGW_AUTOSCALE_MIN_REPLICAS: {{ .Values.appgw.autoscaleMinReplicas | quote }}
29+
{{- end }}
30+
{{- if .Values.appgw.autoscaleMaxReplicas }}
31+
APPGW_AUTOSCALE_MAX_REPLICAS: {{ .Values.appgw.autoscaleMaxReplicas | quote }}
32+
{{- end }}
33+
{{- if .Values.appgw.zones }}
34+
APPGW_ZONES: {{ .Values.appgw.zones | quote }}
35+
{{- end }}
36+
{{- if .Values.appgw.enableHTTP2 }}
37+
APPGW_ENABLE_HTTP2: {{ .Values.appgw.enableHTTP2 | quote }}
38+
{{- end }}
2739
{{- if .Values.appgw.environment }}
2840
AZURE_ENVIRONMENT: {{ .Values.appgw.environment | quote }}
2941
{{- end -}}
@@ -110,4 +122,4 @@ data:
110122

111123
{{- if .Values.addon }}
112124
ADDON_MODE: {{ .Values.addon | quote }}
113-
{{- end }}
125+
{{- end }}

pkg/azure/client.go

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ import (
2323
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/version"
2424
)
2525

26+
type DeployGatewayParams struct {
27+
SkuName string
28+
Zones []string
29+
EnableHTTP2 bool
30+
AutoscaleMinReplicas int32
31+
AutoscaleMaxReplicas int32
32+
}
33+
2634
// AzClient is an interface for client to Azure
2735
type AzClient interface {
2836
SetAuthorizer(authorizer autorest.Authorizer)
@@ -33,8 +41,8 @@ type AzClient interface {
3341
WaitForGetAccessOnGateway(maxRetryCount int) error
3442
GetGateway() (n.ApplicationGateway, error)
3543
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
3846
GetSubnet(string) (n.Subnet, error)
3947

4048
GetPublicIP(string) (n.PublicIPAddress, error)
@@ -308,7 +316,7 @@ func (az *azClient) GetSubnet(subnetID string) (subnet n.Subnet, err error) {
308316
}
309317

310318
// 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) {
312320
vnet, err := az.getVnet(resourceGroupName, vnetName)
313321
if err != nil {
314322
return
@@ -335,12 +343,12 @@ func (az *azClient) DeployGatewayWithVnet(resourceGroupName ResourceGroup, vnetN
335343
}
336344
}
337345

338-
err = az.DeployGatewayWithSubnet(*subnet.ID, skuName)
346+
err = az.DeployGatewayWithSubnet(*subnet.ID, params)
339347
return
340348
}
341349

342350
// 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) {
344352
klog.Infof("Deploying Gateway")
345353

346354
// Check if group exists
@@ -352,7 +360,7 @@ func (az *azClient) DeployGatewayWithSubnet(subnetID, skuName string) (err error
352360

353361
deploymentName := string(az.appGwName)
354362
klog.Infof("Starting ARM template deployment: %s", deploymentName)
355-
result, err := az.createDeployment(subnetID, skuName)
363+
result, err := az.createDeployment(subnetID, params)
356364
if err != nil {
357365
return
358366
}
@@ -435,20 +443,20 @@ func (az *azClient) createSubnet(vnet n.VirtualNetwork, subnetName ResourceName,
435443
}
436444

437445
// 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)
440448
if err != nil {
441449
return
442450
}
443-
params := map[string]interface{}{
451+
templateParams := map[string]interface{}{
444452
"applicationGatewayName": map[string]string{
445453
"value": string(az.appGwName),
446454
},
447455
"applicationGatewaySubnetId": map[string]string{
448456
"value": subnetID,
449457
},
450458
"applicationGatewaySku": map[string]string{
451-
"value": skuName,
459+
"value": params.SkuName,
452460
},
453461
}
454462

@@ -459,7 +467,7 @@ func (az *azClient) createDeployment(subnetID, skuName string) (deployment r.Dep
459467
r.Deployment{
460468
Properties: &r.DeploymentProperties{
461469
Template: template,
462-
Parameters: params,
470+
Parameters: templateParams,
463471
Mode: r.DeploymentModeIncremental,
464472
},
465473
},
@@ -474,7 +482,7 @@ func (az *azClient) createDeployment(subnetID, skuName string) (deployment r.Dep
474482
return deploymentFuture.Result(az.deploymentsClient)
475483
}
476484

477-
func getTemplate() map[string]interface{} {
485+
func getTemplate(params DeployGatewayParams) map[string]interface{} {
478486
template := `
479487
{
480488
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
@@ -519,7 +527,7 @@ func getTemplate() map[string]interface{} {
519527
{
520528
"type": "Microsoft.Network/publicIPAddresses",
521529
"name": "[variables('applicationGatewayPublicIpName')]",
522-
"apiVersion": "2018-08-01",
530+
"apiVersion": "2018-11-01",
523531
"location": "[resourceGroup().location]",
524532
"sku": {
525533
"name": "Standard"
@@ -531,7 +539,7 @@ func getTemplate() map[string]interface{} {
531539
{
532540
"type": "Microsoft.Network/applicationGateways",
533541
"name": "[parameters('applicationGatewayName')]",
534-
"apiVersion": "2018-08-01",
542+
"apiVersion": "2018-11-01",
535543
"location": "[resourceGroup().location]",
536544
"tags": {
537545
"managed-by-k8s-ingress": "true",
@@ -649,5 +657,32 @@ func getTemplate() map[string]interface{} {
649657

650658
contents := make(map[string]interface{})
651659
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+
652687
return contents
653688
}

0 commit comments

Comments
 (0)