@@ -29,7 +29,6 @@ import (
2929 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v7"
3030 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
3131 "github.com/samber/lo"
32- v1 "k8s.io/api/core/v1"
3332 "k8s.io/apimachinery/pkg/util/sets"
3433 "sigs.k8s.io/controller-runtime/pkg/log"
3534 karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"
@@ -375,95 +374,11 @@ func (p *DefaultVMProvider) createCSExtension(ctx context.Context, vmName string
375374 return nil
376375}
377376
378- func (p * DefaultVMProvider ) newNetworkInterfaceForVM (opts * createNICOptions ) armnetwork.Interface {
379- var ipv4BackendPools []* armnetwork.BackendAddressPool
380- for _ , poolID := range opts .BackendPools .IPv4PoolIDs {
381- ipv4BackendPools = append (ipv4BackendPools , & armnetwork.BackendAddressPool {
382- ID : & poolID ,
383- })
384- }
385-
386- skuAcceleratedNetworkingRequirements := scheduling .NewRequirements (
387- scheduling .NewRequirement (v1beta1 .LabelSKUAcceleratedNetworking , v1 .NodeSelectorOpIn , "true" ))
388-
389- enableAcceleratedNetworking := false
390- if err := opts .InstanceType .Requirements .Compatible (skuAcceleratedNetworkingRequirements ); err == nil {
391- enableAcceleratedNetworking = true
392- }
393-
394- var nsgRef * armnetwork.SecurityGroup
395- if opts .NetworkSecurityGroupID != "" {
396- nsgRef = & armnetwork.SecurityGroup {
397- ID : & opts .NetworkSecurityGroupID ,
398- }
399- }
400-
401- nic := armnetwork.Interface {
402- Location : lo .ToPtr (p .location ),
403- Properties : & armnetwork.InterfacePropertiesFormat {
404- IPConfigurations : []* armnetwork.InterfaceIPConfiguration {
405- {
406- Name : & opts .NICName ,
407- Properties : & armnetwork.InterfaceIPConfigurationPropertiesFormat {
408- Primary : lo .ToPtr (true ),
409- PrivateIPAllocationMethod : lo .ToPtr (armnetwork .IPAllocationMethodDynamic ),
410-
411- LoadBalancerBackendAddressPools : ipv4BackendPools ,
412- },
413- },
414- },
415- NetworkSecurityGroup : nsgRef ,
416- EnableAcceleratedNetworking : lo .ToPtr (enableAcceleratedNetworking ),
417- EnableIPForwarding : lo .ToPtr (false ),
418- },
419- }
420- if opts .NetworkPlugin == consts .NetworkPluginAzure && opts .NetworkPluginMode != consts .NetworkPluginModeOverlay {
421- // AzureCNI without overlay requires secondary IPs, for pods. (These IPs are not included in backend address pools.)
422- // NOTE: Unlike AKS RP, this logic does not reduce secondary IP count by the number of expected hostNetwork pods, favoring simplicity instead
423- for i := 1 ; i < int (opts .MaxPods ); i ++ {
424- nic .Properties .IPConfigurations = append (
425- nic .Properties .IPConfigurations ,
426- & armnetwork.InterfaceIPConfiguration {
427- Name : lo .ToPtr (fmt .Sprintf ("ipconfig%d" , i )),
428- Properties : & armnetwork.InterfaceIPConfigurationPropertiesFormat {
429- Primary : lo .ToPtr (false ),
430- PrivateIPAllocationMethod : lo .ToPtr (armnetwork .IPAllocationMethodDynamic ),
431- },
432- },
433- )
434- }
435- }
436- return nic
437- }
438-
439377// E.g., aks-default-2jf98
440378func GenerateResourceName (nodeClaimName string ) string {
441379 return fmt .Sprintf ("aks-%s" , nodeClaimName )
442380}
443381
444- type createNICOptions struct {
445- NICName string
446- BackendPools * loadbalancer.BackendAddressPools
447- InstanceType * corecloudprovider.InstanceType
448- LaunchTemplate * launchtemplate.Template
449- NetworkPlugin string
450- NetworkPluginMode string
451- MaxPods int32
452- NetworkSecurityGroupID string
453- }
454-
455- func (p * DefaultVMProvider ) createNetworkInterface (ctx context.Context , opts * createNICOptions ) (string , error ) {
456- nic := p .newNetworkInterfaceForVM (opts )
457- p .applyTemplateToNic (& nic , opts .LaunchTemplate )
458- log .FromContext (ctx ).V (1 ).Info ("creating network interface" , "nicName" , opts .NICName )
459- res , err := createNic (ctx , p .azClient .NetworkInterfacesClient (), p .resourceGroup , opts .NICName , nic )
460- if err != nil {
461- return "" , err
462- }
463- log .FromContext (ctx ).V (1 ).Info ("successfully created network interface" , "nicName" , opts .NICName , "nicID" , * res .ID )
464- return * res .ID , nil
465- }
466-
467382// createVMOptions contains all the parameters needed to create a VM
468383type createVMOptions struct {
469384 VMName string
@@ -684,43 +599,8 @@ func (p *DefaultVMProvider) beginLaunchInstance(
684599 // resourceName for the NIC, VM, and Disk
685600 resourceName := GenerateResourceName (nodeClaim .Name )
686601
687- backendPools , err := p .loadBalancerProvider .LoadBalancerBackendPools (ctx )
688- if err != nil {
689- return nil , fmt .Errorf ("getting backend pools: %w" , err )
690- }
691- networkPlugin := options .FromContext (ctx ).NetworkPlugin
692- networkPluginMode := options .FromContext (ctx ).NetworkPluginMode
693-
694- isAKSManagedVNET , err := utils .IsAKSManagedVNET (options .FromContext (ctx ).NodeResourceGroup , launchTemplate .SubnetID )
695- if err != nil {
696- return nil , fmt .Errorf ("checking if vnet is managed: %w" , err )
697- }
698- var nsgID string
699- if ! isAKSManagedVNET {
700- nsg , err := p .networkSecurityGroupProvider .ManagedNetworkSecurityGroup (ctx )
701- if err != nil {
702- return nil , fmt .Errorf ("getting managed network security group: %w" , err )
703- }
704- nsgID = lo .FromPtr (nsg .ID )
705- }
706-
707- // TODO: Not returning after launching this LRO because
708- // TODO: doing so would bypass the capacity and other errors that are currently handled by
709- // TODO: core pkg/controllers/nodeclaim/lifecycle/controller.go - in particular, there are metrics/events
710- // TODO: emitted in capacity failure cases that we probably want.
711- nicReference , err := p .createNetworkInterface (
712- ctx ,
713- & createNICOptions {
714- NICName : resourceName ,
715- NetworkPlugin : networkPlugin ,
716- NetworkPluginMode : networkPluginMode ,
717- MaxPods : utils .GetMaxPods (nodeClass , networkPlugin , networkPluginMode ),
718- LaunchTemplate : launchTemplate ,
719- BackendPools : backendPools ,
720- InstanceType : instanceType ,
721- NetworkSecurityGroupID : nsgID ,
722- },
723- )
602+ // Create NIC
603+ nicReference , err := p .buildAndCreateNIC (ctx , resourceName , instanceType , nodeClass , launchTemplate )
724604 if err != nil {
725605 return nil , err
726606 }
@@ -821,14 +701,6 @@ func (p *DefaultVMProvider) beginLaunchInstance(
821701 }, nil
822702}
823703
824- func (p * DefaultVMProvider ) applyTemplateToNic (nic * armnetwork.Interface , template * launchtemplate.Template ) {
825- // set tags
826- nic .Tags = template .Tags
827- for _ , ipConfig := range nic .Properties .IPConfigurations {
828- ipConfig .Properties .Subnet = & armnetwork.Subnet {ID : & template .SubnetID }
829- }
830- }
831-
832704func (p * DefaultVMProvider ) getLaunchTemplate (
833705 ctx context.Context ,
834706 nodeClass * v1beta1.AKSNodeClass ,
0 commit comments