Procházet zdrojové kódy

support resource slider for azure (#4115)

d-g-town před 2 roky
rodič
revize
0887d14d97

+ 235 - 204
dashboard/src/components/azureUtils.ts

@@ -1,215 +1,246 @@
 // These locations are the regions where the default system and monitoring sku types are available (last checked 12/19/2023)
 export const AzureLocationOptions = [
-    { value: "australiaeast", label: "Australia East" },
-    { value: "brazilsouth", label: "Brazil South" },
-    { value: "canadacentral", label: "Canada Central" },
-    { value: "centralindia", label: "Central India" },
-    { value: "centralus", label: "Central US" },
-    { value: "eastasia", label: "East Asia" },
-    { value: "eastus", label: "East US" },
-    { value: "eastus2", label: "East US 2" },
-    { value: "francecentral", label: "France Central" },
-    { value: "northeurope", label: "North Europe" },
-    { value: "norwayeast", label: "Norway East" },
-    { value: "southafricanorth", label: "South Africa North" },
-    { value: "southcentralus", label: "South Central US" },
-    { value: "swedencentral", label: "Sweden Central" },
-    { value: "switzerlandnorth", label: "Switzerland North" },
-    { value: "uaenorth", label: "UAE North" },
-    { value: "uksouth", label: "UK South" },
-    { value: "westeurope", label: "West Europe" },
-    { value: "westus2", label: "West US 2" },
-    { value: "westus3", label: "West US 3" },
+  { value: "australiaeast", label: "Australia East" },
+  { value: "brazilsouth", label: "Brazil South" },
+  { value: "canadacentral", label: "Canada Central" },
+  { value: "centralindia", label: "Central India" },
+  { value: "centralus", label: "Central US" },
+  { value: "eastasia", label: "East Asia" },
+  { value: "eastus", label: "East US" },
+  { value: "eastus2", label: "East US 2" },
+  { value: "francecentral", label: "France Central" },
+  { value: "northeurope", label: "North Europe" },
+  { value: "norwayeast", label: "Norway East" },
+  { value: "southafricanorth", label: "South Africa North" },
+  { value: "southcentralus", label: "South Central US" },
+  { value: "swedencentral", label: "Sweden Central" },
+  { value: "switzerlandnorth", label: "Switzerland North" },
+  { value: "uaenorth", label: "UAE North" },
+  { value: "uksouth", label: "UK South" },
+  { value: "westeurope", label: "West Europe" },
+  { value: "westus2", label: "West US 2" },
+  { value: "westus3", label: "West US 3" },
 ];
 
 export type MachineTypeOption = {
-    value: string;
-    label: string;
-    supportedRegions: Set<string>;
+  value: string;
+  label: string;
+  supportedRegions: Set<string>;
 };
 
-export const azureSupportedMachineTypes = (region: string): MachineTypeOption[] => {
-    return AzureMachineTypeOptions.filter((option) => option.supportedRegions.has(region));
-}
+export const azureSupportedMachineTypes = (
+  region: string
+): MachineTypeOption[] => {
+  return AzureMachineTypeOptions.filter((option) =>
+    option.supportedRegions.has(region)
+  );
+};
 
 // Retrieve updated list of supported regions by running the following command: az vm list-skus --all --output table | grep <INSTANCE_TYPE> | grep 1,2,3 | grep None | awk '{print "\047" tolower($2) "\047"}' | paste -s -d, -
 // last updated 12/19/2020
 const AzureMachineTypeOptions: MachineTypeOption[] = [
-    {
-        value: "Standard_B2als_v2",
-        label: "Standard_B2als_v2",
-        supportedRegions: new Set<string>([
-            "australiaeast",
-            "brazilsouth",
-            "canadacentral",
-            "centralindia",
-            "centralus",
-            "eastasia",
-            "eastus",
-            "eastus2",
-            "francecentral",
-            "northeurope",
-            "norwayeast",
-            "southafricanorth",
-            "southcentralus",
-            "southeastasia",
-            "swedencentral",
-            "switzerlandnorth",
-            "uaenorth",
-            "uksouth",
-            "westeurope",
-            "westus2",
-            "westus3",
-        ]),
-    },
-    {
-        value: "Standard_B2as_v2",
-        label: "Standard_B2as_v2",
-        supportedRegions: new Set<string>([
-            "australiaeast",
-            "brazilsouth",
-            "canadacentral",
-            "centralindia",
-            "centralus",
-            "eastasia",
-            "eastus",
-            "eastus2",
-            "francecentral",
-            "northeurope",
-            "norwayeast",
-            "southafricanorth",
-            "southcentralus",
-            "southeastasia",
-            "swedencentral",
-            "switzerlandnorth",
-            "uaenorth",
-            "uksouth",
-            "westeurope",
-            "westus2",
-            "westus3",
-        ]),
-    },
-    {
-        value: "Standard_A2_v2",
-        label: "Standard_A2_v2",
-        supportedRegions: new Set<string>([
-            "australiaeast",
-            "canadacentral",
-            "centralindia",
-            "eastasia",
-            "eastus",
-            "eastus2",
-            "francecentral",
-            "germanywestcentral",
-            "israelcentral",
-            "italynorth",
-            "northeurope",
-            "norwayeast",
-            "polandcentral",
-            "southafricanorth",
-            "swedencentral",
-            "switzerlandnorth",
-            "uaenorth",
-            "uksouth",
-        ]),
-    },
-    {
-        value: "Standard_A4_v2",
-        label: "Standard_A4_v2",
-        supportedRegions: new Set<string>([
-            "australiaeast",
-            "canadacentral",
-            "centralindia",
-            "eastasia",
-            "eastus",
-            "eastus2",
-            "francecentral",
-            "germanywestcentral",
-            "israelcentral",
-            "italynorth",
-            "northeurope",
-            "norwayeast",
-            "polandcentral",
-            "southafricanorth",
-            "swedencentral",
-            "switzerlandnorth",
-            "uaenorth",
-            "uksouth",
-        ]),
-    },
-    {
-        value: "Standard_DS1_v2",
-        label: "Standard_DS1_v2",
-        supportedRegions: new Set<string>([
-            "australiaeast",
-            "canadacentral",
-            "centralindia",
-            "eastasia",
-            "eastus",
-            "eastus2",
-            "francecentral",
-            "germanywestcentral",
-            "israelcentral",
-            "italynorth",
-            "northeurope",
-            "norwayeast",
-            "polandcentral",
-            "southafricanorth",
-            "swedencentral",
-            "switzerlandnorth",
-            "uaenorth",
-            "uksouth",
-        ]),
-    },
-    {
-        value: "Standard_DS2_v2",
-        label: "Standard_DS2_v2",
-        supportedRegions: new Set<string>([
-            "australiaeast",
-            "canadacentral",
-            "centralindia",
-            "eastasia",
-            "eastus",
-            "eastus2",
-            "francecentral",
-            "germanywestcentral",
-            "israelcentral",
-            "italynorth",
-            "northeurope",
-            "norwayeast",
-            "polandcentral",
-            "southafricanorth",
-            "swedencentral",
-            "switzerlandnorth",
-            "uaenorth",
-            "uksouth",
-            "eastus2euap",
-            "israelcentral",
-            "italynorth",
-            "polandcentral",
-            "qatarcentral",
-            "swedencentral",
-            "switzerlandnorth",
-            "westus3",
-        ]),
-    },
-    {
-        value: "Standard_D2ads_v5",
-        label: "Standard_D2ads_v5",
-        supportedRegions: new Set<string>([
-            "australiaeast",
-            "canadacentral",
-            "centralindia",
-            "eastasia",
-            "eastus",
-            "koreacentral",
-            "northeurope",
-            "norwayeast",
-            "southafricanorth",
-            "swedencentral",
-            "uaenorth",
-            "uksouth",
-            "westus3",
-        ]),
-    },
-];
+  {
+    value: "Standard_B2als_v2",
+    label: "Standard_B2als_v2",
+    supportedRegions: new Set<string>([
+      "australiaeast",
+      "brazilsouth",
+      "canadacentral",
+      "centralindia",
+      "centralus",
+      "eastasia",
+      "eastus",
+      "eastus2",
+      "francecentral",
+      "northeurope",
+      "norwayeast",
+      "southafricanorth",
+      "southcentralus",
+      "southeastasia",
+      "swedencentral",
+      "switzerlandnorth",
+      "uaenorth",
+      "uksouth",
+      "westeurope",
+      "westus2",
+      "westus3",
+    ]),
+  },
+  {
+    value: "Standard_B2as_v2",
+    label: "Standard_B2as_v2",
+    supportedRegions: new Set<string>([
+      "australiaeast",
+      "brazilsouth",
+      "canadacentral",
+      "centralindia",
+      "centralus",
+      "eastasia",
+      "eastus",
+      "eastus2",
+      "francecentral",
+      "northeurope",
+      "norwayeast",
+      "southafricanorth",
+      "southcentralus",
+      "southeastasia",
+      "swedencentral",
+      "switzerlandnorth",
+      "uaenorth",
+      "uksouth",
+      "westeurope",
+      "westus2",
+      "westus3",
+    ]),
+  },
+  {
+    value: "Standard_A2_v2",
+    label: "Standard_A2_v2",
+    supportedRegions: new Set<string>([
+      "australiaeast",
+      "canadacentral",
+      "centralindia",
+      "eastasia",
+      "eastus",
+      "eastus2",
+      "francecentral",
+      "germanywestcentral",
+      "israelcentral",
+      "italynorth",
+      "northeurope",
+      "norwayeast",
+      "polandcentral",
+      "southafricanorth",
+      "swedencentral",
+      "switzerlandnorth",
+      "uaenorth",
+      "uksouth",
+    ]),
+  },
+  {
+    value: "Standard_A4_v2",
+    label: "Standard_A4_v2",
+    supportedRegions: new Set<string>([
+      "australiaeast",
+      "canadacentral",
+      "centralindia",
+      "eastasia",
+      "eastus",
+      "eastus2",
+      "francecentral",
+      "germanywestcentral",
+      "israelcentral",
+      "italynorth",
+      "northeurope",
+      "norwayeast",
+      "polandcentral",
+      "southafricanorth",
+      "swedencentral",
+      "switzerlandnorth",
+      "uaenorth",
+      "uksouth",
+    ]),
+  },
+  {
+    value: "Standard_DS1_v2",
+    label: "Standard_DS1_v2",
+    supportedRegions: new Set<string>([
+      "australiaeast",
+      "canadacentral",
+      "centralindia",
+      "eastasia",
+      "eastus",
+      "eastus2",
+      "francecentral",
+      "germanywestcentral",
+      "israelcentral",
+      "italynorth",
+      "northeurope",
+      "norwayeast",
+      "polandcentral",
+      "southafricanorth",
+      "swedencentral",
+      "switzerlandnorth",
+      "uaenorth",
+      "uksouth",
+    ]),
+  },
+  {
+    value: "Standard_DS2_v2",
+    label: "Standard_DS2_v2",
+    supportedRegions: new Set<string>([
+      "australiaeast",
+      "canadacentral",
+      "centralindia",
+      "eastasia",
+      "eastus",
+      "eastus2",
+      "francecentral",
+      "germanywestcentral",
+      "israelcentral",
+      "italynorth",
+      "northeurope",
+      "norwayeast",
+      "polandcentral",
+      "southafricanorth",
+      "swedencentral",
+      "switzerlandnorth",
+      "uaenorth",
+      "uksouth",
+      "eastus2euap",
+      "israelcentral",
+      "italynorth",
+      "polandcentral",
+      "qatarcentral",
+      "swedencentral",
+      "switzerlandnorth",
+      "westus3",
+    ]),
+  },
+  {
+    value: "Standard_D2ads_v5",
+    label: "Standard_D2ads_v5",
+    supportedRegions: new Set<string>([
+      "australiaeast",
+      "canadacentral",
+      "centralindia",
+      "eastasia",
+      "eastus",
+      "koreacentral",
+      "northeurope",
+      "norwayeast",
+      "southafricanorth",
+      "swedencentral",
+      "uaenorth",
+      "uksouth",
+      "westus3",
+    ]),
+  },
+  {
+    value: "Standard_B4als_v2",
+    label: "Standard_B4als_v2",
+    supportedRegions: new Set<string>([
+      "australiaeast",
+      "brazilsouth",
+      "canadacentral",
+      "centralindia",
+      "centralus",
+      "eastasia",
+      "eastus",
+      "eastus2",
+      "francecentral",
+      "northeurope",
+      "norwayeast",
+      "southafricanorth",
+      "southcentralus",
+      "southeastasia",
+      "swedencentral",
+      "switzerlandnorth",
+      "uaenorth",
+      "uksouth",
+      "westeurope",
+      "westus2",
+      "westus3",
+    ]),
+  },
+];

