Skip to content

Commit

Permalink
fix tests from previous backports
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Sheng committed Mar 29, 2022
1 parent 9856805 commit b2deba1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions cluster-autoscaler/cloudprovider/aws/aws_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
9 changes: 8 additions & 1 deletion cluster-autoscaler/cloudprovider/gce/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
"regexp"
"strings"

"github.com/ghodss/yaml"
gce "google.golang.org/api/compute/v1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"

"github.com/ghodss/yaml"
klog "k8s.io/klog/v2"
)

Expand Down Expand Up @@ -201,15 +203,20 @@ func BuildGenericLabels(ref GceRef, machineType string, nodeName string, os Oper
}

// TODO: extract it somehow
result[kubeletapis.LabelArch] = cloudprovider.DefaultArch
result[apiv1.LabelArchStable] = cloudprovider.DefaultArch
result[kubeletapis.LabelOS] = string(os)
result[apiv1.LabelOSStable] = string(os)

result[apiv1.LabelInstanceType] = machineType
result[apiv1.LabelInstanceTypeStable] = machineType
ix := strings.LastIndex(ref.Zone, "-")
if ix == -1 {
return nil, fmt.Errorf("unexpected zone: %s", ref.Zone)
}
result[apiv1.LabelZoneRegion] = ref.Zone[:ix]
result[apiv1.LabelZoneRegionStable] = ref.Zone[:ix]
result[apiv1.LabelZoneFailureDomain] = ref.Zone
result[apiv1.LabelZoneFailureDomainStable] = ref.Zone
result[gceCSITopologyKeyZone] = ref.Zone
result[apiv1.LabelHostname] = nodeName
Expand Down
9 changes: 8 additions & 1 deletion cluster-autoscaler/cloudprovider/gce/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import (
gpuUtils "k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
"k8s.io/autoscaler/cluster-autoscaler/utils/units"

"github.com/stretchr/testify/assert"
gce "google.golang.org/api/compute/v1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
quota "k8s.io/kubernetes/pkg/quota/v1"

"github.com/stretchr/testify/assert"
)

func TestBuildNodeFromTemplateSetsResources(t *testing.T) {
Expand Down Expand Up @@ -164,11 +166,16 @@ func TestBuildGenericLabels(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
expectedLabels := map[string]string{
apiv1.LabelZoneRegion: "us-central1",
apiv1.LabelZoneRegionStable: "us-central1",
apiv1.LabelZoneFailureDomain: "us-central1-b",
apiv1.LabelZoneFailureDomainStable: "us-central1-b",
gceCSITopologyKeyZone: "us-central1-b",
apiv1.LabelHostname: "sillyname",
apiv1.LabelInstanceType: "n1-standard-8",
apiv1.LabelInstanceTypeStable: "n1-standard-8",
kubeletapis.LabelArch: cloudprovider.DefaultArch,
kubeletapis.LabelOS: tc.expectedOsLabel,
apiv1.LabelArchStable: cloudprovider.DefaultArch,
apiv1.LabelOSStable: tc.expectedOsLabel,
}
Expand Down

0 comments on commit b2deba1

Please sign in to comment.