Replace the deprecated function with the suggest function

This commit is contained in:
xswack 2017-08-21 09:37:49 +08:00
parent e633a1604f
commit 671c0560ae
4 changed files with 20 additions and 32 deletions

View File

@ -577,18 +577,6 @@ func stringPointerArray(orig []string) []*string {
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 {
filter := &ec2.Filter{
Name: aws.String(name),
@ -627,7 +615,7 @@ func (s *awsSdkEC2) DescribeInstances(request *ec2.DescribeInstancesInput) ([]*e
}
nextToken = response.NextToken
if isNilOrEmpty(nextToken) {
if aws.StringValue(nextToken) == "" {
break
}
request.NextToken = nextToken
@ -679,7 +667,7 @@ func (s *awsSdkEC2) DescribeVolumes(request *ec2.DescribeVolumesInput) ([]*ec2.V
results = append(results, response.Volumes...)
nextToken = response.NextToken
if isNilOrEmpty(nextToken) {
if aws.StringValue(nextToken) == "" {
break
}
request.NextToken = nextToken
@ -1098,7 +1086,7 @@ func (c *Cloud) ExternalID(nodeName types.NodeName) (string, error) {
if instance == nil {
return "", cloudprovider.InstanceNotFound
}
return orEmpty(instance.InstanceId), nil
return aws.StringValue(instance.InstanceId), nil
}
// InstanceID returns the cloud provider ID of the node with the specified nodeName.
@ -1112,7 +1100,7 @@ func (c *Cloud) InstanceID(nodeName types.NodeName) (string, error) {
if err != nil {
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
@ -2359,7 +2347,7 @@ func (c *Cloud) ensureSecurityGroup(name string, description string) (string, er
}
time.Sleep(1 * time.Second)
} else {
groupID = orEmpty(createResponse.GroupId)
groupID = aws.StringValue(createResponse.GroupId)
break
}
}
@ -2914,13 +2902,13 @@ func (c *Cloud) EnsureLoadBalancer(clusterName string, apiService *v1.Service, n
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 {
glog.Warningf("Error registering instances with the load balancer: %q", 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?
@ -2947,9 +2935,9 @@ func (c *Cloud) GetLoadBalancer(clusterName string, service *v1.Service) (*v1.Lo
func toStatus(lb *elb.LoadBalancerDescription) *v1.LoadBalancerStatus {
status := &v1.LoadBalancerStatus{}
if !isNilOrEmpty(lb.DNSName) {
if aws.StringValue(lb.DNSName) != "" {
var ingress v1.LoadBalancerIngress
ingress.Hostname = orEmpty(lb.DNSName)
ingress.Hostname = aws.StringValue(lb.DNSName)
status.Ingress = []v1.LoadBalancerIngress{ingress}
}
@ -3035,17 +3023,17 @@ func (c *Cloud) updateInstanceSecurityGroupsForLoadBalancer(lb *elb.LoadBalancer
// Determine the load balancer security group id
loadBalancerSecurityGroupID := ""
for _, securityGroup := range lb.SecurityGroups {
if isNilOrEmpty(securityGroup) {
if aws.StringValue(securityGroup) == "" {
continue
}
if loadBalancerSecurityGroupID != "" {
// 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
}
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
@ -3089,7 +3077,7 @@ func (c *Cloud) updateInstanceSecurityGroupsForLoadBalancer(lb *elb.LoadBalancer
}
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
}
id := aws.StringValue(securityGroup.GroupId)
@ -3205,7 +3193,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.
continue
}
if isNilOrEmpty(securityGroupID) {
if aws.StringValue(securityGroupID) == "" {
glog.Warning("Ignoring empty security group in ", service.Name)
continue
}
@ -3321,7 +3309,7 @@ func (c *Cloud) getInstancesByIDs(instanceIDs []*string) (map[string]*ec2.Instan
}
for _, instance := range instances {
instanceID := orEmpty(instance.InstanceId)
instanceID := aws.StringValue(instance.InstanceId)
if instanceID == "" {
continue
}

View File

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

View File

@ -75,7 +75,7 @@ func (c *Cloud) ListRoutes(clusterName string) ([]*cloudprovider.Route, error) {
var instanceIDs []*string
for _, r := range table.Routes {
instanceID := orEmpty(r.InstanceId)
instanceID := aws.StringValue(r.InstanceId)
if instanceID == "" {
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
// 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 {
return err
}

View File

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