Skip to content

Commit

Permalink
Merge pull request kubernetes#4053 from codablock/old-labels
Browse files Browse the repository at this point in the history
Also set new (non-beta/non-deprecated) labels in buildGenericLabels
  • Loading branch information
k8s-ci-robot authored and Evan Sheng committed Mar 26, 2022
1 parent 78abf7d commit e27b079
Show file tree
Hide file tree
Showing 8 changed files with 640 additions and 46 deletions.
18 changes: 9 additions & 9 deletions cluster-autoscaler/cloudprovider/alicloud/alicloud_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ package alicloud
import (
"errors"
"fmt"
"gopkg.in/gcfg.v1"
"io"
"math/rand"
"time"

"gopkg.in/gcfg.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/cloudprovider/alicloud/alibaba-cloud-sdk-go/services/ess"
klog "k8s.io/klog/v2"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
"math/rand"
"time"
)

const (
Expand Down Expand Up @@ -237,13 +237,13 @@ func (m *AliCloudManager) buildNodeFromTemplate(sg *Asg, template *sgTemplate) (

func buildGenericLabels(template *sgTemplate, nodeName string) map[string]string {
result := make(map[string]string)
result[kubeletapis.LabelArch] = cloudprovider.DefaultArch
result[kubeletapis.LabelOS] = cloudprovider.DefaultOS
result[apiv1.LabelArchStable] = cloudprovider.DefaultArch
result[apiv1.LabelOSStable] = cloudprovider.DefaultOS

result[apiv1.LabelInstanceType] = template.InstanceType.instanceTypeID
result[apiv1.LabelInstanceTypeStable] = template.InstanceType.instanceTypeID

result[apiv1.LabelZoneRegion] = template.Region
result[apiv1.LabelZoneFailureDomain] = template.Zone
result[apiv1.LabelZoneRegionStable] = template.Region
result[apiv1.LabelZoneFailureDomainStable] = template.Zone
result[apiv1.LabelHostname] = nodeName

// append custom node labels
Expand Down
12 changes: 5 additions & 7 deletions cluster-autoscaler/cloudprovider/aws/aws_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
klog "k8s.io/klog/v2"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
provider_aws "k8s.io/legacy-cloud-providers/aws"
)

Expand Down Expand Up @@ -368,15 +367,14 @@ func (m *AwsManager) buildNodeFromTemplate(asg *asg, template *asgTemplate) (*ap

func buildGenericLabels(template *asgTemplate, nodeName string) map[string]string {
result := make(map[string]string)
// TODO: extract it somehow
result[kubeletapis.LabelArch] = template.InstanceType.Architecture

result[apiv1.LabelArchStable] = template.InstanceType.Architecture
result[kubeletapis.LabelOS] = cloudprovider.DefaultOS
result[apiv1.LabelOSStable] = cloudprovider.DefaultOS

result[apiv1.LabelInstanceType] = template.InstanceType.InstanceType
result[apiv1.LabelInstanceTypeStable] = template.InstanceType.InstanceType

result[apiv1.LabelZoneRegion] = template.Region
result[apiv1.LabelZoneFailureDomain] = template.Zone
result[apiv1.LabelZoneRegionStable] = template.Region
result[apiv1.LabelZoneFailureDomainStable] = template.Zone
result[apiv1.LabelHostname] = nodeName
return result
}
Expand Down
4 changes: 1 addition & 3 deletions cluster-autoscaler/cloudprovider/aws/aws_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
provider_aws "k8s.io/legacy-cloud-providers/aws"
)

Expand Down Expand Up @@ -84,9 +83,8 @@ func TestBuildGenericLabels(t *testing.T) {
assert.Equal(t, "us-east-1", labels[apiv1.LabelZoneRegion])
assert.Equal(t, "sillyname", labels[apiv1.LabelHostname])
assert.Equal(t, "c4.large", labels[apiv1.LabelInstanceType])
assert.Equal(t, cloudprovider.DefaultArch, labels[kubeletapis.LabelArch])
assert.Equal(t, cloudprovider.DefaultArch, labels[apiv1.LabelArchStable])
assert.Equal(t, cloudprovider.DefaultOS, labels[kubeletapis.LabelOS])
assert.Equal(t, cloudprovider.DefaultOS, labels[apiv1.LabelOSStable])
}

func TestExtractAllocatableResourcesFromAsg(t *testing.T) {
Expand Down
19 changes: 8 additions & 11 deletions cluster-autoscaler/cloudprovider/azure/azure_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ package azure

import (
"fmt"
"math/rand"
"regexp"
"strings"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -26,10 +30,6 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
cloudvolume "k8s.io/cloud-provider/volume"
"k8s.io/klog/v2"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
"math/rand"
"regexp"
"strings"
)

func buildInstanceOS(template compute.VirtualMachineScaleSet) string {
Expand All @@ -44,24 +44,21 @@ func buildInstanceOS(template compute.VirtualMachineScaleSet) string {
func buildGenericLabels(template compute.VirtualMachineScaleSet, nodeName string) map[string]string {
result := make(map[string]string)

result[kubeletapis.LabelArch] = cloudprovider.DefaultArch
result[apiv1.LabelArchStable] = cloudprovider.DefaultArch

result[kubeletapis.LabelOS] = buildInstanceOS(template)
result[apiv1.LabelOSStable] = buildInstanceOS(template)

result[apiv1.LabelInstanceType] = *template.Sku.Name
result[apiv1.LabelZoneRegion] = strings.ToLower(*template.Location)
result[apiv1.LabelInstanceTypeStable] = *template.Sku.Name
result[apiv1.LabelZoneRegionStable] = strings.ToLower(*template.Location)

if template.Zones != nil && len(*template.Zones) > 0 {
failureDomains := make([]string, len(*template.Zones))
for k, v := range *template.Zones {
failureDomains[k] = strings.ToLower(*template.Location) + "-" + v
}

result[apiv1.LabelZoneFailureDomain] = strings.Join(failureDomains[:], cloudvolume.LabelMultiZoneDelimiter)
result[apiv1.LabelZoneFailureDomainStable] = strings.Join(failureDomains[:], cloudvolume.LabelMultiZoneDelimiter)
} else {
result[apiv1.LabelZoneFailureDomain] = "0"
result[apiv1.LabelZoneFailureDomainStable] = "0"
}

result[apiv1.LabelHostname] = nodeName
Expand Down
9 changes: 1 addition & 8 deletions cluster-autoscaler/cloudprovider/gce/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ 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 @@ -203,20 +201,15 @@ 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: 1 addition & 8 deletions cluster-autoscaler/cloudprovider/gce/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ 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 @@ -166,16 +164,11 @@ 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
Loading

0 comments on commit e27b079

Please sign in to comment.