Skip to content

Commit

Permalink
AKS virtual network static placement for cross RG
Browse files Browse the repository at this point in the history
  • Loading branch information
snehala27 authored and LochanRn committed Sep 30, 2022
1 parent d28ff9a commit 5ddf24b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 23 deletions.
8 changes: 6 additions & 2 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,12 @@ func (s *ManagedControlPlaneScope) Close(ctx context.Context) error {

// Vnet returns the cluster Vnet.
func (s *ManagedControlPlaneScope) Vnet() *infrav1.VnetSpec {
resourceGroupName := s.ControlPlane.Spec.ResourceGroupName
if s.ControlPlane.Spec.VirtualNetwork.ResourceGroupName != "" {
resourceGroupName = s.ControlPlane.Spec.VirtualNetwork.ResourceGroupName
}
return &infrav1.VnetSpec{
ResourceGroup: s.ControlPlane.Spec.ResourceGroupName,
ResourceGroup: resourceGroupName,
Name: s.ControlPlane.Spec.VirtualNetwork.Name,
VnetClassSpec: infrav1.VnetClassSpec{
CIDRBlocks: []string{s.ControlPlane.Spec.VirtualNetwork.CIDRBlock},
Expand Down Expand Up @@ -424,7 +428,7 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec(ctx context.Context) azure
DNSServiceIP: s.ControlPlane.Spec.DNSServiceIP,
VnetSubnetID: azure.SubnetID(
s.ControlPlane.Spec.SubscriptionID,
s.ControlPlane.Spec.ResourceGroupName,
s.VNetSpec().ResourceGroupName(),
s.ControlPlane.Spec.VirtualNetwork.Name,
s.ControlPlane.Spec.VirtualNetwork.Subnet.Name,
),
Expand Down
6 changes: 5 additions & 1 deletion azure/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane
replicas = *machinePool.Spec.Replicas
}

resourceGroupName := managedControlPlane.Spec.ResourceGroupName
if managedControlPlane.Spec.VirtualNetwork.ResourceGroupName != "" {
resourceGroupName = managedControlPlane.Spec.VirtualNetwork.ResourceGroupName
}
agentPoolSpec := &agentpools.AgentPoolSpec{
Name: to.String(managedMachinePool.Spec.Name),
ResourceGroup: managedControlPlane.Spec.ResourceGroupName,
Expand All @@ -165,7 +169,7 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane
OSType: managedMachinePool.Spec.OSType,
VnetSubnetID: azure.SubnetID(
managedControlPlane.Spec.SubscriptionID,
managedControlPlane.Spec.ResourceGroupName,
resourceGroupName,
managedControlPlane.Spec.VirtualNetwork.Name,
managedControlPlane.Spec.VirtualNetwork.Subnet.Name,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ spec:
type: string
name:
type: string
resourceGroupName:
description: ResourceGroupName is the name of the Azure resource
group for the VNet and Subnet.
type: string
subnet:
description: ManagedControlPlaneSubnet describes a subnet for
an AKS cluster.
Expand Down
11 changes: 11 additions & 0 deletions exp/api/v1alpha3/azuremanagedcontrolplane_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (src *AzureManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.LoadBalancerProfile = restored.Spec.LoadBalancerProfile
dst.Spec.APIServerAccessProfile = restored.Spec.APIServerAccessProfile
dst.Spec.AddonProfiles = restored.Spec.AddonProfiles
dst.Spec.VirtualNetwork.ResourceGroupName = restored.Spec.VirtualNetwork.ResourceGroupName

dst.Status.LongRunningOperationStates = restored.Status.LongRunningOperationStates
dst.Status.Conditions = restored.Status.Conditions
Expand Down Expand Up @@ -81,3 +82,13 @@ func (dst *AzureManagedControlPlaneList) ConvertFrom(srcRaw conversion.Hub) erro
src := srcRaw.(*infrav1exp.AzureManagedControlPlaneList)
return Convert_v1beta1_AzureManagedControlPlaneList_To_v1alpha3_AzureManagedControlPlaneList(src, dst, nil)
}

// Convert_v1beta1_ManagedControlPlaneVirtualNetwork_To_v1alpha3_ManagedControlPlaneVirtualNetwork converts v1beta1 ManagedControlPlaneVirtualNetwork to v1alpha3 ManagedControlPlaneVirtualNetwork.
func Convert_v1beta1_ManagedControlPlaneVirtualNetwork_To_v1alpha3_ManagedControlPlaneVirtualNetwork(in *infrav1exp.ManagedControlPlaneVirtualNetwork, out *ManagedControlPlaneVirtualNetwork, s apiconversion.Scope) error {
out.Name = in.Name
out.Subnet.Name = in.Subnet.Name
out.Subnet.CIDRBlock = in.Subnet.CIDRBlock
out.CIDRBlock = in.CIDRBlock

return nil
}
16 changes: 6 additions & 10 deletions exp/api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions exp/api/v1alpha4/azuremanagedcontrolplane_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (src *AzureManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {

dst.Spec.AddonProfiles = restored.Spec.AddonProfiles
dst.Status.Conditions = restored.Status.Conditions
dst.Spec.VirtualNetwork.ResourceGroupName = restored.Spec.VirtualNetwork.ResourceGroupName

return nil
}
Expand Down Expand Up @@ -74,3 +75,12 @@ func (dst *AzureManagedControlPlaneList) ConvertFrom(srcRaw conversion.Hub) erro
src := srcRaw.(*infrav1exp.AzureManagedControlPlaneList)
return Convert_v1beta1_AzureManagedControlPlaneList_To_v1alpha4_AzureManagedControlPlaneList(src, dst, nil)
}

// Convert_v1beta1_ManagedControlPlaneVirtualNetwork_To_v1alpha4_ManagedControlPlaneVirtualNetwork converts v1beta1 ManagedControlPlaneVirtualNetwork to v1alpha4 ManagedControlPlaneVirtualNetwork.
func Convert_v1beta1_ManagedControlPlaneVirtualNetwork_To_v1alpha4_ManagedControlPlaneVirtualNetwork(in *infrav1exp.ManagedControlPlaneVirtualNetwork, out *ManagedControlPlaneVirtualNetwork, s apiconversion.Scope) error {
out.Name = in.Name
out.Subnet.Name = in.Subnet.Name
out.Subnet.CIDRBlock = in.Subnet.CIDRBlock
out.CIDRBlock = in.CIDRBlock
return nil
}
16 changes: 6 additions & 10 deletions exp/api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions exp/api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ type ManagedControlPlaneVirtualNetwork struct {
CIDRBlock string `json:"cidrBlock"`
// +optional
Subnet ManagedControlPlaneSubnet `json:"subnet,omitempty"`
// ResourceGroupName is the name of the Azure resource group for the VNet and Subnet.
// +optional
ResourceGroupName string `json:"resourceGroupName,omitempty"`
}

// ManagedControlPlaneSubnet describes a subnet for an AKS cluster.
Expand Down

0 comments on commit 5ddf24b

Please sign in to comment.