func CreateMasterVMNetworkInterfaces()

in pkg/engine/networkinterfaces.go [15:135]


func CreateMasterVMNetworkInterfaces(cs *api.ContainerService) NetworkInterfaceARM {
	var dependencies []string
	if cs.Properties.MasterProfile != nil && cs.Properties.MasterProfile.IsCustomVNET() {
		dependencies = append(dependencies, "[variables('nsgID')]")
	} else {
		dependencies = append(dependencies, "[variables('vnetID')]")
	}

	if cs.Properties.MasterProfile != nil && cs.Properties.MasterProfile.HasMultipleNodes() {
		dependencies = append(dependencies, "[variables('masterInternalLbName')]")
	}

	if cs.Properties.MasterProfile != nil && cs.Properties.MasterProfile.HasCosmosEtcd() {
		dependencies = append(dependencies, "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('cosmosAccountName'))]")
	}

	lbBackendAddressPools := []network.BackendAddressPool{}
	dependencies = append(dependencies, "[variables('masterLbName')]")
	publicLbPool := network.BackendAddressPool{
		ID: to.StringPtr("[concat(variables('masterLbID'), '/backendAddressPools/', variables('masterLbBackendPoolName'))]"),
	}
	lbBackendAddressPools = append(lbBackendAddressPools, publicLbPool)

	armResource := ARMResource{
		APIVersion: "[variables('apiVersionNetwork')]",
		Copy: map[string]string{
			"count": "[sub(variables('masterCount'), variables('masterOffset'))]",
			"name":  "nicLoopNode",
		},
		DependsOn: dependencies,
	}

	if cs.Properties.MasterProfile != nil && cs.Properties.MasterProfile.HasMultipleNodes() {
		internalLbPool := network.BackendAddressPool{
			ID: to.StringPtr("[concat(variables('masterInternalLbID'), '/backendAddressPools/', variables('masterLbBackendPoolName'))]"),
		}
		lbBackendAddressPools = append(lbBackendAddressPools, internalLbPool)
	}

	loadBalancerIPConfig := network.InterfaceIPConfiguration{
		Name: to.StringPtr("ipconfig1"),
		InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{
			LoadBalancerBackendAddressPools: &lbBackendAddressPools,
			PrivateIPAddress:                to.StringPtr("[variables('masterPrivateIpAddrs')[copyIndex(variables('masterOffset'))]]"),
			Primary:                         to.BoolPtr(true),
			PrivateIPAllocationMethod:       network.Static,
			Subnet: &network.Subnet{
				ID: to.StringPtr("[variables('vnetSubnetID')]"),
			},
		},
	}

	publicNatRules := []network.InboundNatRule{
		{
			ID: to.StringPtr("[concat(variables('masterLbID'),'/inboundNatRules/SSH-',variables('masterVMNamePrefix'),copyIndex(variables('masterOffset')))]"),
		},
	}
	loadBalancerIPConfig.LoadBalancerInboundNatRules = &publicNatRules

	isAzureCNI := cs.Properties.OrchestratorProfile.IsAzureCNI()

	ipConfigurations := []network.InterfaceIPConfiguration{loadBalancerIPConfig}

	nicProperties := network.InterfacePropertiesFormat{
		IPConfigurations: &ipConfigurations,
	}

	if isAzureCNI {
		ipConfigurations = append(ipConfigurations, getSecondaryNICIPConfigs(cs.Properties.MasterProfile.IPAddressCount)...)
		if cs.Properties.FeatureFlags.IsFeatureEnabled("EnableIPv6DualStack") {
			nicProperties.EnableIPForwarding = to.BoolPtr(true)
		}
	} else {
		if !cs.Properties.IsAzureStackCloud() {
			nicProperties.EnableIPForwarding = to.BoolPtr(true)
		}
	}

	// 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("[variables('vnetSubnetID')]"),
				},
			},
		}

		ipConfigurations = append(ipConfigurations, ipv6Config)
	}

	linuxProfile := cs.Properties.LinuxProfile
	if linuxProfile != nil && linuxProfile.HasCustomNodesDNS() {
		nicProperties.DNSSettings = &network.InterfaceDNSSettings{
			DNSServers: &[]string{
				"[parameters('dnsServer')]",
			},
		}
	}

	if cs.Properties.MasterProfile != nil && cs.Properties.MasterProfile.IsCustomVNET() {
		nicProperties.NetworkSecurityGroup = &network.SecurityGroup{
			ID: to.StringPtr("[variables('nsgID')]"),
		}
	}

	networkInterface := network.Interface{
		Location:                  to.StringPtr("[variables('location')]"),
		Name:                      to.StringPtr("[concat(variables('masterVMNamePrefix'), 'nic-', copyIndex(variables('masterOffset')))]"),
		InterfacePropertiesFormat: &nicProperties,
		Type:                      to.StringPtr("Microsoft.Network/networkInterfaces"),
	}

	return NetworkInterfaceARM{
		ARMResource: armResource,
		Interface:   networkInterface,
	}
}