Skip to content

Commit

Permalink
Merge pull request #2479 from Jont828/async-agentpools
Browse files Browse the repository at this point in the history
Make agent pools reconcile/delete async
  • Loading branch information
k8s-ci-robot authored Aug 30, 2022
2 parents 85c1951 + 6d11cb6 commit 6365d2e
Show file tree
Hide file tree
Showing 17 changed files with 1,391 additions and 917 deletions.
66 changes: 20 additions & 46 deletions azure/converters/managedagentpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,29 @@ package converters

import (
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2021-05-01/containerservice"
"github.com/Azure/go-autorest/autorest/to"
"sigs.k8s.io/cluster-api-provider-azure/azure"
)

// AgentPoolToManagedClusterAgentPoolProfile converts a AgentPoolSpec to an Azure SDK ManagedClusterAgentPoolProfile used in managedcluster reconcile.
func AgentPoolToManagedClusterAgentPoolProfile(pool azure.AgentPoolSpec) containerservice.ManagedClusterAgentPoolProfile {
func AgentPoolToManagedClusterAgentPoolProfile(pool containerservice.AgentPool) containerservice.ManagedClusterAgentPoolProfile {
properties := pool.ManagedClusterAgentPoolProfileProperties
return containerservice.ManagedClusterAgentPoolProfile{
Name: &pool.Name,
VMSize: &pool.SKU,
OsType: containerservice.OSType(to.String(pool.OSType)),
OsDiskSizeGB: &pool.OSDiskSizeGB,
Count: &pool.Replicas,
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
OrchestratorVersion: pool.Version,
VnetSubnetID: &pool.VnetSubnetID,
Mode: containerservice.AgentPoolMode(pool.Mode),
EnableAutoScaling: pool.EnableAutoScaling,
MaxCount: pool.MaxCount,
MinCount: pool.MinCount,
NodeTaints: &pool.NodeTaints,
AvailabilityZones: &pool.AvailabilityZones,
MaxPods: pool.MaxPods,
OsDiskType: containerservice.OSDiskType(to.String(pool.OsDiskType)),
NodeLabels: pool.NodeLabels,
EnableUltraSSD: pool.EnableUltraSSD,
}
}

// AgentPoolToContainerServiceAgentPool converts a AgentPoolSpec to an Azure SDK AgentPool used in agentpool reconcile.
func AgentPoolToContainerServiceAgentPool(pool azure.AgentPoolSpec) containerservice.AgentPool {
return containerservice.AgentPool{
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
VMSize: &pool.SKU,
OsType: containerservice.OSType(to.String(pool.OSType)),
OsDiskSizeGB: &pool.OSDiskSizeGB,
Count: &pool.Replicas,
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
OrchestratorVersion: pool.Version,
VnetSubnetID: &pool.VnetSubnetID,
Mode: containerservice.AgentPoolMode(pool.Mode),
EnableAutoScaling: pool.EnableAutoScaling,
MaxCount: pool.MaxCount,
MinCount: pool.MinCount,
NodeTaints: &pool.NodeTaints,
AvailabilityZones: &pool.AvailabilityZones,
MaxPods: pool.MaxPods,
OsDiskType: containerservice.OSDiskType(to.String(pool.OsDiskType)),
NodeLabels: pool.NodeLabels,
EnableUltraSSD: pool.EnableUltraSSD,
},
Name: pool.Name, // Note: if converting from agentPoolSpec.Parameters(), this field will not be set
VMSize: properties.VMSize,
OsType: properties.OsType,
OsDiskSizeGB: properties.OsDiskSizeGB,
Count: properties.Count,
Type: properties.Type,
OrchestratorVersion: properties.OrchestratorVersion,
VnetSubnetID: properties.VnetSubnetID,
Mode: properties.Mode,
EnableAutoScaling: properties.EnableAutoScaling,
MaxCount: properties.MaxCount,
MinCount: properties.MinCount,
NodeTaints: properties.NodeTaints,
AvailabilityZones: properties.AvailabilityZones,
MaxPods: properties.MaxPods,
OsDiskType: properties.OsDiskType,
NodeLabels: properties.NodeLabels,
EnableUltraSSD: properties.EnableUltraSSD,
}
}
108 changes: 22 additions & 86 deletions azure/converters/managedagentpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,33 @@ import (
func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) {
cases := []struct {
name string
pool azure.AgentPoolSpec
pool containerservice.AgentPool
expect func(*GomegaWithT, containerservice.ManagedClusterAgentPoolProfile)
}{
{
name: "Should set all values correctly",
pool: azure.AgentPoolSpec{
SKU: "Standard_D2s_v3",
OSDiskSizeGB: 100,
Replicas: 2,
OSType: to.StringPtr(azure.LinuxOS),
Version: to.StringPtr("1.22.6"),
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
Mode: "User",
EnableAutoScaling: to.BoolPtr(true),
MaxCount: to.Int32Ptr(5),
MinCount: to.Int32Ptr(2),
NodeTaints: []string{"key1=value1:NoSchedule"},
AvailabilityZones: []string{"zone1"},
MaxPods: to.Int32Ptr(60),
OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeManaged)),
NodeLabels: map[string]*string{
"custom": to.StringPtr("default"),
pool: containerservice.AgentPool{
Name: to.StringPtr("agentpool1"),
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
VMSize: to.StringPtr("Standard_D2s_v3"),
OsType: azure.LinuxOS,
OsDiskSizeGB: to.Int32Ptr(100),
Count: to.Int32Ptr(2),
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
OrchestratorVersion: to.StringPtr("1.22.6"),
VnetSubnetID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123"),
Mode: containerservice.AgentPoolModeUser,
EnableAutoScaling: to.BoolPtr(true),
MaxCount: to.Int32Ptr(5),
MinCount: to.Int32Ptr(2),
NodeTaints: to.StringSlicePtr([]string{"key1=value1:NoSchedule"}),
AvailabilityZones: to.StringSlicePtr([]string{"zone1"}),
MaxPods: to.Int32Ptr(60),
OsDiskType: containerservice.OSDiskTypeManaged,
NodeLabels: map[string]*string{
"custom": to.StringPtr("default"),
},
},
Name: "agentpool1",
},

expect: func(g *GomegaWithT, result containerservice.ManagedClusterAgentPoolProfile) {
Expand Down Expand Up @@ -90,70 +93,3 @@ func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) {
})
}
}

