Skip to content

Commit

Permalink
replace slice loop with append for simple and clear
Browse files Browse the repository at this point in the history
Signed-off-by: Guangming Wang <guangming.wang@daocloud.io>
  • Loading branch information
Guangming Wang committed Oct 8, 2019
1 parent 2afa349 commit c295a49
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 60 deletions.
8 changes: 2 additions & 6 deletions cloudmock/aws/mockec2/securitygroups.go
Expand Up @@ -260,9 +260,7 @@ func (m *MockEC2) AuthorizeSecurityGroupEgress(request *ec2.AuthorizeSecurityGro
sg.IpPermissionsEgress = append(sg.IpPermissionsEgress, p)
}

for _, p := range request.IpPermissions {
sg.IpPermissionsEgress = append(sg.IpPermissionsEgress, p)
}
sg.IpPermissionsEgress = append(sg.IpPermissionsEgress, request.IpPermissions...)

// TODO: We need to fold permissions

Expand Down Expand Up @@ -318,9 +316,7 @@ func (m *MockEC2) AuthorizeSecurityGroupIngress(request *ec2.AuthorizeSecurityGr
sg.IpPermissions = append(sg.IpPermissions, p)
}

for _, p := range request.IpPermissions {
sg.IpPermissions = append(sg.IpPermissions, p)
}
sg.IpPermissions = append(sg.IpPermissions, request.IpPermissions...)

// TODO: We need to fold permissions

Expand Down
Expand Up @@ -60,9 +60,7 @@ func (r *Route53APIStub) ListResourceRecordSetsPages(input *route53.ListResource
output.ResourceRecordSets = []*route53.ResourceRecordSet{}
} else {
for _, rrsets := range r.recordSets[*input.HostedZoneId] {
for _, rrset := range rrsets {
output.ResourceRecordSets = append(output.ResourceRecordSets, rrset)
}
output.ResourceRecordSets = append(output.ResourceRecordSets, rrsets...)
}
}
lastPage := true
Expand Down
4 changes: 1 addition & 3 deletions hack/machine_types/machine_types.go
Expand Up @@ -144,9 +144,7 @@ func run() error {
}
}

for _, p := range result.PriceList {
prices = append(prices, p)
}
prices = append(prices, result.PriceList...)

