mirror of https://github.com/k3s-io/k3s
parent
85832892b1
commit
b87c4398c7
|
@ -21,7 +21,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -1109,56 +1108,6 @@ func (c *Cloud) InstanceType(nodeName types.NodeName) (string, error) {
|
|||
return aws.StringValue(inst.InstanceType), nil
|
||||
}
|
||||
|
||||
// Return a list of instances matching regex string.
|
||||
func (c *Cloud) getInstancesByRegex(regex string) ([]types.NodeName, error) {
|
||||
filters := []*ec2.Filter{newEc2Filter("instance-state-name", "running")}
|
||||
|
||||
instances, err := c.describeInstances(filters)
|
||||
if err != nil {
|
||||
return []types.NodeName{}, err
|
||||
}
|
||||
|
||||
if len(instances) == 0 {
|
||||
return []types.NodeName{}, fmt.Errorf("no instances returned")
|
||||
}
|
||||
|
||||
if strings.HasPrefix(regex, "'") && strings.HasSuffix(regex, "'") {
|
||||
glog.Infof("Stripping quotes around regex (%s)", regex)
|
||||
regex = regex[1 : len(regex)-1]
|
||||
}
|
||||
|
||||
re, err := regexp.Compile(regex)
|
||||
if err != nil {
|
||||
return []types.NodeName{}, err
|
||||
}
|
||||
|
||||
matchingInstances := []types.NodeName{}
|
||||
for _, instance := range instances {
|
||||
// Only return fully-ready instances when listing instances
|
||||
// (vs a query by name, where we will return it if we find it)
|
||||
if orEmpty(instance.State.Name) == "pending" {
|
||||
glog.V(2).Infof("Skipping EC2 instance (pending): %s", *instance.InstanceId)
|
||||
continue
|
||||
}
|
||||
|
||||
nodeName := mapInstanceToNodeName(instance)
|
||||
if nodeName == "" {
|
||||
glog.V(2).Infof("Skipping EC2 instance (no PrivateDNSName): %s",
|
||||
aws.StringValue(instance.InstanceId))
|
||||
continue
|
||||
}
|
||||
|
||||
for _, tag := range instance.Tags {
|
||||
if orEmpty(tag.Key) == "Name" && re.MatchString(orEmpty(tag.Value)) {
|
||||
matchingInstances = append(matchingInstances, nodeName)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
glog.V(2).Infof("Matched EC2 instances: %s", matchingInstances)
|
||||
return matchingInstances, nil
|
||||
}
|
||||
|
||||
// getCandidateZonesForDynamicVolume retrieves a list of all the zones in which nodes are running
|
||||
// It currently involves querying all instances
|
||||
func (c *Cloud) getCandidateZonesForDynamicVolume() (sets.String, error) {
|
||||
|
|
Loading…
Reference in New Issue