Skip to content

Commit

Permalink
update machinepool scope
Browse files Browse the repository at this point in the history
  • Loading branch information
LochanRn committed Mar 20, 2023
1 parent 682789e commit 142981e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions azure/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,24 @@ func (s *ManagedMachinePoolScope) Name() string {

// SetSubnetName updates AzureManagedMachinePool.SubnetName if AzureManagedMachinePool.SubnetName is empty with s.ControlPlane.Spec.VirtualNetwork.Subnet.Name.
func (s *ManagedMachinePoolScope) SetSubnetName() {
if s.ControlPlane.Spec.VirtualNetwork.Name != "" && s.InfraMachinePool.Spec.SubnetName == nil {
s.InfraMachinePool.Spec.SubnetName = to.StringPtr(s.ControlPlane.Spec.VirtualNetwork.Subnet.Name)
}
s.InfraMachinePool.Spec.SubnetName = getAgentPoolSubnet(s.ControlPlane, s.InfraMachinePool)
}

// AgentPoolSpec returns an azure.ResourceSpecGetter for currently reconciled AzureManagedMachinePool.
func (s *ManagedMachinePoolScope) AgentPoolSpec() azure.ResourceSpecGetter {
return buildAgentPoolSpec(s.ControlPlane, s.MachinePool, s.InfraMachinePool, s.AgentPoolAnnotations())
}

func getAgentPoolSubnet(controlPlane *infrav1.AzureManagedControlPlane, infraMachinePool *infrav1.AzureManagedMachinePool) *string {
if infraMachinePool.Spec.SubnetName != nil {
return infraMachinePool.Spec.SubnetName
}
if controlPlane.Spec.VirtualNetwork.Name != "" {
return to.StringPtr(controlPlane.Spec.VirtualNetwork.Subnet.Name)
}
return nil
}

func buildAgentPoolSpec(managedControlPlane *infrav1.AzureManagedControlPlane,
machinePool *expv1.MachinePool,
managedMachinePool *infrav1.AzureManagedMachinePool,
Expand Down Expand Up @@ -174,7 +182,7 @@ func buildAgentPoolSpec(managedControlPlane *infrav1.AzureManagedControlPlane,
managedControlPlane.Spec.SubscriptionID,
managedControlPlane.Spec.VirtualNetwork.ResourceGroup,
managedControlPlane.Spec.VirtualNetwork.Name,
to.String(managedMachinePool.Spec.SubnetName),
to.String(getAgentPoolSubnet(managedControlPlane, managedMachinePool)),
),
Mode: managedMachinePool.Spec.Mode,
MaxPods: managedMachinePool.Spec.MaxPods,
Expand Down

0 comments on commit 142981e

Please sign in to comment.