Skip to content

Commit

Permalink
Allow resource group name to be configurable for amcp template
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed May 7, 2024
1 parent 392f7d6 commit 74d7dde
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
4 changes: 0 additions & 4 deletions api/v1beta1/azuremanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ const (
type AzureManagedControlPlaneSpec struct {
AzureManagedControlPlaneClassSpec `json:",inline"`

// ResourceGroupName is the name of the Azure resource group for this AKS Cluster.
// Immutable.
ResourceGroupName string `json:"resourceGroupName"`

// NodeResourceGroupName is the name of the resource group
// containing cluster IaaS resources. Will be populated to default
// in webhook.
Expand Down
38 changes: 20 additions & 18 deletions api/v1beta1/azuremanagedcontrolplane_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ func TestDefaultingWebhook(t *testing.T) {
},
},
},
ResourceGroupName: "fooRg",
SSHPublicKey: ptr.To(""),
SSHPublicKey: ptr.To(""),
},
}
mcpw := &azureManagedControlPlaneWebhook{}
err := mcpw.Default(context.Background(), amcp)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(amcp.Spec.ResourceGroupName).To(Equal("fooCluster"))
g.Expect(amcp.Spec.NetworkPlugin).To(Equal(ptr.To(AzureNetworkPluginName)))
g.Expect(amcp.Spec.LoadBalancerSKU).To(Equal(ptr.To("Standard")))
g.Expect(amcp.Spec.Version).To(Equal("v1.17.5"))
g.Expect(*amcp.Spec.SSHPublicKey).NotTo(BeEmpty())
g.Expect(amcp.Spec.NodeResourceGroupName).To(Equal("MC_fooRg_fooName_fooLocation"))
g.Expect(amcp.Spec.NodeResourceGroupName).To(Equal("MC_fooCluster_fooName_fooLocation"))
g.Expect(amcp.Spec.VirtualNetwork.Name).To(Equal("fooName"))
g.Expect(amcp.Spec.VirtualNetwork.CIDRBlock).To(Equal(defaultAKSVnetCIDR))
g.Expect(amcp.Spec.VirtualNetwork.Subnet.Name).To(Equal("fooName"))
Expand All @@ -87,6 +87,7 @@ func TestDefaultingWebhook(t *testing.T) {
amcp.Spec.NetworkPolicy = &netPol
amcp.Spec.Version = "9.99.99"
amcp.Spec.SSHPublicKey = nil
amcp.Spec.ResourceGroupName = "fooRg"
amcp.Spec.NodeResourceGroupName = "fooNodeRg"
amcp.Spec.VirtualNetwork.Name = "fooVnetName"
amcp.Spec.VirtualNetwork.Subnet.Name = "fooSubnetName"
Expand Down Expand Up @@ -116,6 +117,7 @@ func TestDefaultingWebhook(t *testing.T) {
g.Expect(*amcp.Spec.NetworkPolicy).To(Equal(netPol))
g.Expect(amcp.Spec.Version).To(Equal("v9.99.99"))
g.Expect(amcp.Spec.SSHPublicKey).To(BeNil())
g.Expect(amcp.Spec.ResourceGroupName).To(Equal("fooRg"))
g.Expect(amcp.Spec.NodeResourceGroupName).To(Equal("fooNodeRg"))
g.Expect(amcp.Spec.VirtualNetwork.Name).To(Equal("fooVnetName"))
g.Expect(amcp.Spec.VirtualNetwork.Subnet.Name).To(Equal("fooSubnetName"))
Expand All @@ -142,6 +144,7 @@ func TestDefaultingWebhook(t *testing.T) {
},
Spec: AzureManagedControlPlaneSpec{
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
ResourceGroupName: "fooRg",
Location: "fooLocation",
Version: "1.17.5",
NetworkPluginMode: ptr.To(NetworkPluginModeOverlay),
Expand All @@ -160,8 +163,7 @@ func TestDefaultingWebhook(t *testing.T) {
},
},
},
ResourceGroupName: "fooRg",
SSHPublicKey: ptr.To(""),
SSHPublicKey: ptr.To(""),
},
}
err = mcpw.Default(context.Background(), amcp)
Expand Down Expand Up @@ -1991,19 +1993,19 @@ func TestAzureManagedControlPlane_ValidateUpdate(t *testing.T) {
oldAMCP: &AzureManagedControlPlane{
Spec: AzureManagedControlPlaneSpec{
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
DNSServiceIP: ptr.To("192.168.0.10"),
Version: "v1.18.0",
DNSServiceIP: ptr.To("192.168.0.10"),
Version: "v1.18.0",
ResourceGroupName: "hello-1",
},
ResourceGroupName: "hello-1",
},
},
amcp: &AzureManagedControlPlane{
Spec: AzureManagedControlPlaneSpec{
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
DNSServiceIP: ptr.To("192.168.0.10"),
Version: "v1.18.0",
DNSServiceIP: ptr.To("192.168.0.10"),
Version: "v1.18.0",
ResourceGroupName: "hello-2",
},
ResourceGroupName: "hello-2",
},
},
wantErr: true,
Expand Down Expand Up @@ -4054,8 +4056,8 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
},
},
Spec: AzureManagedControlPlaneSpec{
ResourceGroupName: "rg1",
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
ResourceGroupName: "rg1",
VirtualNetwork: ManagedControlPlaneVirtualNetwork{
ResourceGroup: "rg1",
Name: "vnet1",
Expand All @@ -4082,8 +4084,8 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
},
},
Spec: AzureManagedControlPlaneSpec{
ResourceGroupName: "rg1",
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
ResourceGroupName: "rg1",
VirtualNetwork: ManagedControlPlaneVirtualNetwork{
ResourceGroup: "rg2",
Name: "vnet1",
Expand All @@ -4110,8 +4112,8 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
},
},
Spec: AzureManagedControlPlaneSpec{
ResourceGroupName: "rg1",
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
ResourceGroupName: "rg1",
VirtualNetwork: ManagedControlPlaneVirtualNetwork{
ResourceGroup: "rg2",
Name: "vnet1",
Expand All @@ -4138,8 +4140,8 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
},
},
Spec: AzureManagedControlPlaneSpec{
ResourceGroupName: "rg1",
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
ResourceGroupName: "rg1",
VirtualNetwork: ManagedControlPlaneVirtualNetwork{
ResourceGroup: "rg2",
Name: "vnet1",
Expand All @@ -4165,8 +4167,8 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
},
},
Spec: AzureManagedControlPlaneSpec{
ResourceGroupName: "rg1",
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
ResourceGroupName: "rg1",
VirtualNetwork: ManagedControlPlaneVirtualNetwork{
ResourceGroup: "rg2",
Name: "vnet1",
Expand All @@ -4192,8 +4194,8 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
},
},
Spec: AzureManagedControlPlaneSpec{
ResourceGroupName: "rg1",
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
ResourceGroupName: "rg1",
VirtualNetwork: ManagedControlPlaneVirtualNetwork{
ResourceGroup: "rg2",
Name: "vnet1",
Expand All @@ -4220,8 +4222,8 @@ func TestValidateAMCPVirtualNetwork(t *testing.T) {
},
},
Spec: AzureManagedControlPlaneSpec{
ResourceGroupName: "rg1",
AzureManagedControlPlaneClassSpec: AzureManagedControlPlaneClassSpec{
ResourceGroupName: "rg1",
VirtualNetwork: ManagedControlPlaneVirtualNetwork{
ResourceGroup: "rg2",
Name: "vnet1",
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/types_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ type AzureManagedControlPlaneClassSpec struct {
// +optional
MachineTemplate *AzureManagedControlPlaneTemplateMachineTemplate `json:"machineTemplate,omitempty"`

// ResourceGroupName is the name of the Azure resource group for this AKS Cluster.
// Immutable.
ResourceGroupName string `json:"resourceGroupName"`

// Version defines the desired Kubernetes version.
// +kubebuilder:validation:MinLength:=2
Version string `json:"version"`
Expand Down
8 changes: 4 additions & 4 deletions azure/scope/managedcontrolplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1638,8 +1638,8 @@ func TestManagedControlPlaneScope_GroupSpecs(t *testing.T) {
},
ControlPlane: &infrav1.AzureManagedControlPlane{
Spec: infrav1.AzureManagedControlPlaneSpec{
ResourceGroupName: "dummy-rg",
AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{
ResourceGroupName: "dummy-rg",
VirtualNetwork: infrav1.ManagedControlPlaneVirtualNetwork{
ResourceGroup: "different-rg",
},
Expand Down Expand Up @@ -1674,8 +1674,8 @@ func TestManagedControlPlaneScope_GroupSpecs(t *testing.T) {
},
ControlPlane: &infrav1.AzureManagedControlPlane{
Spec: infrav1.AzureManagedControlPlaneSpec{
ResourceGroupName: "dummy-rg",
AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{
ResourceGroupName: "dummy-rg",
VirtualNetwork: infrav1.ManagedControlPlaneVirtualNetwork{
ResourceGroup: "dummy-rg",
},
Expand Down Expand Up @@ -1704,8 +1704,8 @@ func TestManagedControlPlaneScope_GroupSpecs(t *testing.T) {
},
ControlPlane: &infrav1.AzureManagedControlPlane{
Spec: infrav1.AzureManagedControlPlaneSpec{
ResourceGroupName: "dummy-rg",
AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{
ResourceGroupName: "dummy-rg",
VirtualNetwork: infrav1.ManagedControlPlaneVirtualNetwork{
Name: "vnet1",
},
Expand Down Expand Up @@ -1734,8 +1734,8 @@ func TestManagedControlPlaneScope_GroupSpecs(t *testing.T) {
},
ControlPlane: &infrav1.AzureManagedControlPlane{
Spec: infrav1.AzureManagedControlPlaneSpec{
ResourceGroupName: "dummy-rg",
AzureManagedControlPlaneClassSpec: infrav1.AzureManagedControlPlaneClassSpec{
ResourceGroupName: "dummy-rg",
VirtualNetwork: infrav1.ManagedControlPlaneVirtualNetwork{
ResourceGroup: "my_custom_rg",
Name: "vnet1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ spec:
- userAssignedNATGateway
- userDefinedRouting
type: string
resourceGroupName:
description: |-
ResourceGroupName is the name of the Azure resource group for this AKS Cluster.
Immutable.
type: string
securityProfile:
description: SecurityProfile defines the security profile
for cluster.
Expand Down Expand Up @@ -860,6 +865,7 @@ spec:
required:
- identityRef
- location
- resourceGroupName
- version
type: object
required:
Expand Down
2 changes: 1 addition & 1 deletion controllers/azuremanagedcontrolplane_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func TestAzureManagedControlPlaneReconcilePaused(t *testing.T) {
Namespace: "default",
Kind: "AzureClusterIdentity",
},
ResourceGroupName: name,
},
ResourceGroupName: name,
},
}
g.Expect(c.Create(ctx, instance)).To(Succeed())
Expand Down

0 comments on commit 74d7dde

Please sign in to comment.