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

AWS: Remove getInstancesByRegex (dead code) #47411

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 0 additions & 51 deletions pkg/cloudprovider/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"io"
"net"
"regexp"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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) {
Expand Down