Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ MOCKGEN_VER := v0.4.0
MOCKGEN_BIN := mockgen
MOCKGEN := $(BIN_DIR)/$(MOCKGEN_BIN)-$(MOCKGEN_VER)

GINKGO_VER := v2.22.0
GINKGO_VER := v2.22.2
GINKGO_BIN := ginkgo
GINKGO := $(BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER)

Expand Down
40 changes: 40 additions & 0 deletions pkg/aks/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,43 @@ func generateUniqueLogWorkspace(workspaceName string) string {
shaString := fmt.Sprintf("%x", hexHash)
return fmt.Sprintf("%s-%s", s, shaString[0:16])
}

var aksRegionsWithAzSupport = map[string]bool{
"australiaeast": true,
"brazilsouth": true,
"canadacentral": true,
"centralindia": true,
"chinanorth3": true,
"centralus": true,
"eastasia": true,
"eastus": true,
"eastus2": true,
"eastus2euap": true,
"francecentral": true,
"germanywestcentral": true,
"israelcentral": true,
"italynorth": true,
"japaneast": true,
"koreacentral": true,
"mexicocentral": true,
"newzealandnorth": true,
"northeurope": true,
"norwayeast": true,
"polandcentral": true,
"qatarcentral": true,
"southafricanorth": true,
"southcentralus": true,
"southeastasia": true,
"spaincentral": true,
"swedencentral": true,
"switzerlandnorth": true,
"uaenorth": true,
"uksouth": true,
"westeurope": true,
"westus2": true,
"westus3": true,
}

func CheckAvailabilityZonesSupport(location string) bool {
return aksRegionsWithAzSupport[location]
}
17 changes: 17 additions & 0 deletions pkg/aks/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,20 @@ var _ = Describe("CheckLogAnalyticsWorkspaceForMonitoring", func() {
Expect(err).To(HaveOccurred())
})
})

var _ = Describe("CheckAvailabilityZonesSupport", func() {
var (
locationWithAZ = "eastus"
locationWithoutAZ = "westus"
)

It("should success for region with availability zones", func() {
result := CheckAvailabilityZonesSupport(locationWithAZ)
Expect(result).To(BeTrue())
})

It("should fail for region with availability zones", func() {
result := CheckAvailabilityZonesSupport(locationWithoutAZ)
Expect(result).To(BeFalse())
})
})
6 changes: 6 additions & 0 deletions pkg/aks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func createManagedCluster(ctx context.Context, cred *Credentials, workplacesClie
agentProfile.OrchestratorVersion = np.OrchestratorVersion
}
if np.AvailabilityZones != nil && len(*np.AvailabilityZones) > 0 {
if !CheckAvailabilityZonesSupport(spec.ResourceLocation) {
return nil, fmt.Errorf("availability zones are not supported in region %s", spec.ResourceLocation)
}
agentProfile.AvailabilityZones = utils.ConvertToSliceOfPointers(np.AvailabilityZones)
}

Expand Down Expand Up @@ -306,6 +309,9 @@ func createManagedCluster(ctx context.Context, cred *Credentials, workplacesClie
// CreateOrUpdateAgentPool creates a new pool(s) in AKS. If one already exists it updates the upstream node pool with
// any provided updates.
func CreateOrUpdateAgentPool(ctx context.Context, agentPoolClient services.AgentPoolsClientInterface, spec *aksv1.AKSClusterConfigSpec, np *aksv1.AKSNodePool) error {
if np.AvailabilityZones != nil && len(*np.AvailabilityZones) > 0 && !CheckAvailabilityZonesSupport(spec.ResourceLocation) {
return fmt.Errorf("availability zones are not supported in region %s", spec.ResourceLocation)
}
agentProfile := &armcontainerservice.ManagedClusterAgentPoolProfileProperties{
Count: np.Count,
MaxPods: np.MaxPods,
Expand Down
12 changes: 12 additions & 0 deletions pkg/aks/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ var _ = Describe("newManagedCluster", func() {
},
}, nil)
clusterSpec.ResourceLocation = "chinaeast"
clusterSpec.NodePools[0].AvailabilityZones = nil
managedCluster, err := createManagedCluster(ctx, cred, workplacesClientMock, clusterSpec, "test-phase")
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -394,6 +395,12 @@ var _ = Describe("newManagedCluster", func() {
Expect(err).To(HaveOccurred())
})

It("should fail for region without availibility zones", func() {
clusterSpec.ResourceLocation = "westus"
_, err := createManagedCluster(ctx, cred, workplacesClientMock, clusterSpec, "test-phase")
Expect(err).To(HaveOccurred())
})

It("should successfully create managed cluster with custom node resource group name", func() {
clusterSpec.NodeResourceGroup = to.Ptr("test-node-resource-group-name")
workplacesClientMock.EXPECT().Get(ctx, String(clusterSpec.LogAnalyticsWorkspaceGroup), String(clusterSpec.LogAnalyticsWorkspaceName), nil).
Expand Down Expand Up @@ -545,6 +552,11 @@ var _ = Describe("CreateOrUpdateAgentPool", func() {

Expect(CreateOrUpdateAgentPool(ctx, agentPoolClientMock, clusterSpec, nodePoolSpec)).ToNot(Succeed())
})

It("should fail for region without avaibility zones", func() {
clusterSpec.ResourceLocation = "westus"
Expect(CreateOrUpdateAgentPool(ctx, agentPoolClientMock, clusterSpec, nodePoolSpec)).ToNot(Succeed())
})
})

func newTestClusterSpec() *aksv1.AKSClusterConfigSpec {
Expand Down
Loading