@@ -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.
3738type 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.
4547type 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.
5558func 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
8791func (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
115118func (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
150154func (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
193195func (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
204207func (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
281283func (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 )
0 commit comments