Skip to content

Commit

Permalink
Make agent pools reconcile/delete async
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Jul 13, 2022
1 parent fec592c commit d6e6a52
Show file tree
Hide file tree
Showing 12 changed files with 754 additions and 806 deletions.
104 changes: 52 additions & 52 deletions azure/converters/managedagentpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,57 @@ limitations under the License.

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"
)
// 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/services/agentpools"
// )

// AgentPoolToManagedClusterAgentPoolProfile converts a AgentPoolSpec to an Azure SDK ManagedClusterAgentPoolProfile used in managedcluster reconcile.
func AgentPoolToManagedClusterAgentPoolProfile(pool azure.AgentPoolSpec) containerservice.ManagedClusterAgentPoolProfile {
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,
}
}
// // AgentPoolToManagedClusterAgentPoolProfile converts a AgentPoolSpec to an Azure SDK ManagedClusterAgentPoolProfile used in managedcluster reconcile.
// func AgentPoolToManagedClusterAgentPoolProfile(pool agentpools.AgentPoolSpec) containerservice.ManagedClusterAgentPoolProfile {
// 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,
},
}
}
// // AgentPoolToContainerServiceAgentPool converts a AgentPoolSpec to an Azure SDK AgentPool used in agentpool reconcile.
// func AgentPoolToContainerServiceAgentPool(pool agentpools.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,
// },
// }
// }
268 changes: 134 additions & 134 deletions azure/converters/managedagentpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,144 +16,144 @@ limitations under the License.

package converters

import (
"testing"
// import (
// "testing"

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

func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) {
cases := []struct {
name string
pool azure.AgentPoolSpec
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"),
},
Name: "agentpool1",
},
// func Test_AgentPoolToManagedClusterAgentPoolProfile(t *testing.T) {
// cases := []struct {
// name string
// pool azure.AgentPoolSpec
// 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"),
// },
// Name: "agentpool1",
// },

expect: func(g *GomegaWithT, result containerservice.ManagedClusterAgentPoolProfile) {
g.Expect(result).To(Equal(containerservice.ManagedClusterAgentPoolProfile{
Name: to.StringPtr("agentpool1"),
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"),
},
}))
},
},
}
// expect: func(g *GomegaWithT, result containerservice.ManagedClusterAgentPoolProfile) {
// g.Expect(result).To(Equal(containerservice.ManagedClusterAgentPoolProfile{
// Name: to.StringPtr("agentpool1"),
// 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 := AgentPoolToManagedClusterAgentPoolProfile(c.pool)
c.expect(g, result)
})
}
}
// for _, c := range cases {
// c := c
// t.Run(c.name, func(t *testing.T) {
// t.Parallel()
// g := NewGomegaWithT(t)
// result := AgentPoolToManagedClusterAgentPoolProfile(c.pool)
// c.expect(g, result)
// })
// }
// }

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"),
},
},
// 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"),
},
},
}))
},
},
}
// 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)
})
}
}
// 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)
// })
// }
// }
Loading

0 comments on commit d6e6a52

Please sign in to comment.