mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
InstanceTypeByProviderID
This commit is contained in:
parent
17783afc94
commit
baa85c830a
@ -1111,7 +1111,16 @@ func (c *Cloud) InstanceID(nodeName types.NodeName) (string, error) {
|
|||||||
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
// This method will not be called from the node that is requesting this ID. i.e. metadata service
|
||||||
// and other local methods cannot be used here
|
// and other local methods cannot be used here
|
||||||
func (c *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
|
func (c *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
|
||||||
return "", errors.New("unimplemented")
|
// In AWS, we're using the instanceID as the providerID.
|
||||||
|
instanceID := providerID
|
||||||
|
|
||||||
|
instance, error := c.describeInstanceByInstanceID(instanceID)
|
||||||
|
|
||||||
|
if error != nil {
|
||||||
|
return "", error
|
||||||
|
}
|
||||||
|
|
||||||
|
return aws.StringValue(instance.InstanceType), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstanceType returns the type of the node with the specified nodeName.
|
// InstanceType returns the type of the node with the specified nodeName.
|
||||||
@ -3397,6 +3406,20 @@ func (c *Cloud) describeInstancesByInstanceID(instanceID string) ([]*ec2.Instanc
|
|||||||
return c.describeInstances(filters)
|
return c.describeInstances(filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cloud) describeInstanceByInstanceID(instanceID string) (*ec2.Instance, error) {
|
||||||
|
filters := []*ec2.Filter{newEc2Filter("instance-id", instanceID)}
|
||||||
|
instances, err := c.describeInstances(filters)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(instances) != 1 {
|
||||||
|
return nil, fmt.Errorf("expected 1 instance, found %d for instanceID %s", len(instances), instanceID)
|
||||||
|
}
|
||||||
|
|
||||||
|
return instances[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Cloud) describeInstances(filters []*ec2.Filter) ([]*ec2.Instance, error) {
|
func (c *Cloud) describeInstances(filters []*ec2.Filter) ([]*ec2.Instance, error) {
|
||||||
filters = c.tagging.addFilters(filters)
|
filters = c.tagging.addFilters(filters)
|
||||||
request := &ec2.DescribeInstancesInput{
|
request := &ec2.DescribeInstancesInput{
|
||||||
|
Loading…
Reference in New Issue
Block a user