Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/appgw-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,18 @@ func main() {
// 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.
err = azClient.WaitForGetAccessOnGateway(maxRetryCount)
if err != nil {
deployParams := azure.DeployGatewayParams{
SkuName: env.AppGwSkuName,
Zones: env.AppGwZones,
EnableHTTP2: env.AppGwEnableHTTP2,
AutoscaleMinReplicas: env.AppGwAutoscaleMinReplicas,
AutoscaleMaxReplicas: env.AppGwAutoscaleMaxReplicas,
}
if controllererrors.IsErrorCode(err, controllererrors.ErrorApplicationGatewayNotFound) && env.EnableDeployAppGateway {
if env.AppGwSubnetID != "" {
err = azClient.DeployGatewayWithSubnet(env.AppGwSubnetID, env.AppGwSkuName)
err = azClient.DeployGatewayWithSubnet(env.AppGwSubnetID, deployParams)
} else if cpConfig != nil {
err = azClient.DeployGatewayWithVnet(azure.ResourceGroup(cpConfig.VNetResourceGroup), azure.ResourceName(cpConfig.VNetName), azure.ResourceName(env.AppGwSubnetName), env.AppGwSubnetPrefix, env.AppGwSkuName)
err = azClient.DeployGatewayWithVnet(azure.ResourceGroup(cpConfig.VNetResourceGroup), azure.ResourceName(cpConfig.VNetName), azure.ResourceName(env.AppGwSubnetName), env.AppGwSubnetPrefix, deployParams)
}

if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion helm/ingress-azure/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ data:
{{- if .Values.appgw.usePrivateIP }}
USE_PRIVATE_IP: {{ .Values.appgw.usePrivateIP | quote }}
{{- end }}
{{- if .Values.appgw.autoscaleMinReplicas }}
APPGW_AUTOSCALE_MIN_REPLICAS: {{ .Values.appgw.autoscaleMinReplicas | quote }}
{{- end }}
{{- if .Values.appgw.autoscaleMaxReplicas }}
APPGW_AUTOSCALE_MAX_REPLICAS: {{ .Values.appgw.autoscaleMaxReplicas | quote }}
{{- end }}
{{- if .Values.appgw.zones }}
APPGW_ZONES: {{ .Values.appgw.zones | quote }}
{{- end }}
{{- if .Values.appgw.enableHTTP2 }}
APPGW_ENABLE_HTTP2: {{ .Values.appgw.enableHTTP2 | quote }}
{{- end }}
{{- if .Values.appgw.environment }}
AZURE_ENVIRONMENT: {{ .Values.appgw.environment | quote }}
{{- end -}}
Expand Down Expand Up @@ -110,4 +122,4 @@ data:

{{- if .Values.addon }}
ADDON_MODE: {{ .Values.addon | quote }}
{{- end }}
{{- end }}
63 changes: 49 additions & 14 deletions pkg/azure/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ import (
"github.com/Azure/application-gateway-kubernetes-ingress/pkg/version"
)

type DeployGatewayParams struct {
SkuName string
Zones []string
EnableHTTP2 bool
AutoscaleMinReplicas int32
AutoscaleMaxReplicas int32
}

// AzClient is an interface for client to Azure
type AzClient interface {
SetAuthorizer(authorizer autorest.Authorizer)
Expand All @@ -33,8 +41,8 @@ type AzClient interface {
WaitForGetAccessOnGateway(maxRetryCount int) error
GetGateway() (n.ApplicationGateway, error)
UpdateGateway(*n.ApplicationGateway) error
DeployGatewayWithVnet(ResourceGroup, ResourceName, ResourceName, string, string) error
DeployGatewayWithSubnet(string, string) error
DeployGatewayWithVnet(ResourceGroup, ResourceName, ResourceName, string, DeployGatewayParams) error
DeployGatewayWithSubnet(string, DeployGatewayParams) error
GetSubnet(string) (n.Subnet, error)

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

// DeployGatewayWithVnet creates Application Gateway within the specifid VNet. Implements AzClient interface.
func (az *azClient) DeployGatewayWithVnet(resourceGroupName ResourceGroup, vnetName ResourceName, subnetName ResourceName, subnetPrefix, skuName string) (err error) {
func (az *azClient) DeployGatewayWithVnet(resourceGroupName ResourceGroup, vnetName ResourceName, subnetName ResourceName, subnetPrefix string, params DeployGatewayParams) (err error) {
vnet, err := az.getVnet(resourceGroupName, vnetName)
if err != nil {
return
Expand All @@ -335,12 +343,12 @@ func (az *azClient) DeployGatewayWithVnet(resourceGroupName ResourceGroup, vnetN
}
}

err = az.DeployGatewayWithSubnet(*subnet.ID, skuName)
err = az.DeployGatewayWithSubnet(*subnet.ID, params)
return
}

// DeployGatewayWithSubnet creates Application Gateway within the specifid subnet. Implements AzClient interface.
func (az *azClient) DeployGatewayWithSubnet(subnetID, skuName string) (err error) {
func (az *azClient) DeployGatewayWithSubnet(subnetID string, params DeployGatewayParams) (err error) {
klog.Infof("Deploying Gateway")

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

deploymentName := string(az.appGwName)
klog.Infof("Starting ARM template deployment: %s", deploymentName)
result, err := az.createDeployment(subnetID, skuName)
result, err := az.createDeployment(subnetID, params)
if err != nil {
return
}
Expand Down Expand Up @@ -435,20 +443,20 @@ func (az *azClient) createSubnet(vnet n.VirtualNetwork, subnetName ResourceName,
}

// Create the deployment
func (az *azClient) createDeployment(subnetID, skuName string) (deployment r.DeploymentExtended, err error) {
template := getTemplate()
func (az *azClient) createDeployment(subnetID string, params DeployGatewayParams) (deployment r.DeploymentExtended, err error) {
template := getTemplate(params)
if err != nil {
return
}
params := map[string]interface{}{
templateParams := map[string]interface{}{
"applicationGatewayName": map[string]string{
"value": string(az.appGwName),
},
"applicationGatewaySubnetId": map[string]string{
"value": subnetID,
},
"applicationGatewaySku": map[string]string{
"value": skuName,
"value": params.SkuName,
},
}

Expand All @@ -459,7 +467,7 @@ func (az *azClient) createDeployment(subnetID, skuName string) (deployment r.Dep
r.Deployment{
Properties: &r.DeploymentProperties{
Template: template,
Parameters: params,
Parameters: templateParams,
Mode: r.DeploymentModeIncremental,
},
},
Expand All @@ -474,7 +482,7 @@ func (az *azClient) createDeployment(subnetID, skuName string) (deployment r.Dep
return deploymentFuture.Result(az.deploymentsClient)
}

func getTemplate() map[string]interface{} {
func getTemplate(params DeployGatewayParams) map[string]interface{} {
template := `
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
Expand Down Expand Up @@ -519,7 +527,7 @@ func getTemplate() map[string]interface{} {
{
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('applicationGatewayPublicIpName')]",
"apiVersion": "2018-08-01",
"apiVersion": "2018-11-01",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard"
Expand All @@ -531,7 +539,7 @@ func getTemplate() map[string]interface{} {
{
"type": "Microsoft.Network/applicationGateways",
"name": "[parameters('applicationGatewayName')]",
"apiVersion": "2018-08-01",
"apiVersion": "2018-11-01",
"location": "[resourceGroup().location]",
"tags": {
"managed-by-k8s-ingress": "true",
Expand Down Expand Up @@ -649,5 +657,32 @@ func getTemplate() map[string]interface{} {

contents := make(map[string]interface{})
json.Unmarshal([]byte(template), &contents)

// Apply customizations based on params
resources := contents["resources"].([]interface{})
appGwResource := resources[1].(map[string]interface{})
appGwProperties := appGwResource["properties"].(map[string]interface{})
sku := appGwProperties["sku"].(map[string]interface{})

// Handle autoscaling configuration
if params.AutoscaleMinReplicas > 0 && params.AutoscaleMaxReplicas > 0 {
// Remove static capacity and add autoscale configuration
delete(sku, "capacity")
appGwProperties["autoscaleConfiguration"] = map[string]interface{}{
"minCapacity": params.AutoscaleMinReplicas,
"maxCapacity": params.AutoscaleMaxReplicas,
}
}

// Add zones if specified
if len(params.Zones) > 0 {
appGwResource["zones"] = params.Zones
}

// Enable HTTP/2 if specified
if params.EnableHTTP2 {
appGwProperties["enableHttp2"] = true
}

return contents
}
Loading