@@ -471,9 +471,9 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec() (azure.ManagedClusterSpe
471471 return managedClusterSpec , nil
472472}
473473
474- // GetAgentPoolSpecs gets a slice of azure.AgentPoolSpec for the list of agent pools.
475- func (s * ManagedControlPlaneScope ) GetAgentPoolSpecs (ctx context.Context ) ([]azure.AgentPoolSpec , error ) {
476- ctx , log , done := tele .StartSpanWithLogger (ctx , "scope.ManagedControlPlaneScope.GetAgentPoolSpecs " )
474+ // GetAllAgentPoolSpecs gets a slice of azure.AgentPoolSpec for the list of agent pools.
475+ func (s * ManagedControlPlaneScope ) GetAllAgentPoolSpecs (ctx context.Context ) ([]azure.AgentPoolSpec , error ) {
476+ ctx , log , done := tele .StartSpanWithLogger (ctx , "scope.ManagedControlPlaneScope.GetAllAgentPoolSpecs " )
477477 defer done ()
478478
479479 if len (s .AllNodePools ) == 0 {
@@ -495,7 +495,7 @@ func (s *ManagedControlPlaneScope) GetAgentPoolSpecs(ctx context.Context) ([]azu
495495 ammps = make ([]azure.AgentPoolSpec , 0 , len (s .AllNodePools ))
496496 foundSystemPool = false
497497 )
498- for _ , pool := range s .AllNodePools {
498+ for i , pool := range s .AllNodePools {
499499 // Fetch the owning MachinePool.
500500
501501 ownerPool , err := capiexputil .GetOwnerMachinePool (ctx , s .Client , pool .ObjectMeta )
@@ -512,34 +512,14 @@ func (s *ManagedControlPlaneScope) GetAgentPoolSpecs(ctx context.Context) ([]azu
512512 foundSystemPool = true
513513 }
514514
515- ammp := azure.AgentPoolSpec {
516- Name : to .String (pool .Spec .Name ),
517- SKU : pool .Spec .SKU ,
518- Replicas : 1 ,
519- OSDiskSizeGB : 0 ,
520- Mode : pool .Spec .Mode ,
521- MaxPods : pool .Spec .MaxPods ,
522- AvailabilityZones : pool .Spec .AvailabilityZones ,
523- OsDiskType : pool .Spec .OsDiskType ,
524- }
525-
526- // Set optional values
527- if pool .Spec .OSDiskSizeGB != nil {
528- ammp .OSDiskSizeGB = * pool .Spec .OSDiskSizeGB
529- }
530-
531- if ownerPool .Spec .Replicas != nil {
532- ammp .Replicas = * ownerPool .Spec .Replicas
533- }
534-
535515 if ownerPool .Spec .Template .Spec .Version != nil {
536516 version := * ownerPool .Spec .Template .Spec .Version
537517 if semver .Compare (version , s .ControlPlane .Spec .Version ) > 0 {
538518 return nil , errors .New ("MachinePool version cannot be greater than the AzureManagedControlPlane version" )
539519 }
540- ammp .Version = to .StringPtr (strings .TrimPrefix (version , "v" ))
541520 }
542521
522+ ammp := buildAgentPoolSpec (s .ControlPlane , ownerPool , & s .AllNodePools [i ])
543523 ammps = append (ammps , ammp )
544524 }
545525
@@ -552,44 +532,50 @@ func (s *ManagedControlPlaneScope) GetAgentPoolSpecs(ctx context.Context) ([]azu
552532
553533// AgentPoolSpec returns an azure.AgentPoolSpec for currently reconciled AzureManagedMachinePool.
554534func (s * ManagedControlPlaneScope ) AgentPoolSpec () azure.AgentPoolSpec {
535+ return buildAgentPoolSpec (s .ControlPlane , s .MachinePool , s .InfraMachinePool )
536+ }
537+
538+ func buildAgentPoolSpec (managedControlPlane * infrav1exp.AzureManagedControlPlane ,
539+ machinePool * expv1.MachinePool ,
540+ managedMachinePool * infrav1exp.AzureManagedMachinePool ) azure.AgentPoolSpec {
555541 var normalizedVersion * string
556- if s . MachinePool .Spec .Template .Spec .Version != nil {
557- v := strings .TrimPrefix (* s . MachinePool .Spec .Template .Spec .Version , "v" )
542+ if machinePool .Spec .Template .Spec .Version != nil {
543+ v := strings .TrimPrefix (* machinePool .Spec .Template .Spec .Version , "v" )
558544 normalizedVersion = & v
559545 }
560546
561547 replicas := int32 (1 )
562- if s . MachinePool .Spec .Replicas != nil {
563- replicas = * s . MachinePool .Spec .Replicas
548+ if machinePool .Spec .Replicas != nil {
549+ replicas = * machinePool .Spec .Replicas
564550 }
565551
566552 agentPoolSpec := azure.AgentPoolSpec {
567- Name : to .String (s . InfraMachinePool .Spec .Name ),
568- ResourceGroup : s . ControlPlane .Spec .ResourceGroupName ,
569- Cluster : s . ControlPlane .Name ,
570- SKU : s . InfraMachinePool .Spec .SKU ,
553+ Name : to .String (managedMachinePool .Spec .Name ),
554+ ResourceGroup : managedControlPlane .Spec .ResourceGroupName ,
555+ Cluster : managedControlPlane .Name ,
556+ SKU : managedMachinePool .Spec .SKU ,
571557 Replicas : replicas ,
572558 Version : normalizedVersion ,
573559 VnetSubnetID : azure .SubnetID (
574- s . ControlPlane .Spec .SubscriptionID ,
575- s . ControlPlane .Spec .ResourceGroupName ,
576- s . ControlPlane .Spec .VirtualNetwork .Name ,
577- s . ControlPlane .Spec .VirtualNetwork .Subnet .Name ,
560+ managedControlPlane .Spec .SubscriptionID ,
561+ managedControlPlane .Spec .ResourceGroupName ,
562+ managedControlPlane .Spec .VirtualNetwork .Name ,
563+ managedControlPlane .Spec .VirtualNetwork .Subnet .Name ,
578564 ),
579- Mode : s . InfraMachinePool .Spec .Mode ,
580- MaxPods : s . InfraMachinePool .Spec .MaxPods ,
581- AvailabilityZones : s . InfraMachinePool .Spec .AvailabilityZones ,
582- OsDiskType : s . InfraMachinePool .Spec .OsDiskType ,
565+ Mode : managedMachinePool .Spec .Mode ,
566+ MaxPods : managedMachinePool .Spec .MaxPods ,
567+ AvailabilityZones : managedMachinePool .Spec .AvailabilityZones ,
568+ OsDiskType : managedMachinePool .Spec .OsDiskType ,
583569 }
584570
585- if s . InfraMachinePool .Spec .OSDiskSizeGB != nil {
586- agentPoolSpec .OSDiskSizeGB = * s . InfraMachinePool .Spec .OSDiskSizeGB
571+ if managedMachinePool .Spec .OSDiskSizeGB != nil {
572+ agentPoolSpec .OSDiskSizeGB = * managedMachinePool .Spec .OSDiskSizeGB
587573 }
588574
589- if s . InfraMachinePool .Spec .Scaling != nil {
575+ if managedMachinePool .Spec .Scaling != nil {
590576 agentPoolSpec .EnableAutoScaling = to .BoolPtr (true )
591- agentPoolSpec .MaxCount = s . InfraMachinePool .Spec .Scaling .MaxSize
592- agentPoolSpec .MinCount = s . InfraMachinePool .Spec .Scaling .MinSize
577+ agentPoolSpec .MaxCount = managedMachinePool .Spec .Scaling .MaxSize
578+ agentPoolSpec .MinCount = managedMachinePool .Spec .Scaling .MinSize
593579 }
594580
595581 return agentPoolSpec
0 commit comments