+ 22 - 2
dashboard/src/lib/hooks/useClusterResourceLimits.ts

@@ -1,7 +1,6 @@
 import { useEffect, useState } from "react";
 import {
   Contract,
-  GKENodePoolType,
   LoadBalancerType,
   NodeGroupType,
   NodePoolType,
@@ -11,7 +10,10 @@ import convert from "convert";
 import { match } from "ts-pattern";
 import { z } from "zod";
 
-import { AWS_INSTANCE_LIMITS } from "main/home/app-dashboard/validate-apply/services-settings/tabs/utils";
+import {
+  AWS_INSTANCE_LIMITS,
+  AZURE_INSTANCE_LIMITS,
+} from "main/home/app-dashboard/validate-apply/services-settings/tabs/utils";
 
 import api from "shared/api";
 
@@ -109,6 +111,24 @@ const clusterNodesValidator = z
     }
     const instanceType = data.labels["beta.kubernetes.io/instance-type"];
 
+    if (!instanceType) {
+      return defaultResources;
+    }
+
+    // Azure instance types are all prefixed with "Standard_"
+    if (instanceType.startsWith("Standard_")) {
+      if (AZURE_INSTANCE_LIMITS[instanceType]) {
+        const { vCPU, RAM } = AZURE_INSTANCE_LIMITS[instanceType];
+        return {
+          maxCPU: vCPU,
+          maxRAM: RAM,
+          azureType: instanceType,
+        };
+      } else {
+        return defaultResources;
+      }
+    }
+
     let parsedType;
     if (instanceType && instanceType.includes(".")) {
       parsedType = z

+ 13 - 0
dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/utils.ts

@@ -6,6 +6,7 @@ type InstanceDetails = {
 };
 
 type InstanceTypes = Record<string, Record<string, InstanceDetails>>;
+type AzureInstanceTypes = Record<string, InstanceDetails>;
 
 // use values from AWS as base constant, convert to MB
 export const AWS_INSTANCE_LIMITS: InstanceTypes = Object.freeze({
@@ -120,3 +121,15 @@ export const AWS_INSTANCE_LIMITS: InstanceTypes = Object.freeze({
     "standard-44": { vCPU: 44, RAM: 176 },
   },
 });
+
+// use values from Azure as base constant, convert to MB
+export const AZURE_INSTANCE_LIMITS: AzureInstanceTypes = Object.freeze({
+  Standard_B2als_v2: { vCPU: 2, RAM: 4 },
+  Standard_B2as_v2: { vCPU: 2, RAM: 8 },
+  Standard_B4als_v2: { vCPU: 4, RAM: 8 },
+  Standard_A2_v2: { vCPU: 2, RAM: 4 },
+  Standard_A4_v2: { vCPU: 4, RAM: 8 },
+  Standard_DS1_v2: { vCPU: 1, RAM: 3.5 },
+  Standard_DS2_v2: { vCPU: 2, RAM: 7 },
+  Standard_D2ads_v5: { vCPU: 2, RAM: 8 },
+});