in pkg/engine/networkinterfaces.go [296:431]
func createAgentVMASNetworkInterface(cs *api.ContainerService, profile *api.AgentPoolProfile) NetworkInterfaceARM {
isWindows := profile.IsWindows()
isCustomVNet := profile.IsCustomVNET()
isAzureCNI := cs.Properties.OrchestratorProfile.IsAzureCNI()
armResource := ARMResource{
APIVersion: "[variables('apiVersionNetwork')]",
Copy: map[string]string{
"count": fmt.Sprintf("[sub(variables('%[1]sCount'), variables('%[1]sOffset'))]", profile.Name),
"name": "loop",
},
}
var dependencies []string
if isCustomVNet {
dependencies = append(dependencies, "[variables('nsgID')]")
} else {
dependencies = append(dependencies, "[variables('vnetID')]")
}
if profile.LoadBalancerBackendAddressPoolIDs == nil &&
cs.Properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku == api.StandardLoadBalancerSku {
dependencies = append(dependencies, "[variables('agentLbID')]")
}
armResource.DependsOn = dependencies
networkInterface := network.Interface{
Type: to.StringPtr("Microsoft.Network/networkInterfaces"),
Name: to.StringPtr("[concat(variables('" + profile.Name + "VMNamePrefix'), 'nic-', copyIndex(variables('" + profile.Name + "Offset')))]"),
Location: to.StringPtr("[variables('location')]"),
}
networkInterface.InterfacePropertiesFormat = &network.InterfacePropertiesFormat{}
if isCustomVNet {
networkInterface.NetworkSecurityGroup = &network.SecurityGroup{
ID: to.StringPtr("[variables('nsgID')]"),
}
}
if isWindows {
networkInterface.EnableAcceleratedNetworking = profile.AcceleratedNetworkingEnabledWindows
} else {
networkInterface.EnableAcceleratedNetworking = profile.AcceleratedNetworkingEnabled
}
var ipConfigurations []network.InterfaceIPConfiguration
for i := 1; i <= profile.IPAddressCount; i++ {
ipConfig := network.InterfaceIPConfiguration{
Name: to.StringPtr(fmt.Sprintf("ipconfig%d", i)),
InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{},
}
if i == 1 {
ipConfig.Primary = to.BoolPtr(true)
backendPools := make([]network.BackendAddressPool, 0)
if profile.LoadBalancerBackendAddressPoolIDs != nil {
for _, lbBackendPoolID := range profile.LoadBalancerBackendAddressPoolIDs {
backendPools = append(backendPools,
network.BackendAddressPool{
ID: to.StringPtr(lbBackendPoolID),
},
)
}
} else {
if cs.Properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku == api.StandardLoadBalancerSku {
agentLbBackendAddressPools := network.BackendAddressPool{
ID: to.StringPtr("[concat(variables('agentLbID'), '/backendAddressPools/', variables('agentLbBackendPoolName'))]"),
}
backendPools = append(backendPools, agentLbBackendAddressPools)
}
}
ipConfig.LoadBalancerBackendAddressPools = &backendPools
}
ipConfig.PrivateIPAllocationMethod = network.Dynamic
ipConfig.Subnet = &network.Subnet{
ID: to.StringPtr(fmt.Sprintf("[variables('%sVnetSubnetID')]", profile.Name)),
}
if !isWindows {
if profile.Role == "Infra" {
ipConfig.LoadBalancerBackendAddressPools = &[]network.BackendAddressPool{
{
ID: to.StringPtr("[concat(resourceId('Microsoft.Network/loadBalancers', variables('routerLBName')), '/backendAddressPools/backend')]"),
},
}
}
}
if cs.Properties.FeatureFlags.IsFeatureEnabled("EnableIPv6DualStack") || cs.Properties.FeatureFlags.IsFeatureEnabled("EnableIPv6Only") {
if cs.Properties.OrchestratorProfile.KubernetesConfig.LoadBalancerSku != api.StandardLoadBalancerSku {
var backendPools []network.BackendAddressPool
if ipConfig.LoadBalancerBackendAddressPools != nil {
backendPools = *ipConfig.LoadBalancerBackendAddressPools
}
backendPools = append(backendPools, network.BackendAddressPool{
ID: to.StringPtr("[concat(resourceId('Microsoft.Network/loadBalancers',parameters('masterEndpointDNSNamePrefix')), '/backendAddressPools/', parameters('masterEndpointDNSNamePrefix'))]"),
})
ipConfig.LoadBalancerBackendAddressPools = &backendPools
}
}
ipConfigurations = append(ipConfigurations, ipConfig)
}
// add ipv6 nic config for dual stack
if cs.Properties.FeatureFlags.IsFeatureEnabled("EnableIPv6DualStack") || cs.Properties.FeatureFlags.IsFeatureEnabled("EnableIPv6Only") {
ipv6Config := network.InterfaceIPConfiguration{
Name: to.StringPtr("ipconfigv6"),
InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAddressVersion: "IPv6",
Primary: to.BoolPtr(false),
Subnet: &network.Subnet{
ID: to.StringPtr(fmt.Sprintf("[variables('%sVnetSubnetID')]", profile.Name)),
},
},
}
ipConfigurations = append(ipConfigurations, ipv6Config)
}
networkInterface.IPConfigurations = &ipConfigurations
if !isAzureCNI && !cs.Properties.IsAzureStackCloud() {
networkInterface.EnableIPForwarding = to.BoolPtr(true)
}
// Enable IPForwarding on NetworkInterface for azurecni dualstack
if isAzureCNI {
if cs.Properties.FeatureFlags.IsFeatureEnabled("EnableIPv6DualStack") {
networkInterface.EnableIPForwarding = to.BoolPtr(true)
}
}
return NetworkInterfaceARM{
ARMResource: armResource,
Interface: networkInterface,
}
}