func Test_AgentPoolToAgentPoolToContainerServiceAgentPool(t *testing.T) {
cases := []struct {
name string
pool azure.AgentPoolSpec
expect func(*GomegaWithT, containerservice.AgentPool)
}{
{
name: "Should set all values correctly",
pool: azure.AgentPoolSpec{
Name: "agentpool1",
SKU: "Standard_D2s_v3",
OSDiskSizeGB: 100,
OSType: to.StringPtr(azure.LinuxOS),
Replicas: 2,
Version: to.StringPtr("1.22.6"),
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123",
Mode: "User",
EnableAutoScaling: to.BoolPtr(true),
MaxCount: to.Int32Ptr(5),
MinCount: to.Int32Ptr(2),
NodeTaints: []string{"key1=value1:NoSchedule"},
AvailabilityZones: []string{"zone1"},
MaxPods: to.Int32Ptr(60),
OsDiskType: to.StringPtr(string(containerservice.OSDiskTypeManaged)),
NodeLabels: map[string]*string{
"custom": to.StringPtr("default"),
},
},

expect: func(g *GomegaWithT, result containerservice.AgentPool) {
g.Expect(result).To(Equal(containerservice.AgentPool{
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
VMSize: to.StringPtr("Standard_D2s_v3"),
OsType: azure.LinuxOS,
OsDiskSizeGB: to.Int32Ptr(100),
Count: to.Int32Ptr(2),
Type: containerservice.AgentPoolTypeVirtualMachineScaleSets,
OrchestratorVersion: to.StringPtr("1.22.6"),
VnetSubnetID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-123/providers/Microsoft.Network/virtualNetworks/vnet-123/subnets/subnet-123"),
Mode: containerservice.AgentPoolModeUser,
EnableAutoScaling: to.BoolPtr(true),
MaxCount: to.Int32Ptr(5),
MinCount: to.Int32Ptr(2),
NodeTaints: to.StringSlicePtr([]string{"key1=value1:NoSchedule"}),
AvailabilityZones: to.StringSlicePtr([]string{"zone1"}),
MaxPods: to.Int32Ptr(60),
OsDiskType: containerservice.OSDiskTypeManaged,
NodeLabels: map[string]*string{
"custom": to.StringPtr("default"),
},
},
}))
},
},
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
g := NewGomegaWithT(t)
result := AgentPoolToContainerServiceAgentPool(c.pool)
c.expect(g, result)
})
}
}
6 changes: 3 additions & 3 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec(ctx context.Context) azure
}

