Skip to content

Commit ab642d6

Browse files
authored
Improve golint (#419)
1 parent 852dbed commit ab642d6

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

cloud/scope/cluster.go

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,10 @@ func (s *ClusterScope) CreateVPC() (*vpcv1.VPC, error) {
105105
vpc, _, err := s.IBMVPCClients.VPCService.CreateVPC(options)
106106
if err != nil {
107107
return nil, err
108-
} else {
109-
if err := s.updateDefaultSG(*vpc.DefaultSecurityGroup.ID); err != nil {
110-
return nil, err
111-
} else {
112-
return vpc, nil
113-
}
108+
} else if err := s.updateDefaultSG(*vpc.DefaultSecurityGroup.ID); err != nil {
109+
return nil, err
114110
}
111+
return vpc, nil
115112
}
116113

117114
// DeleteVPC deletes IBM VPC associated with a VPC id
@@ -128,14 +125,13 @@ func (s *ClusterScope) ensureVPCUnique(vpcName string) (*vpcv1.VPC, error) {
128125
vpcs, _, err := s.IBMVPCClients.VPCService.ListVpcs(listVpcsOptions)
129126
if err != nil {
130127
return nil, err
131-
} else {
132-
for _, vpc := range vpcs.Vpcs {
133-
if (*vpc.Name) == vpcName {
134-
return &vpc, nil
135-
}
128+
}
129+
for _, vpc := range vpcs.Vpcs {
130+
if (*vpc.Name) == vpcName {
131+
return &vpc, nil
136132
}
137-
return nil, nil
138133
}
134+
return nil, nil
139135
}
140136

141137
func (s *ClusterScope) updateDefaultSG(sgID string) error {
@@ -181,14 +177,13 @@ func (s *ClusterScope) ensureFIPUnique(fipName string) (*vpcv1.FloatingIP, error
181177
floatingIPs, _, err := s.IBMVPCClients.VPCService.ListFloatingIps(listFloatingIpsOptions)
182178
if err != nil {
183179
return nil, err
184-
} else {
185-
for _, fip := range floatingIPs.FloatingIps {
186-
if *fip.Name == fipName {
187-
return &fip, nil
188-
}
180+
}
181+
for _, fip := range floatingIPs.FloatingIps {
182+
if *fip.Name == fipName {
183+
return &fip, nil
189184
}
190-
return nil, nil
191185
}
186+
return nil, nil
192187
}
193188

194189
// DeleteFloatingIP deletes a Floating IP associated with floating ip id
@@ -253,14 +248,13 @@ func (s *ClusterScope) getSubnetAddrPrefix(vpcID, zone string) (string, error) {
253248

254249
if err != nil {
255250
return "", err
256-
} else {
257-
for _, addrPrefix := range addrCollection.AddressPrefixes {
258-
if *addrPrefix.Zone.Name == zone {
259-
return *addrPrefix.CIDR, nil
260-
}
251+
}
252+
for _, addrPrefix := range addrCollection.AddressPrefixes {
253+
if *addrPrefix.Zone.Name == zone {
254+
return *addrPrefix.CIDR, nil
261255
}
262-
return "", fmt.Errorf("not found a valid CIDR for VPC %s in zone %s", vpcID, zone)
263256
}
257+
return "", fmt.Errorf("not found a valid CIDR for VPC %s in zone %s", vpcID, zone)
264258
}
265259

266260
func (s *ClusterScope) ensureSubnetUnique(subnetName string) (*vpcv1.Subnet, error) {
@@ -269,14 +263,13 @@ func (s *ClusterScope) ensureSubnetUnique(subnetName string) (*vpcv1.Subnet, err
269263

270264
if err != nil {
271265
return nil, err
272-
} else {
273-
for _, subnet := range subnets.Subnets {
274-
if *subnet.Name == subnetName {
275-
return &subnet, nil
276-
}
266+
}
267+
for _, subnet := range subnets.Subnets {
268+
if *subnet.Name == subnetName {
269+
return &subnet, nil
277270
}
278-
return nil, nil
279271
}
272+
return nil, nil
280273
}
281274

282275
// DeleteSubnet deletes a subnet associated with subnet id

cloud/scope/machine.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,13 @@ func (m *MachineScope) ensureInstanceUnique(instanceName string) (*vpcv1.Instanc
162162

163163
if err != nil {
164164
return nil, err
165-
} else {
166-
for _, instance := range instances.Instances {
167-
if *instance.Name == instanceName {
168-
return &instance, nil
169-
}
165+
}
166+
for _, instance := range instances.Instances {
167+
if *instance.Name == instanceName {
168+
return &instance, nil
170169
}
171-
return nil, nil
172170
}
171+
return nil, nil
173172
}
174173

175174
// GetMachine returns a machine associated with a machine instanceID

cloud/scope/powervs_clients.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ import (
2323
"github.com/IBM-Cloud/power-go-client/ibmpisession"
2424
)
2525

26+
// TIMEOUT is used while creating IBM Power VS client
2627
const TIMEOUT = 1 * time.Hour
2728

29+
// IBMPowerVSClient used to store IBM Power VS client information
2830
type IBMPowerVSClient struct {
2931
session *ibmpisession.IBMPISession
3032
InstanceClient *instance.IBMPIInstanceClient
3133
NetworkClient *instance.IBMPINetworkClient
3234
}
3335

36+
// NewIBMPowerVSClient creates and returns a IBM Power VS client
3437
func NewIBMPowerVSClient(token, account, cloudInstanceID, region, zone string, debug bool) (_ *IBMPowerVSClient, err error) {
3538
client := &IBMPowerVSClient{}
3639
client.session, err = ibmpisession.New(token, region, debug, TIMEOUT, account, zone)

0 commit comments

Comments
 (0)