Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize instance-type node label when EC2 metadata isn't available #1060

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/cloud/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/cloud/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down