diff --git a/cluster-autoscaler/cloudprovider/alicloud/alicloud_manager_test.go b/cluster-autoscaler/cloudprovider/alicloud/alicloud_manager_test.go index 5f15427d2109..fe5c06141394 100644 --- a/cluster-autoscaler/cloudprovider/alicloud/alicloud_manager_test.go +++ b/cluster-autoscaler/cloudprovider/alicloud/alicloud_manager_test.go @@ -36,7 +36,7 @@ func TestBuildGenericLabels(t *testing.T) { } nodeName := "virtual-node" labels := buildGenericLabels(template, nodeName) - assert.Equal(t, labels[apiv1.LabelInstanceType], template.InstanceType.instanceTypeID) + assert.Equal(t, labels[apiv1.LabelInstanceTypeStable], template.InstanceType.instanceTypeID) } func TestExtractLabelsFromAsg(t *testing.T) { diff --git a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go index 8b70f534ddfd..722b70a60132 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go @@ -80,9 +80,9 @@ func TestBuildGenericLabels(t *testing.T) { }, Region: "us-east-1", }, "sillyname") - assert.Equal(t, "us-east-1", labels[apiv1.LabelZoneRegion]) + assert.Equal(t, "us-east-1", labels[apiv1.LabelZoneRegionStable]) assert.Equal(t, "sillyname", labels[apiv1.LabelHostname]) - assert.Equal(t, "c4.large", labels[apiv1.LabelInstanceType]) + assert.Equal(t, "c4.large", labels[apiv1.LabelInstanceTypeStable]) assert.Equal(t, cloudprovider.DefaultArch, labels[apiv1.LabelArchStable]) assert.Equal(t, cloudprovider.DefaultOS, labels[apiv1.LabelOSStable]) } diff --git a/cluster-autoscaler/cloudprovider/gce/gce_price_model.go b/cluster-autoscaler/cloudprovider/gce/gce_price_model.go index a6b01ff2d531..da6e711ad6eb 100644 --- a/cluster-autoscaler/cloudprovider/gce/gce_price_model.go +++ b/cluster-autoscaler/cloudprovider/gce/gce_price_model.go @@ -348,7 +348,7 @@ func (model *GcePriceModel) NodePrice(node *apiv1.Node, startTime time.Time, end // Base instance price if node.Labels != nil { isPreemptible = node.Labels[preemptibleLabel] == "true" - if machineType, found := node.Labels[apiv1.LabelInstanceType]; found { + if machineType, found := getInstanceTypeFromLabels(node.Labels); found { priceMapToUse := instancePrices if isPreemptible { priceMapToUse = preemptiblePrices @@ -362,8 +362,10 @@ func (model *GcePriceModel) NodePrice(node *apiv1.Node, startTime time.Time, end } } if !basePriceFound { - price = getBasePrice(node.Status.Capacity, node.Labels[apiv1.LabelInstanceType], startTime, endTime) - price = price * getPreemptibleDiscount(node) + if machineType, found := getInstanceTypeFromLabels(node.Labels); found { + price = getBasePrice(node.Status.Capacity, machineType, startTime, endTime) + price = price * getPreemptibleDiscount(node) + } } // GPUs @@ -407,7 +409,10 @@ func getPreemptibleDiscount(node *apiv1.Node) float64 { if node.Labels[preemptibleLabel] != "true" { return 1.0 } - instanceType := node.Labels[apiv1.LabelInstanceType] + instanceType, found := getInstanceTypeFromLabels(node.Labels) + if !found { + return 1.0 + } instanceFamily := getInstanceFamily(instanceType) discountMap := predefinedPreemptibleDiscount @@ -476,3 +481,11 @@ func getAdditionalPrice(resources apiv1.ResourceList, startTime time.Time, endTi price += float64(gpu.MilliValue()) / 1000.0 * gpuPricePerHour * hours return price } + +func getInstanceTypeFromLabels(labels map[string]string) (string, bool) { + machineType, found := labels[apiv1.LabelInstanceTypeStable] + if !found { + machineType, found = labels[apiv1.LabelInstanceType] + } + return machineType, found +} diff --git a/cluster-autoscaler/cloudprovider/gce/templates_test.go b/cluster-autoscaler/cloudprovider/gce/templates_test.go index 8ff261068316..7963a5475725 100644 --- a/cluster-autoscaler/cloudprovider/gce/templates_test.go +++ b/cluster-autoscaler/cloudprovider/gce/templates_test.go @@ -226,13 +226,13 @@ func TestBuildGenericLabels(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { expectedLabels := map[string]string{ - apiv1.LabelTopologyRegion: "us-central1", - apiv1.LabelTopologyZone: "us-central1-b", - gceCSITopologyKeyZone: "us-central1-b", - apiv1.LabelHostname: "sillyname", - apiv1.LabelInstanceTypeStable: "n1-standard-8", - apiv1.LabelArchStable: cloudprovider.DefaultArch, - apiv1.LabelOSStable: tc.expectedOsLabel, + apiv1.LabelTopologyRegion: "us-central1", + apiv1.LabelTopologyZone: "us-central1-b", + gceCSITopologyKeyZone: "us-central1-b", + apiv1.LabelHostname: "sillyname", + apiv1.LabelInstanceTypeStable: "n1-standard-8", + apiv1.LabelArchStable: cloudprovider.DefaultArch, + apiv1.LabelOSStable: tc.expectedOsLabel, } labels, err := BuildGenericLabels(GceRef{ Name: "kubernetes-minion-group",