if result.NextToken != nil {
input.NextToken = result.NextToken
Expand Down
4 changes: 1 addition & 3 deletions nodeup/pkg/model/kubelet.go
Expand Up @@ -545,9 +545,7 @@ func (b *KubeletBuilder) buildKubeletConfigSpec() (*kops.KubeletConfigSpec, erro

// Use --register-with-taints for k8s 1.6 and on
if b.Cluster.IsKubernetesGTE("1.6") {
for _, t := range b.InstanceGroup.Spec.Taints {
c.Taints = append(c.Taints, t)
}
c.Taints = append(c.Taints, b.InstanceGroup.Spec.Taints...)

if len(c.Taints) == 0 && isMaster {
// (Even though the value is empty, we still expect <Key>=<Value>:<Effect>)
Expand Down
4 changes: 1 addition & 3 deletions pkg/acls/gce/storage.go
Expand Up @@ -64,9 +64,7 @@ func (s *gcsAclStrategy) GetACL(p vfs.Path, cluster *kops.Cluster) (vfs.ACL, err
}

var acls []*storage.ObjectAccessControl
for _, a := range bucket.DefaultObjectAcl {
acls = append(acls, a)
}
acls = append(acls, bucket.DefaultObjectAcl...)

acls = append(acls, &storage.ObjectAccessControl{
Email: serviceAccount,
Expand Down
4 changes: 1 addition & 3 deletions pkg/model/awsmodel/autoscalinggroup.go
Expand Up @@ -310,9 +310,7 @@ func (b *AutoscalingGroupModelBuilder) buildAutoScalingGroupTask(c *fi.ModelBuil
t.Tags = tags

processes := []string{}
for _, p := range ig.Spec.SuspendProcesses {
processes = append(processes, p)
}
processes = append(processes, ig.Spec.SuspendProcesses...)
t.SuspendProcesses = &processes

t.InstanceProtection = ig.Spec.InstanceProtection
Expand Down
8 changes: 2 additions & 6 deletions pkg/resources/ali/ali.go
Expand Up @@ -327,9 +327,7 @@ func (d *clusterDiscoveryALI) ListSecurityGroup() ([]*resources.Resource, error)
}
}

for _, block := range blocked {
groupTracker.Blocked = append(groupTracker.Blocked, block)
}
groupTracker.Blocked = append(groupTracker.Blocked, blocked...)
resourceTrackers = append(resourceTrackers, groupTracker)
}
}
Expand Down Expand Up @@ -558,9 +556,7 @@ func (d *clusterDiscoveryALI) ListVPC() ([]*resources.Resource, error) {
for _, vpc := range vpcs {
if name == vpc.VpcName {
vpcsToDelete = append(vpcsToDelete, vpc.VpcId)
for _, vswitch := range vpc.VSwitchIds.VSwitchId {
vswitchsToDelete = append(vswitchsToDelete, vswitch)
}
vswitchsToDelete = append(vswitchsToDelete, vpc.VSwitchIds.VSwitchId...)
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions pkg/resources/aws/aws.go
Expand Up @@ -258,9 +258,7 @@ func FindAutoscalingLaunchConfiguration(cloud awsup.AWSCloud, name string) (*aut
LaunchConfigurationNames: []*string{&name},
}
err := cloud.Autoscaling().DescribeLaunchConfigurationsPages(request, func(p *autoscaling.DescribeLaunchConfigurationsOutput, lastPage bool) bool {
for _, t := range p.LaunchConfigurations {
results = append(results, t)
}
results = append(results, p.LaunchConfigurations...)
return true
})
if err != nil {
Expand Down Expand Up @@ -1094,9 +1092,7 @@ func DescribeInternetGateways(cloud fi.Cloud) ([]*ec2.InternetGateway, error) {
}

var gateways []*ec2.InternetGateway
for _, o := range response.InternetGateways {
gateways = append(gateways, o)
}
gateways = append(gateways, response.InternetGateways...)

return gateways, nil
}
Expand All @@ -1116,9 +1112,7 @@ func DescribeInternetGatewaysIgnoreTags(cloud fi.Cloud) ([]*ec2.InternetGateway,

var gateways []*ec2.InternetGateway

for _, igw := range response.InternetGateways {
gateways = append(gateways, igw)
}
gateways = append(gateways, response.InternetGateways...)

return gateways, nil
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/resources/ops/delete.go
Expand Up @@ -40,9 +40,7 @@ func DeleteResources(cloud fi.Cloud, resourceMap map[string]*resources.Resource)
depMap[block] = append(depMap[block], k)
}

for _, blocked := range t.Blocked {
depMap[k] = append(depMap[k], blocked)
}
depMap[k] = append(depMap[k], t.Blocked...)

if t.Done {
done[k] = t
Expand Down
4 changes: 1 addition & 3 deletions protokube/pkg/gossip/ali/seeds.go
Expand Up @@ -62,9 +62,7 @@ func (p *SeedProvider) GetSeeds() ([]string, error) {

for _, instance := range instances {
// TODO: Multiple IP addresses?
for _, ip := range instance.VpcAttributes.PrivateIpAddress.IpAddress {
seeds = append(seeds, ip)
}
seeds = append(seeds, instance.VpcAttributes.PrivateIpAddress.IpAddress...)
}

return seeds, nil
Expand Down
4 changes: 1 addition & 3 deletions protokube/pkg/protokube/gossipdns.go
Expand Up @@ -33,9 +33,7 @@ func (p *GossipDnsProvider) Replace(fqdn string, values []string) error {
Name: fqdn,
RrsType: "A",
}
for _, value := range values {
record.Rrdatas = append(record.Rrdatas, value)
}
record.Rrdatas = append(record.Rrdatas, values...)
return p.DNSView.ApplyChangeset(p.Zone, nil, []*dns.DNSRecord{record})
}

Expand Down
8 changes: 2 additions & 6 deletions upup/pkg/fi/cloudup/gce/network.go
Expand Up @@ -66,9 +66,7 @@ func performNetworkAssignmentsIPAliases(ctx context.Context, c *kops.Cluster, cl

var regions []*compute.Region
if err := cloud.Compute().Regions.List(cloud.Project()).Pages(ctx, func(p *compute.RegionList) error {
for _, r := range p.Items {
regions = append(regions, r)
}
regions = append(regions, p.Items...)
return nil
}); err != nil {
return fmt.Errorf("error listing Regions: %v", err)
Expand All @@ -89,9 +87,7 @@ func performNetworkAssignmentsIPAliases(ctx context.Context, c *kops.Cluster, cl
var subnets []*compute.Subnetwork
for _, r := range regions {
if err := cloud.Compute().Subnetworks.List(cloud.Project(), r.Name).Pages(ctx, func(p *compute.SubnetworkList) error {
for _, s := range p.Items {
subnets = append(subnets, s)
}
subnets = append(subnets, p.Items...)
return nil
}); err != nil {
return fmt.Errorf("error listing Subnetworks: %v", err)
Expand Down
4 changes: 1 addition & 3 deletions upup/pkg/fi/cloudup/gcetasks/instance.go
Expand Up @@ -73,9 +73,7 @@ func (e *Instance) Find(c *fi.Context) (*Instance, error) {

actual := &Instance{}
actual.Name = &r.Name
for _, tag := range r.Tags.Items {
actual.Tags = append(actual.Tags, tag)
}
actual.Tags = append(actual.Tags, r.Tags.Items...)
actual.Zone = fi.String(lastComponent(r.Zone))
actual.MachineType = fi.String(lastComponent(r.MachineType))
actual.CanIPForward = &r.CanIpForward
Expand Down
4 changes: 1 addition & 3 deletions upup/pkg/fi/cloudup/gcetasks/instancetemplate.go
Expand Up @@ -103,9 +103,7 @@ func (e *InstanceTemplate) Find(c *fi.Context) (*InstanceTemplate, error) {

p := r.Properties

for _, tag := range p.Tags.Items {
actual.Tags = append(actual.Tags, tag)
}
actual.Tags = append(actual.Tags, p.Tags.Items...)
actual.MachineType = fi.String(lastComponent(p.MachineType))
actual.CanIPForward = &p.CanIpForward

Expand Down
4 changes: 1 addition & 3 deletions upup/pkg/kutil/import_cluster.go
Expand Up @@ -635,9 +635,7 @@ func findInstances(c awsup.AWSCloud) ([]*ec2.Instance, error) {

err := c.EC2().DescribeInstancesPages(request, func(p *ec2.DescribeInstancesOutput, lastPage bool) bool {
for _, reservation := range p.Reservations {
for _, instance := range reservation.Instances {
instances = append(instances, instance)
}
instances = append(instances, reservation.Instances...)
}
return true
})
Expand Down

0 comments on commit c295a49

Please sign in to comment.