diff --git a/Makefile b/Makefile index d671f12d..89b23fc4 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/pkg/aks/check.go b/pkg/aks/check.go index 33ecd39c..ff8576c4 100644 --- a/pkg/aks/check.go +++ b/pkg/aks/check.go @@ -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] +} diff --git a/pkg/aks/check_test.go b/pkg/aks/check_test.go index a2584246..4ba60bd5 100644 --- a/pkg/aks/check_test.go +++ b/pkg/aks/check_test.go @@ -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()) + }) +}) diff --git a/pkg/aks/create.go b/pkg/aks/create.go index 03765052..8bbfe007 100644 --- a/pkg/aks/create.go +++ b/pkg/aks/create.go @@ -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) } @@ -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, diff --git a/pkg/aks/create_test.go b/pkg/aks/create_test.go index 2e246e4c..8a2b787c 100644 --- a/pkg/aks/create_test.go +++ b/pkg/aks/create_test.go @@ -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()) @@ -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). @@ -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 {