Skip to content

Commit 7e5d37b

Browse files
authored
Fix golint (#416)
1 parent 57e2245 commit 7e5d37b

17 files changed

+73
-38
lines changed

api/v1alpha3/ibmvpccluster_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type IBMVPCClusterStatus struct {
6363
APIEndpoint APIEndpoint `json:"apiEndpoint,omitempty"`
6464
}
6565

66+
// VPC holds the VPC information
6667
type VPC struct {
6768
ID string `json:"id"`
6869
Name string `json:"name"`

api/v1alpha3/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ limitations under the License.
1616

1717
package v1alpha3
1818

19+
// NetworkInterface holds the network interface information like subnet id.
1920
type NetworkInterface struct {
2021
// Subnet ID of the network interface
2122
Subnet string `json:"subnet,omitempty"`
2223
}
2324

25+
// Subnet describes a subnet
2426
type Subnet struct {
2527
Ipv4CidrBlock *string `json:"cidr"`
2628
Name *string `json:"name"`
2729
ID *string `json:"id"`
2830
Zone *string `json:"zone"`
2931
}
3032

33+
// APIEndpoint describes a APIEndpoint
3134
type APIEndpoint struct {
3235
Address *string `json:"address"`
3336
FIPID *string `json:"floatingIPID"`

api/v1alpha4/ibmpowervsmachinetemplate_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type IBMPowerVSMachineTemplateSpec struct {
2828
Template IBMPowerVSMachineTemplateResource `json:"template"`
2929
}
3030

31+
// IBMPowerVSMachineTemplateResource holds the IBMPowerVSMachine spec
3132
type IBMPowerVSMachineTemplateResource struct {
3233
Spec IBMPowerVSMachineSpec `json:"spec"`
3334
}

api/v1alpha4/ibmvpccluster_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type IBMVPCClusterStatus struct {
6363
APIEndpoint APIEndpoint `json:"apiEndpoint,omitempty"`
6464
}
6565

66+
// VPC holds the VPC information
6667
type VPC struct {
6768
ID string `json:"id"`
6869
Name string `json:"name"`

api/v1alpha4/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ limitations under the License.
1616

1717
package v1alpha4
1818

19+
// NetworkInterface holds the network interface information like subnet id.
1920
type NetworkInterface struct {
2021
// Subnet ID of the network interface
2122
Subnet string `json:"subnet,omitempty"`
2223
}
2324

25+
// Subnet describes a subnet
2426
type Subnet struct {
2527
Ipv4CidrBlock *string `json:"cidr"`
2628
Name *string `json:"name"`
2729
ID *string `json:"id"`
2830
Zone *string `json:"zone"`
2931
}
3032

33+
// APIEndpoint describes a APIEndpoint
3134
type APIEndpoint struct {
3235
Address *string `json:"address"`
3336
FIPID *string `json:"floatingIPID"`

cloud/scope/clients.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/IBM/vpc-go-sdk/vpcv1"
2222
)
2323

24+
// IBMVPCClients hosts the IBM VPC service
2425
type IBMVPCClients struct {
2526
VPCService *vpcv1.VpcV1
2627
//APIKey string

cloud/scope/cluster.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
infrav1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1alpha3"
3535
)
3636

37+
// ClusterScopeParams defines the input parameters used to create a new ClusterScope.
3738
type ClusterScopeParams struct {
3839
IBMVPCClients
3940
Client client.Client
@@ -42,6 +43,7 @@ type ClusterScopeParams struct {
4243
IBMVPCCluster *infrav1.IBMVPCCluster
4344
}
4445

46+
// ClusterScope defines a scope defined around a cluster.
4547
type ClusterScope struct {
4648
logr.Logger
4749
client client.Client
@@ -52,6 +54,7 @@ type ClusterScope struct {
5254
IBMVPCCluster *infrav1.IBMVPCCluster
5355
}
5456

57+
// NewClusterScope creates a new ClusterScope from the supplied parameters.
5558
func NewClusterScope(params ClusterScopeParams, authenticator core.Authenticator, svcEndpoint string) (*ClusterScope, error) {
5659
if params.Cluster == nil {
5760
return nil, errors.New("failed to generate new scope from nil Cluster")
@@ -84,15 +87,14 @@ func NewClusterScope(params ClusterScopeParams, authenticator core.Authenticator
8487
}, nil
8588
}
8689

90+
// CreateVPC creates a new IBM VPC in specified resource group
8791
func (s *ClusterScope) CreateVPC() (*vpcv1.VPC, error) {
8892
vpcReply, err := s.ensureVPCUnique(s.IBMVPCCluster.Spec.VPC)
8993
if err != nil {
9094
return nil, err
91-
} else {
92-
if vpcReply != nil {
93-
//TODO need a resonable wraped error
94-
return vpcReply, nil
95-
}
95+
} else if vpcReply != nil {
96+
//TODO need a reasonable wrapped error
97+
return vpcReply, nil
9698
}
9799

98100
options := &vpcv1.CreateVPCOptions{}
@@ -112,6 +114,7 @@ func (s *ClusterScope) CreateVPC() (*vpcv1.VPC, error) {
112114
}
113115
}
114116

117+
// DeleteVPC deletes IBM VPC associated with a VPC id
115118
func (s *ClusterScope) DeleteVPC() error {
116119
deleteVpcOptions := &vpcv1.DeleteVPCOptions{}
117120
deleteVpcOptions.SetID(s.IBMVPCCluster.Status.VPC.ID)
@@ -147,18 +150,16 @@ func (s *ClusterScope) updateDefaultSG(sgID string) error {
147150
return err
148151
}
149152

153+
// ReserveFIP creates a Floating IP in a provided resource group and zone
150154
func (s *ClusterScope) ReserveFIP() (*vpcv1.FloatingIP, error) {
151155
fipName := s.IBMVPCCluster.Name + "-control-plane"
152156
fipReply, err := s.ensureFIPUnique(fipName)
153157
if err != nil {
154158
return nil, err
155-
} else {
156-
if fipReply != nil {
157-
//TODO need a resonable wraped error
158-
return fipReply, nil
159-
}
159+
} else if fipReply != nil {
160+
//TODO need a reasonable wrapped error
161+
return fipReply, nil
160162
}
161-
162163
options := &vpcv1.CreateFloatingIPOptions{}
163164

164165
options.SetFloatingIPPrototype(&vpcv1.FloatingIPPrototype{
@@ -190,6 +191,7 @@ func (s *ClusterScope) ensureFIPUnique(fipName string) (*vpcv1.FloatingIP, error
190191
}
191192
}
192193

194+
// DeleteFloatingIP deletes a Floating IP associated with floating ip id
193195
func (s *ClusterScope) DeleteFloatingIP() error {
194196
fipID := *s.IBMVPCCluster.Status.APIEndpoint.FIPID
195197
if fipID != "" {
@@ -201,16 +203,15 @@ func (s *ClusterScope) DeleteFloatingIP() error {
201203
return nil
202204
}
203205

206+
// CreateSubnet creates a subnet within provided vpc and zone
204207
func (s *ClusterScope) CreateSubnet() (*vpcv1.Subnet, error) {
205208
subnetName := s.IBMVPCCluster.Name + "-subnet"
206209
subnetReply, err := s.ensureSubnetUnique(subnetName)
207210
if err != nil {
208211
return nil, err
209-
} else {
210-
if subnetReply != nil {
211-
//TODO need a resonable wraped error
212-
return subnetReply, nil
213-
}
212+
} else if subnetReply != nil {
213+
//TODO need a reasonable wrapped error
214+
return subnetReply, nil
214215
}
215216

216217
options := &vpcv1.CreateSubnetOptions{}
@@ -278,15 +279,16 @@ func (s *ClusterScope) ensureSubnetUnique(subnetName string) (*vpcv1.Subnet, err
278279
}
279280
}
280281

282+
// DeleteSubnet deletes a subnet associated with subnet id
281283
func (s *ClusterScope) DeleteSubnet() error {
282284
subnetID := *s.IBMVPCCluster.Status.Subnet.ID
283285

284286
// get the pgw id for given subnet, so we can delete it later
285287
getPGWOptions := &vpcv1.GetSubnetPublicGatewayOptions{}
286288
getPGWOptions.SetID(subnetID)
287289
pgw, _, err := s.IBMVPCClients.VPCService.GetSubnetPublicGateway(getPGWOptions)
288-
if pgw != nil && err == nil { // publicgateway found
289-
// Unset the publicgateway for subnet first
290+
if pgw != nil && err == nil { // public gateway found
291+
// Unset the public gateway for subnet first
290292
err = s.detachPublicGateway(subnetID, *pgw.ID)
291293
if err != nil {
292294
return errors.Wrap(err, "Error when detaching publicgateway for subnet "+subnetID)

cloud/scope/machine.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
infrav1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1alpha3"
3737
)
3838

39+
// MachineScopeParams defines the input parameters used to create a new MachineScope.
3940
type MachineScopeParams struct {
4041
IBMVPCClients
4142
Client client.Client
@@ -46,6 +47,7 @@ type MachineScopeParams struct {
4647
IBMVPCMachine *infrav1.IBMVPCMachine
4748
}
4849

50+
// MachineScope defines a scope defined around a machine and its cluster.
4951
type MachineScope struct {
5052
logr.Logger
5153
client client.Client
@@ -59,6 +61,7 @@ type MachineScope struct {
5961
IBMVPCMachine *infrav1.IBMVPCMachine
6062
}
6163

64+
// NewMachineScope creates a new MachineScope from the supplied parameters.
6265
func NewMachineScope(params MachineScopeParams, authenticator core.Authenticator, svcEndpoint string) (*MachineScope, error) {
6366
if params.Machine == nil {
6467
return nil, errors.New("failed to generate new scope from nil Machine")
@@ -93,15 +96,14 @@ func NewMachineScope(params MachineScopeParams, authenticator core.Authenticator
9396
}, nil
9497
}
9598

99+
// CreateMachine creates a vpc machine
96100
func (m *MachineScope) CreateMachine() (*vpcv1.Instance, error) {
97101
instanceReply, err := m.ensureInstanceUnique(m.IBMVPCMachine.Name)
98102
if err != nil {
99103
return nil, err
100-
} else {
101-
if instanceReply != nil {
102-
//TODO need a resonable wraped error
103-
return instanceReply, nil
104-
}
104+
} else if instanceReply != nil {
105+
//TODO need a reasonable wrapped error
106+
return instanceReply, nil
105107
}
106108

107109
cloudInitData, err := m.GetBootstrapData()
@@ -146,6 +148,7 @@ func (m *MachineScope) CreateMachine() (*vpcv1.Instance, error) {
146148
return instance, err
147149
}
148150

151+
// DeleteMachine deletes the vpc machine associated with machine instance id.
149152
func (m *MachineScope) DeleteMachine() error {
150153
options := &vpcv1.DeleteInstanceOptions{}
151154
options.SetID(m.IBMVPCMachine.Status.InstanceID)
@@ -169,6 +172,7 @@ func (m *MachineScope) ensureInstanceUnique(instanceName string) (*vpcv1.Instanc
169172
}
170173
}
171174

175+
// GetMachine returns a machine associated with a machine instanceID
172176
func (m *MachineScope) GetMachine(instanceID string) (*vpcv1.Instance, error) {
173177
options := &vpcv1.GetInstanceOptions{}
174178
options.SetID(instanceID)

cloud/scope/powervs_cluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ import (
3434
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg"
3535
)
3636

37+
// PowerVSClusterScopeParams defines the input parameters used to create a new PowerVSClusterScope.
3738
type PowerVSClusterScopeParams struct {
3839
Client client.Client
3940
Logger logr.Logger
4041
Cluster *clusterv1.Cluster
4142
IBMPowerVSCluster *v1alpha4.IBMPowerVSCluster
4243
}
4344

45+
// PowerVSClusterScope defines a scope defined around a Power VS Cluster.
4446
type PowerVSClusterScope struct {
4547
logr.Logger
4648
client client.Client
@@ -51,6 +53,7 @@ type PowerVSClusterScope struct {
5153
IBMPowerVSCluster *v1alpha4.IBMPowerVSCluster
5254
}
5355

56+
// NewPowerVSClusterScope creates a new PowerVSClusterScope from the supplied parameters.
5457
func NewPowerVSClusterScope(params PowerVSClusterScopeParams) (*PowerVSClusterScope, error) {
5558
if params.Cluster == nil {
5659
return nil, errors.New("failed to generate new scope from nil Cluster")

cloud/scope/powervs_machine.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg"
4343
)
4444

45+
// PowerVSMachineScopeParams defines the input parameters used to create a new PowerVSMachineScope.
4546
type PowerVSMachineScopeParams struct {
4647
Logger logr.Logger
4748
Client client.Client
@@ -51,6 +52,7 @@ type PowerVSMachineScopeParams struct {
5152
IBMPowerVSMachine *v1alpha4.IBMPowerVSMachine
5253
}
5354

55+
// PowerVSMachineScope defines a scope defined around a Power VS Machine.
5456
type PowerVSMachineScope struct {
5557
logr.Logger
5658
client client.Client
@@ -63,6 +65,7 @@ type PowerVSMachineScope struct {
6365
IBMPowerVSMachine *v1alpha4.IBMPowerVSMachine
6466
}
6567

68+
// NewPowerVSMachineScope creates a new PowerVSMachineScope from the supplied parameters.
6669
func NewPowerVSMachineScope(params PowerVSMachineScopeParams) (*PowerVSMachineScope, error) {
6770
if params.Client == nil {
6871
return nil, errors.New("client is required when creating a MachineScope")
@@ -129,17 +132,16 @@ func (m *PowerVSMachineScope) ensureInstanceUnique(instanceName string) (*models
129132
return nil, nil
130133
}
131134

135+
// CreateMachine creates a power vs machine
132136
func (m *PowerVSMachineScope) CreateMachine() (*models.PVMInstanceReference, error) {
133137
s := m.IBMPowerVSMachine.Spec
134138

135139
instanceReply, err := m.ensureInstanceUnique(m.IBMPowerVSMachine.Name)
136140
if err != nil {
137141
return nil, err
138-
} else {
139-
if instanceReply != nil {
140-
//TODO need a resonable wraped error
141-
return instanceReply, nil
142-
}
142+
} else if instanceReply != nil {
143+
//TODO need a reasonable wrapped error
144+
return instanceReply, nil
143145
}
144146
cloudInitData, err := m.GetBootstrapData()
145147
if err != nil {
@@ -190,6 +192,7 @@ func (m *PowerVSMachineScope) PatchObject() error {
190192
return m.patchHelper.Patch(context.TODO(), m.IBMPowerVSMachine)
191193
}
192194

195+
// DeleteMachine deletes the power vs machine associated with machine instance id and service instance id.
193196
func (m *PowerVSMachineScope) DeleteMachine() error {
194197
return m.IBMPowerVSClient.InstanceClient.Delete(m.IBMPowerVSMachine.Status.InstanceID, m.IBMPowerVSMachine.Spec.ServiceInstanceID, time.Hour)
195198
}

0 commit comments

Comments
 (0)