Skip to content

Commit

Permalink
Recognize instance-type node label when EC2 metadata isn't available
Browse files Browse the repository at this point in the history
This fixes volume limits on nodes that dont have the EC2 metadata endpoint available.
  • Loading branch information
rifelpet committed Sep 12, 2021
1 parent 0678dfe commit ac03e66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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 %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

0 comments on commit ac03e66

Please sign in to comment.