simplfy code

This commit is contained in:
tanjunchen 2019-10-04 22:19:08 +08:00
parent f671873629
commit 119e36be29
10 changed files with 12 additions and 31 deletions

View File

@ -119,11 +119,11 @@ func (c *ResourceRecordChangeset) nameToID(name string) (string, error) {
}
allPages, err := recordsets.ListByZone(c.zone.zones.iface.sc, c.zone.impl.ID, opts).AllPages()
if err != nil {
return "", err
}
rrs, err := recordsets.ExtractRecordSets(allPages)
if err != nil {
return "", err
}
switch len(rrs) {
case 0:

View File

@ -665,9 +665,7 @@ func DescribeVolumes(cloud fi.Cloud) ([]*ec2.Volume, error) {
}
err := c.EC2().DescribeVolumesPages(request, func(p *ec2.DescribeVolumesOutput, lastPage bool) bool {
for _, volume := range p.Volumes {
volumes = append(volumes, volume)
}
volumes = append(volumes, p.Volumes...)
return true
})
if err != nil {

View File

@ -276,9 +276,7 @@ func (t *LaunchTemplate) findAllLaunchTemplates(c *fi.Context) ([]*ec2.LaunchTem
if err != nil {
return nil, err
}
for _, x := range resp.LaunchTemplates {
list = append(list, x)
}
list = append(list, resp.LaunchTemplates...)
if resp.NextToken == nil {
return list, nil
@ -312,9 +310,7 @@ func (t *LaunchTemplate) findAllLaunchTemplatesVersions(c *fi.Context) ([]*ec2.L
if err != nil {
return err
}
for _, x := range resp.LaunchTemplateVersions {
list = append(list, x)
}
list = append(list, resp.LaunchTemplateVersions...)
if resp.NextToken == nil {
return nil
}

View File

@ -67,9 +67,7 @@ func findEtcdStatus(c AWSCloud, cluster *kops.Cluster) ([]kops.EtcdClusterStatus
var volumes []*ec2.Volume
klog.V(2).Infof("Listing EC2 Volumes")
err := c.EC2().DescribeVolumesPages(request, func(p *ec2.DescribeVolumesOutput, lastPage bool) bool {
for _, volume := range p.Volumes {
volumes = append(volumes, volume)
}
volumes = append(volumes, p.Volumes...)
return true
})
if err != nil {

View File

@ -108,9 +108,7 @@ func (e *executor) RunTasks(taskMap map[string]Task) error {
progress := false
var tasks []*taskState
for _, ts := range canRun {
tasks = append(tasks, ts)
}
tasks = append(tasks, canRun...)
taskErrors := e.forkJoin(tasks)
var errors []error

View File

@ -61,9 +61,7 @@ func (e *Archive) GetDependencies(tasks map[string]fi.Task) []fi.Task {
var deps []fi.Task
// Requires parent directories to be created
for _, v := range findCreatesDirParents(e.TargetDir, tasks) {
deps = append(deps, v)
}
deps = append(deps, findCreatesDirParents(e.TargetDir, tasks)...)
return deps
}

View File

@ -66,9 +66,7 @@ func (e *BindMount) GetDependencies(tasks map[string]fi.Task) []fi.Task {
var deps []fi.Task
// Requires parent directories to be created
for _, v := range findCreatesDirParents(e.Mountpoint, tasks) {
deps = append(deps, v)
}
deps = append(deps, findCreatesDirParents(e.Mountpoint, tasks)...)
for _, v := range findCreatesDirMatching(e.Mountpoint, tasks) {
if v != e && findTaskInSlice(deps, v) == -1 {
deps = append(deps, v)

View File

@ -105,9 +105,7 @@ func (e *File) GetDependencies(tasks map[string]fi.Task) []fi.Task {
}
// Requires parent directories to be created
for _, v := range findCreatesDirParents(e.Path, tasks) {
deps = append(deps, v)
}
deps = append(deps, findCreatesDirParents(e.Path, tasks)...)
// Requires other files to be created first
for _, f := range e.AfterFiles {

View File

@ -60,10 +60,7 @@ func (e *MountDiskTask) GetDependencies(tasks map[string]fi.Task) []fi.Task {
var deps []fi.Task
// Requires parent directories to be created
for _, v := range findCreatesDirParents(e.Mountpoint, tasks) {
deps = append(deps, v)
}
deps = append(deps, findCreatesDirParents(e.Mountpoint, tasks)...)
return deps
}

View File

@ -94,7 +94,7 @@ func ValueAsString(value reflect.Value) string {
for _, p := range printers {
s, ok := p(intf)
if ok {
fmt.Fprintf(b, s)
fmt.Fprintf(b, "%s", s)
done = true
break
}