Skip to content

Commit 725e373

Browse files
authored
Merge pull request #2667 from spectrocloud/support-cross-rg
AKS virtual network static placement for cross RG
2 parents 16ce6e2 + e424fb4 commit 725e373

12 files changed

+221
-23
lines changed

azure/scope/managedcontrolplane.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (s *ManagedControlPlaneScope) Close(ctx context.Context) error {
211211
// Vnet returns the cluster Vnet.
212212
func (s *ManagedControlPlaneScope) Vnet() *infrav1.VnetSpec {
213213
return &infrav1.VnetSpec{
214-
ResourceGroup: s.ControlPlane.Spec.ResourceGroupName,
214+
ResourceGroup: s.ControlPlane.Spec.VirtualNetwork.ResourceGroup,
215215
Name: s.ControlPlane.Spec.VirtualNetwork.Name,
216216
VnetClassSpec: infrav1.VnetClassSpec{
217217
CIDRBlocks: []string{s.ControlPlane.Spec.VirtualNetwork.CIDRBlock},
@@ -424,7 +424,7 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec(ctx context.Context) azure
424424
DNSServiceIP: s.ControlPlane.Spec.DNSServiceIP,
425425
VnetSubnetID: azure.SubnetID(
426426
s.ControlPlane.Spec.SubscriptionID,
427-
s.ControlPlane.Spec.ResourceGroupName,
427+
s.VNetSpec().ResourceGroupName(),
428428
s.ControlPlane.Spec.VirtualNetwork.Name,
429429
s.ControlPlane.Spec.VirtualNetwork.Subnet.Name,
430430
),

azure/scope/managedmachinepool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func buildAgentPoolSpec(managedControlPlane *infrav1exp.AzureManagedControlPlane
165165
OSType: managedMachinePool.Spec.OSType,
166166
VnetSubnetID: azure.SubnetID(
167167
managedControlPlane.Spec.SubscriptionID,
168-
managedControlPlane.Spec.ResourceGroupName,
168+
managedControlPlane.Spec.VirtualNetwork.ResourceGroup,
169169
managedControlPlane.Spec.VirtualNetwork.Name,
170170
managedControlPlane.Spec.VirtualNetwork.Subnet.Name,
171171
),

config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedcontrolplanes.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ spec:
733733
type: string
734734
name:
735735
type: string
736+
resourceGroup:
737+
description: ResourceGroup is the name of the Azure resource group
738+
for the VNet and Subnet.
739+
type: string
736740
subnet:
737741
description: ManagedControlPlaneSubnet describes a subnet for
738742
an AKS cluster.

docs/book/src/topics/managedcluster.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,29 @@ should be fairly clear from context.
175175
| networkPolicy | azure, calico |
176176
177177
178+
### Use an existing Virtual Network to provision an AKS cluster.
179+
180+
If you'd like to deploy your AKS cluster in an existing Virtual Network, but create the cluster itself in a different resource group, you can configure the AzureManagedControlPlane resource with a reference to the existing Virtual Network and subnet. For example:
181+
182+
```yaml
183+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
184+
kind: AzureManagedControlPlane
185+
metadata:
186+
name: my-cluster-control-plane
187+
spec:
188+
location: southcentralus
189+
resourceGroupName: foo-bar
190+
sshPublicKey: ${AZURE_SSH_PUBLIC_KEY_B64:=""}
191+
subscriptionID: 00000000-0000-0000-0000-000000000000 # fake uuid
192+
version: v1.21.2
193+
virtualNetwork:
194+
cidrBlock: 10.0.0.0/8
195+
name: test-vnet
196+
resourceGroup: test-rg
197+
subnet:
198+
cidrBlock: 10.0.2.0/24
199+
name: test-subnet
200+
```
178201
### Multitenancy
179202
180203
Multitenancy for managed clusters can be configured by using `aks-multi-tenancy` flavor. The steps for creating an azure managed identity and mapping it to an `AzureClusterIdentity` are similar to the ones described [here](https://capz.sigs.k8s.io/topics/multitenancy.html).
@@ -451,6 +474,7 @@ Following is the list of immutable fields for managed clusters:
451474
| AzureManagedControlPlane | .spec.networkPolicy | |
452475
| AzureManagedControlPlane | .spec.loadBalancerSKU | |
453476
| AzureManagedControlPlane | .spec.apiServerAccessProfile | except AuthorizedIPRanges |
477+
| AzureManagedControlPlane | .spec.virtualNetwork | |
454478
| AzureManagedMachinePool | .spec.sku | |
455479
| AzureManagedMachinePool | .spec.osDiskSizeGB | |
456480
| AzureManagedMachinePool | .spec.osDiskType | |

exp/api/v1alpha3/azuremanagedcontrolplane_conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (src *AzureManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
4141
dst.Spec.LoadBalancerProfile = restored.Spec.LoadBalancerProfile
4242
dst.Spec.APIServerAccessProfile = restored.Spec.APIServerAccessProfile
4343
dst.Spec.AddonProfiles = restored.Spec.AddonProfiles
44+
dst.Spec.VirtualNetwork.ResourceGroup = restored.Spec.VirtualNetwork.ResourceGroup
4445

4546
dst.Status.LongRunningOperationStates = restored.Status.LongRunningOperationStates
4647
dst.Status.Conditions = restored.Status.Conditions
@@ -81,3 +82,13 @@ func (dst *AzureManagedControlPlaneList) ConvertFrom(srcRaw conversion.Hub) erro
8182
src := srcRaw.(*infrav1exp.AzureManagedControlPlaneList)
8283
return Convert_v1beta1_AzureManagedControlPlaneList_To_v1alpha3_AzureManagedControlPlaneList(src, dst, nil)
8384
}
85+
86+
// Convert_v1beta1_ManagedControlPlaneVirtualNetwork_To_v1alpha3_ManagedControlPlaneVirtualNetwork converts v1beta1 ManagedControlPlaneVirtualNetwork to v1alpha3 ManagedControlPlaneVirtualNetwork.
87+
func Convert_v1beta1_ManagedControlPlaneVirtualNetwork_To_v1alpha3_ManagedControlPlaneVirtualNetwork(in *infrav1exp.ManagedControlPlaneVirtualNetwork, out *ManagedControlPlaneVirtualNetwork, s apiconversion.Scope) error {
88+
out.Name = in.Name
89+
out.Subnet.Name = in.Subnet.Name
90+
out.Subnet.CIDRBlock = in.Subnet.CIDRBlock
91+
out.CIDRBlock = in.CIDRBlock
92+
93+
return nil
94+
}

exp/api/v1alpha3/zz_generated.conversion.go

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/api/v1alpha4/azuremanagedcontrolplane_conversion.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (src *AzureManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
3838

3939
dst.Spec.AddonProfiles = restored.Spec.AddonProfiles
4040
dst.Status.Conditions = restored.Status.Conditions
41+
dst.Spec.VirtualNetwork.ResourceGroup = restored.Spec.VirtualNetwork.ResourceGroup
4142

4243
return nil
4344
}
@@ -74,3 +75,12 @@ func (dst *AzureManagedControlPlaneList) ConvertFrom(srcRaw conversion.Hub) erro
7475
src := srcRaw.(*infrav1exp.AzureManagedControlPlaneList)
7576
return Convert_v1beta1_AzureManagedControlPlaneList_To_v1alpha4_AzureManagedControlPlaneList(src, dst, nil)
7677
}
78+
79+
// Convert_v1beta1_ManagedControlPlaneVirtualNetwork_To_v1alpha4_ManagedControlPlaneVirtualNetwork converts v1beta1 ManagedControlPlaneVirtualNetwork to v1alpha4 ManagedControlPlaneVirtualNetwork.
80+
func Convert_v1beta1_ManagedControlPlaneVirtualNetwork_To_v1alpha4_ManagedControlPlaneVirtualNetwork(in *infrav1exp.ManagedControlPlaneVirtualNetwork, out *ManagedControlPlaneVirtualNetwork, s apiconversion.Scope) error {
81+
out.Name = in.Name
82+
out.Subnet.Name = in.Subnet.Name
83+
out.Subnet.CIDRBlock = in.Subnet.CIDRBlock
84+
out.CIDRBlock = in.CIDRBlock
85+
return nil
86+
}

exp/api/v1alpha4/zz_generated.conversion.go

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exp/api/v1beta1/azuremanagedcontrolplane_default.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func (m *AzureManagedControlPlane) setDefaultVirtualNetwork() {
6060
if m.Spec.VirtualNetwork.CIDRBlock == "" {
6161
m.Spec.VirtualNetwork.CIDRBlock = defaultAKSVnetCIDR
6262
}
63+
if m.Spec.VirtualNetwork.ResourceGroup == "" {
64+
m.Spec.VirtualNetwork.ResourceGroup = m.Spec.ResourceGroupName
65+
}
6366
}
6467

6568
// setDefaultSubnet sets the default Subnet for an AzureManagedControlPlane.

exp/api/v1beta1/azuremanagedcontrolplane_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ type ManagedControlPlaneVirtualNetwork struct {
210210
CIDRBlock string `json:"cidrBlock"`
211211
// +optional
212212
Subnet ManagedControlPlaneSubnet `json:"subnet,omitempty"`
213+
// ResourceGroup is the name of the Azure resource group for the VNet and Subnet.
214+
// +optional
215+
ResourceGroup string `json:"resourceGroup,omitempty"`
213216
}
214217

215218
// ManagedControlPlaneSubnet describes a subnet for an AKS cluster.

0 commit comments

Comments
 (0)