// GetAllAgentPoolSpecs gets a slice of azure.AgentPoolSpec for the list of agent pools.
func (s *ManagedControlPlaneScope) GetAllAgentPoolSpecs() ([]azure.AgentPoolSpec, error) {
func (s *ManagedControlPlaneScope) GetAllAgentPoolSpecs() ([]azure.ResourceSpecGetter, error) {
var (
ammps = make([]azure.AgentPoolSpec, 0, len(s.ManagedMachinePools))
ammps = make([]azure.ResourceSpecGetter, 0, len(s.ManagedMachinePools))
foundSystemPool = false
)
for _, pool := range s.ManagedMachinePools {
Expand All @@ -515,7 +515,7 @@ func (s *ManagedControlPlaneScope) GetAllAgentPoolSpecs() ([]azure.AgentPoolSpec
foundSystemPool = true
}

ammp := buildAgentPoolSpec(s.ControlPlane, pool.MachinePool, pool.InfraMachinePool)
ammp := buildAgentPoolSpec(s.ControlPlane, pool.MachinePool, pool.InfraMachinePool, pool.InfraMachinePool.Annotations)
ammps = append(ammps, ammp)
}

Expand Down
26 changes: 16 additions & 10 deletions azure/scope/managedcontrolplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/agentpools"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/managedclusters"
infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand All @@ -41,7 +42,7 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) {
cases := []struct {
Name string
Input ManagedControlPlaneScopeParams
Expected []azure.AgentPoolSpec
Expected []azure.ResourceSpecGetter
Err string
}{
{
Expand Down Expand Up @@ -72,14 +73,15 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) {
},
},
},
Expected: []azure.AgentPoolSpec{
{
Expected: []azure.ResourceSpecGetter{
&agentpools.AgentPoolSpec{
Name: "pool0",
SKU: "Standard_D2s_v3",
Replicas: 1,
Mode: "System",
Cluster: "cluster1",
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
Headers: map[string]string{},
},
},
},
Expand Down Expand Up @@ -112,15 +114,16 @@ func TestManagedControlPlaneScope_PoolVersion(t *testing.T) {
},
},
},
Expected: []azure.AgentPoolSpec{
{
Expected: []azure.ResourceSpecGetter{
&agentpools.AgentPoolSpec{
Name: "pool0",
SKU: "Standard_D2s_v3",
Mode: "System",
Replicas: 1,
Version: to.StringPtr("1.21.1"),
Cluster: "cluster1",
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
Headers: map[string]string{},
},
},
},
Expand Down Expand Up @@ -276,7 +279,7 @@ func TestManagedControlPlaneScope_OSType(t *testing.T) {
cases := []struct {
Name string
Input ManagedControlPlaneScopeParams
Expected []azure.AgentPoolSpec
Expected []azure.ResourceSpecGetter
Err string
}{
{
Expand Down Expand Up @@ -316,32 +319,35 @@ func TestManagedControlPlaneScope_OSType(t *testing.T) {
},
},
},
Expected: []azure.AgentPoolSpec{
{
Expected: []azure.ResourceSpecGetter{
&agentpools.AgentPoolSpec{
Name: "pool0",
SKU: "Standard_D2s_v3",
Mode: "System",
Replicas: 1,
Cluster: "cluster1",
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
Headers: map[string]string{},
},
{
&agentpools.AgentPoolSpec{
Name: "pool1",
SKU: "Standard_D2s_v3",
Mode: "User",
Replicas: 1,
Cluster: "cluster1",
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
OSType: to.StringPtr(azure.LinuxOS),
Headers: map[string]string{},
},
{
&agentpools.AgentPoolSpec{
Name: "pool2",
SKU: "Standard_D2s_v3",
Mode: "User",
Replicas: 1,
Cluster: "cluster1",
VnetSubnetID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups//providers/Microsoft.Network/virtualNetworks//subnets/",
OSType: to.StringPtr(azure.WindowsOS),
Headers: map[string]string{},
},
},
},
Expand Down
Loading

0 comments on commit 6365d2e

Please sign in to comment.