Merge pull request #50993 from wackxu/fixdepfuncaws

Automatic merge from submit-queue (batch tested with PRs 51301, 50497, 50112, 48184, 50993)

Replace the deprecated function with the suggest function in aws module

**What this PR does / why we need it**:

There are some deprecated  function and I replace the deprecated function with the suggest function in aws module.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-09-02 23:50:07 -07:00 committed by GitHub
commit 6b39b017b4
4 changed files with 20 additions and 32 deletions

View File

@ -601,18 +601,6 @@ func stringPointerArray(orig []string) []*string {
return aws.StringSlice(orig) return aws.StringSlice(orig)
} }
// isNilOrEmpty returns true if the value is nil or ""
// Deprecated: prefer aws.StringValue(x) == "" (and elimination of this check altogether where possible)
func isNilOrEmpty(s *string) bool {
return s == nil || *s == ""
}
// orEmpty returns the string value, or "" if the pointer is nil
// Deprecated: prefer aws.StringValue
func orEmpty(s *string) string {
return aws.StringValue(s)
}
func newEc2Filter(name string, values ...string) *ec2.Filter { func newEc2Filter(name string, values ...string) *ec2.Filter {
filter := &ec2.Filter{ filter := &ec2.Filter{
Name: aws.String(name), Name: aws.String(name),
@ -651,7 +639,7 @@ func (s *awsSdkEC2) DescribeInstances(request *ec2.DescribeInstancesInput) ([]*e
} }
nextToken = response.NextToken nextToken = response.NextToken
if isNilOrEmpty(nextToken) { if aws.StringValue(nextToken) == "" {
break break
} }
request.NextToken = nextToken request.NextToken = nextToken
@ -703,7 +691,7 @@ func (s *awsSdkEC2) DescribeVolumes(request *ec2.DescribeVolumesInput) ([]*ec2.V
results = append(results, response.Volumes...) results = append(results, response.Volumes...)
nextToken = response.NextToken nextToken = response.NextToken
if isNilOrEmpty(nextToken) { if aws.StringValue(nextToken) == "" {
break break
} }
request.NextToken = nextToken request.NextToken = nextToken
@ -1153,7 +1141,7 @@ func (c *Cloud) ExternalID(nodeName types.NodeName) (string, error) {
if instance == nil { if instance == nil {
return "", cloudprovider.InstanceNotFound return "", cloudprovider.InstanceNotFound
} }
return orEmpty(instance.InstanceId), nil return aws.StringValue(instance.InstanceId), nil
} }
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running. // InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
@ -1173,7 +1161,7 @@ func (c *Cloud) InstanceID(nodeName types.NodeName) (string, error) {
if err != nil { if err != nil {
return "", fmt.Errorf("getInstanceByNodeName failed for %q with %q", nodeName, err) return "", fmt.Errorf("getInstanceByNodeName failed for %q with %q", nodeName, err)
} }
return "/" + orEmpty(inst.Placement.AvailabilityZone) + "/" + orEmpty(inst.InstanceId), nil return "/" + aws.StringValue(inst.Placement.AvailabilityZone) + "/" + aws.StringValue(inst.InstanceId), nil
} }
// InstanceTypeByProviderID returns the cloudprovider instance type of the node with the specified unique providerID // InstanceTypeByProviderID returns the cloudprovider instance type of the node with the specified unique providerID
@ -2483,7 +2471,7 @@ func (c *Cloud) ensureSecurityGroup(name string, description string) (string, er
} }
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} else { } else {
groupID = orEmpty(createResponse.GroupId) groupID = aws.StringValue(createResponse.GroupId)
break break
} }
} }
@ -3038,13 +3026,13 @@ func (c *Cloud) EnsureLoadBalancer(clusterName string, apiService *v1.Service, n
return nil, err return nil, err
} }
err = c.ensureLoadBalancerInstances(orEmpty(loadBalancer.LoadBalancerName), loadBalancer.Instances, instances) err = c.ensureLoadBalancerInstances(aws.StringValue(loadBalancer.LoadBalancerName), loadBalancer.Instances, instances)
if err != nil { if err != nil {
glog.Warningf("Error registering instances with the load balancer: %q", err) glog.Warningf("Error registering instances with the load balancer: %q", err)
return nil, err return nil, err
} }
glog.V(1).Infof("Loadbalancer %s (%v) has DNS name %s", loadBalancerName, serviceName, orEmpty(loadBalancer.DNSName)) glog.V(1).Infof("Loadbalancer %s (%v) has DNS name %s", loadBalancerName, serviceName, aws.StringValue(loadBalancer.DNSName))
// TODO: Wait for creation? // TODO: Wait for creation?
@ -3071,9 +3059,9 @@ func (c *Cloud) GetLoadBalancer(clusterName string, service *v1.Service) (*v1.Lo
func toStatus(lb *elb.LoadBalancerDescription) *v1.LoadBalancerStatus { func toStatus(lb *elb.LoadBalancerDescription) *v1.LoadBalancerStatus {
status := &v1.LoadBalancerStatus{} status := &v1.LoadBalancerStatus{}
if !isNilOrEmpty(lb.DNSName) { if aws.StringValue(lb.DNSName) != "" {
var ingress v1.LoadBalancerIngress var ingress v1.LoadBalancerIngress
ingress.Hostname = orEmpty(lb.DNSName) ingress.Hostname = aws.StringValue(lb.DNSName)
status.Ingress = []v1.LoadBalancerIngress{ingress} status.Ingress = []v1.LoadBalancerIngress{ingress}
} }
@ -3159,17 +3147,17 @@ func (c *Cloud) updateInstanceSecurityGroupsForLoadBalancer(lb *elb.LoadBalancer
// Determine the load balancer security group id // Determine the load balancer security group id
loadBalancerSecurityGroupID := "" loadBalancerSecurityGroupID := ""
for _, securityGroup := range lb.SecurityGroups { for _, securityGroup := range lb.SecurityGroups {
if isNilOrEmpty(securityGroup) { if aws.StringValue(securityGroup) == "" {
continue continue
} }
if loadBalancerSecurityGroupID != "" { if loadBalancerSecurityGroupID != "" {
// We create LBs with one SG // We create LBs with one SG
glog.Warningf("Multiple security groups for load balancer: %q", orEmpty(lb.LoadBalancerName)) glog.Warningf("Multiple security groups for load balancer: %q", aws.StringValue(lb.LoadBalancerName))
} }
loadBalancerSecurityGroupID = *securityGroup loadBalancerSecurityGroupID = *securityGroup
} }
if loadBalancerSecurityGroupID == "" { if loadBalancerSecurityGroupID == "" {
return fmt.Errorf("Could not determine security group for load balancer: %s", orEmpty(lb.LoadBalancerName)) return fmt.Errorf("Could not determine security group for load balancer: %s", aws.StringValue(lb.LoadBalancerName))
} }
// Get the actual list of groups that allow ingress from the load-balancer // Get the actual list of groups that allow ingress from the load-balancer
@ -3213,7 +3201,7 @@ func (c *Cloud) updateInstanceSecurityGroupsForLoadBalancer(lb *elb.LoadBalancer
} }
if securityGroup == nil { if securityGroup == nil {
glog.Warning("Ignoring instance without security group: ", orEmpty(instance.InstanceId)) glog.Warning("Ignoring instance without security group: ", aws.StringValue(instance.InstanceId))
continue continue
} }
id := aws.StringValue(securityGroup.GroupId) id := aws.StringValue(securityGroup.GroupId)
@ -3329,7 +3317,7 @@ func (c *Cloud) EnsureLoadBalancerDeleted(clusterName string, service *v1.Servic
//We don't want to delete a security group that was defined in the Cloud Configurationn. //We don't want to delete a security group that was defined in the Cloud Configurationn.
continue continue
} }
if isNilOrEmpty(securityGroupID) { if aws.StringValue(securityGroupID) == "" {
glog.Warning("Ignoring empty security group in ", service.Name) glog.Warning("Ignoring empty security group in ", service.Name)
continue continue
} }
@ -3445,7 +3433,7 @@ func (c *Cloud) getInstancesByIDs(instanceIDs []*string) (map[string]*ec2.Instan
} }
for _, instance := range instances { for _, instance := range instances {
instanceID := orEmpty(instance.InstanceId) instanceID := aws.StringValue(instance.InstanceId)
if instanceID == "" { if instanceID == "" {
continue continue
} }

View File

@ -388,7 +388,7 @@ func (c *Cloud) ensureLoadBalancerHealthCheck(loadBalancer *elb.LoadBalancerDesc
expectedTarget := protocol + ":" + strconv.FormatInt(int64(port), 10) + path expectedTarget := protocol + ":" + strconv.FormatInt(int64(port), 10) + path
if expectedTarget == orEmpty(actual.Target) && if expectedTarget == aws.StringValue(actual.Target) &&
expectedHealthyThreshold == orZero(actual.HealthyThreshold) && expectedHealthyThreshold == orZero(actual.HealthyThreshold) &&
expectedUnhealthyThreshold == orZero(actual.UnhealthyThreshold) && expectedUnhealthyThreshold == orZero(actual.UnhealthyThreshold) &&
expectedTimeout == orZero(actual.Timeout) && expectedTimeout == orZero(actual.Timeout) &&
@ -426,7 +426,7 @@ func (c *Cloud) ensureLoadBalancerInstances(loadBalancerName string, lbInstances
actual := sets.NewString() actual := sets.NewString()
for _, lbInstance := range lbInstances { for _, lbInstance := range lbInstances {
actual.Insert(orEmpty(lbInstance.InstanceId)) actual.Insert(aws.StringValue(lbInstance.InstanceId))
} }
additions := expected.Difference(actual) additions := expected.Difference(actual)

View File

@ -75,7 +75,7 @@ func (c *Cloud) ListRoutes(clusterName string) ([]*cloudprovider.Route, error) {
var instanceIDs []*string var instanceIDs []*string
for _, r := range table.Routes { for _, r := range table.Routes {
instanceID := orEmpty(r.InstanceId) instanceID := aws.StringValue(r.InstanceId)
if instanceID == "" { if instanceID == "" {
continue continue
@ -146,7 +146,7 @@ func (c *Cloud) CreateRoute(clusterName string, nameHint string, route *cloudpro
// In addition to configuring the route itself, we also need to configure the instance to accept that traffic // In addition to configuring the route itself, we also need to configure the instance to accept that traffic
// On AWS, this requires turning source-dest checks off // On AWS, this requires turning source-dest checks off
err = c.configureInstanceSourceDestCheck(orEmpty(instance.InstanceId), false) err = c.configureInstanceSourceDestCheck(aws.StringValue(instance.InstanceId), false)
if err != nil { if err != nil {
return err return err
} }

View File

@ -38,7 +38,7 @@ func stringSetFromPointers(in []*string) sets.String {
} }
out := sets.NewString() out := sets.NewString()
for i := range in { for i := range in {
out.Insert(orEmpty(in[i])) out.Insert(aws.StringValue(in[i]))
} }
return out return out
} }