diff --git a/pkg/cloud/metadata.go b/pkg/cloud/metadata.go index 995b043a59..4815103044 100644 --- a/pkg/cloud/metadata.go +++ b/pkg/cloud/metadata.go @@ -28,6 +28,7 @@ import ( "github.com/aws/aws-sdk-go/aws/ec2metadata" "github.com/aws/aws-sdk-go/aws/session" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" @@ -210,9 +211,14 @@ func KubernetesAPIInstanceInfo(clientset kubernetes.Interface) (*Metadata, error return nil, fmt.Errorf("did not find aws instance ID in node providerID string") } + var instanceType string + if it, ok := node.GetLabels()[corev1.LabelInstanceTypeStable]; ok { + instanceType = it + } + instanceInfo := Metadata{ InstanceID: instanceID, - InstanceType: "", // we have no way to find this, so we leave it empty + InstanceType: instanceType, Region: region, AvailabilityZone: availabilityZone, } diff --git a/pkg/cloud/metadata_test.go b/pkg/cloud/metadata_test.go index 07ebd34bae..d968b44f76 100644 --- a/pkg/cloud/metadata_test.go +++ b/pkg/cloud/metadata_test.go @@ -114,6 +114,9 @@ func TestNewMetadataService(t *testing.T) { APIVersion: "v1", }, ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "node.kubernetes.io/instance-type": stdInstanceType, + }, Name: nodeName, }, Spec: v1.NodeSpec{ @@ -325,6 +328,9 @@ func TestNewMetadataService(t *testing.T) { if m.GetInstanceID() != stdInstanceID { t.Errorf("NewMetadataService() failed: got wrong instance ID %v, expected %v", m.GetInstanceID(), stdInstanceID) } + if m.GetInstanceType() != stdInstanceType { + t.Errorf("GetInstanceType() failed: got wrong instance type %v, expected %v", m.GetInstanceType(), stdInstanceType) + } if m.GetRegion() != stdRegion { t.Errorf("NewMetadataService() failed: got wrong region %v, expected %v", m.GetRegion(), stdRegion) }