Skip to content

Commit c2c19bb

Browse files
committed
Fix simple lint errors
1 parent a0f08c8 commit c2c19bb

File tree

9 files changed

+52
-54
lines changed

9 files changed

+52
-54
lines changed

api/v1beta1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// package v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group
17+
// Package v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group
1818
//+kubebuilder:object:generate=true
1919
//+groupName=infrastructure.cluster.x-k8s.io
2020
package v1beta1

controllers/cloudstackmachine_controller.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type CloudStackMachineReconciler struct {
5454
CS cloud.Client
5555
}
5656

57-
const RequeueTimeout = 5 * time.Second
57+
const requeueTimeout = 5 * time.Second
5858

5959
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachines,verbs=get;list;watch;create;update;patch;delete
6060
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=cloudstackmachines/status,verbs=get;update;patch
@@ -100,14 +100,14 @@ func (r *CloudStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
100100
return ctrl.Result{}, err
101101
} else if capiMachine == nil {
102102
log.Info("Waiting for CAPI cluster controller to set owner reference on CloudStack machine.")
103-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
103+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
104104
}
105105

106106
// Fetch the CAPI Cluster.
107107
cluster, err := util.GetClusterFromMetadata(ctx, r.Client, capiMachine.ObjectMeta)
108108
if err != nil {
109109
log.Info("Machine is missing cluster label or cluster does not exist.")
110-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
110+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
111111
}
112112

113113
// Check if the machine is paused.
@@ -131,13 +131,12 @@ func (r *CloudStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
131131
csCluster); err != nil {
132132
if client.IgnoreNotFound(err) == nil {
133133
log.Info("CloudStackCluster not found.")
134-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
135-
} else {
136-
return ctrl.Result{}, err
134+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
137135
}
136+
return ctrl.Result{}, err
138137
} else if csCluster.Status.ZoneID == "" {
139138
log.Info("CloudStackCluster ZoneId not initialized. Likely not ready.")
140-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
139+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
141140
}
142141

143142
// Reconcile a VM instance for creates/updates
@@ -169,7 +168,7 @@ func (r *CloudStackMachineReconciler) reconcile(
169168

170169
value, ok := secret.Data["value"]
171170
if !ok {
172-
return ctrl.Result{}, errors.New("Bootstrap secret data not ok.")
171+
return ctrl.Result{}, errors.New("bootstrap secret data not ok")
173172
}
174173

175174
// Create VM (or Fetch if present). Will set ready to true.
@@ -190,10 +189,10 @@ func (r *CloudStackMachineReconciler) reconcile(
190189
if err := r.Client.Delete(ctx, capiMachine); err != nil {
191190
return ctrl.Result{}, err
192191
}
193-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
192+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
194193
} else {
195194
log.Info(fmt.Sprintf("Instance not ready, is %s.", csMachine.Status.InstanceState))
196-
return ctrl.Result{RequeueAfter: RequeueTimeout}, nil
195+
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
197196
}
198197

199198
if util.IsControlPlaneMachine(capiMachine) && csCluster.Status.NetworkType != cloud.NetworkTypeShared {

controllers/utils/utils.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
clientPkg "sigs.k8s.io/controller-runtime/pkg/client"
3131
)
3232

33-
// GetMachineSet attempts to fetch a MachineSet from CAPI machine owner reference.
34-
func GetMachineSetFromCAPIMachine(
33+
// getMachineSetFromCAPIMachine attempts to fetch a MachineSet from CAPI machine owner reference.
34+
func getMachineSetFromCAPIMachine(
3535
ctx context.Context,
3636
client clientPkg.Client,
3737
capiMachine *capiv1.Machine,
@@ -58,8 +58,8 @@ func GetMachineSetFromCAPIMachine(
5858
return nil, nil
5959
}
6060

61-
// GetKubeadmControlPlaneFromCAPIMachine attempts to fetch a KubeadmControlPlane from a CAPI machine owner reference.
62-
func GetKubeadmControlPlaneFromCAPIMachine(
61+
// getKubeadmControlPlaneFromCAPIMachine attempts to fetch a KubeadmControlPlane from a CAPI machine owner reference.
62+
func getKubeadmControlPlaneFromCAPIMachine(
6363
ctx context.Context,
6464
client clientPkg.Client,
6565
capiMachine *capiv1.Machine,
@@ -91,15 +91,15 @@ func IsOwnerDeleted(ctx context.Context, client clientPkg.Client, capiMachine *c
9191
if util.IsControlPlaneMachine(capiMachine) {
9292
// The controlplane sticks around after deletion pending the deletion of its machiens.
9393
// As such, need to check the deletion timestamp thereof.
94-
if cp, err := GetKubeadmControlPlaneFromCAPIMachine(ctx, client, capiMachine); cp != nil && cp.DeletionTimestamp == nil {
94+
if cp, err := getKubeadmControlPlaneFromCAPIMachine(ctx, client, capiMachine); cp != nil && cp.DeletionTimestamp == nil {
9595
return false, nil
9696
} else if err != nil && !strings.Contains(err.Error(), "not found") {
9797
return false, err
9898
}
9999
} else {
100100
// The machineset is deleted immediately, regardless of machine ownership.
101101
// It is sufficient to check for its existence.
102-
if ms, err := GetMachineSetFromCAPIMachine(ctx, client, capiMachine); ms != nil {
102+
if ms, err := getMachineSetFromCAPIMachine(ctx, client, capiMachine); ms != nil {
103103
return false, nil
104104
} else if err != nil && !strings.Contains(err.Error(), "not found") {
105105
return false, err
@@ -122,7 +122,6 @@ func fetchOwnerRef(refList []meta.OwnerReference, kind string) *meta.OwnerRefere
122122
func GetManagementOwnerRef(capiMachine *capiv1.Machine) *meta.OwnerReference {
123123
if util.IsControlPlaneMachine(capiMachine) {
124124
return fetchOwnerRef(capiMachine.OwnerReferences, "KubeadmControlPlane")
125-
} else {
126-
return fetchOwnerRef(capiMachine.OwnerReferences, "MachineSet")
127125
}
126+
return fetchOwnerRef(capiMachine.OwnerReferences, "MachineSet")
128127
}

pkg/cloud/affinity_groups.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type AffinityGroup struct {
3232
Id string
3333
}
3434

35-
type AffinityGroupIFace interface {
35+
type AffinityGroupIface interface {
3636
FetchAffinityGroup(*AffinityGroup) error
3737
GetOrCreateAffinityGroup(*infrav1.CloudStackCluster, *AffinityGroup) error
3838
DeleteAffinityGroup(*AffinityGroup) error
@@ -94,9 +94,9 @@ func (c *client) DeleteAffinityGroup(group *AffinityGroup) (retErr error) {
9494
return retErr
9595
}
9696

97-
type AffinityGroups []AffinityGroup
97+
type affinityGroups []AffinityGroup
9898

99-
func (c *client) GetCurrentAffinityGroups(csMachine *infrav1.CloudStackMachine) (AffinityGroups, error) {
99+
func (c *client) getCurrentAffinityGroups(csMachine *infrav1.CloudStackMachine) (affinityGroups, error) {
100100
// Start by fetching VM details which includes an array of currently associated affinity groups.
101101
if virtM, count, err := c.cs.VirtualMachine.GetVirtualMachineByID(*csMachine.Spec.InstanceID); err != nil {
102102
return nil, err
@@ -111,15 +111,15 @@ func (c *client) GetCurrentAffinityGroups(csMachine *infrav1.CloudStackMachine)
111111
}
112112
}
113113

114-
func (ags *AffinityGroups) ToArrayOfIDs() []string {
114+
func (ags *affinityGroups) toArrayOfIDs() []string {
115115
groupIds := make([]string, 0, len(*ags))
116116
for _, group := range *ags {
117117
groupIds = append(groupIds, group.Id)
118118
}
119119
return groupIds
120120
}
121121

122-
func (ags *AffinityGroups) AddGroup(addGroup AffinityGroup) {
122+
func (ags *affinityGroups) addGroup(addGroup AffinityGroup) {
123123
// This is essentially adding to a set followed by array conversion.
124124
groupSet := map[string]AffinityGroup{addGroup.Id: addGroup}
125125
for _, group := range *ags {
@@ -131,7 +131,7 @@ func (ags *AffinityGroups) AddGroup(addGroup AffinityGroup) {
131131
}
132132
}
133133

134-
func (ags *AffinityGroups) RemoveGroup(removeGroup AffinityGroup) {
134+
func (ags *affinityGroups) removeGroup(removeGroup AffinityGroup) {
135135
// This is essentially subtracting from a set followed by array conversion.
136136
groupSet := map[string]AffinityGroup{}
137137
for _, group := range *ags {
@@ -144,9 +144,9 @@ func (ags *AffinityGroups) RemoveGroup(removeGroup AffinityGroup) {
144144
}
145145
}
146146

147-
func (c *client) StopAndModifyAffinityGroups(csMachine *infrav1.CloudStackMachine, groups AffinityGroups) (retErr error) {
147+
func (c *client) stopAndModifyAffinityGroups(csMachine *infrav1.CloudStackMachine, groups affinityGroups) (retErr error) {
148148
agp := c.cs.AffinityGroup.NewUpdateVMAffinityGroupParams(*csMachine.Spec.InstanceID)
149-
agp.SetAffinitygroupids(groups.ToArrayOfIDs())
149+
agp.SetAffinitygroupids(groups.toArrayOfIDs())
150150

151151
p1 := c.cs.VirtualMachine.NewStopVirtualMachineParams(string(*csMachine.Spec.InstanceID))
152152
if _, err := c.cs.VirtualMachine.StopVirtualMachine(p1); err != nil {
@@ -163,19 +163,19 @@ func (c *client) StopAndModifyAffinityGroups(csMachine *infrav1.CloudStackMachin
163163
}
164164

165165
func (c *client) AssociateAffinityGroup(csMachine *infrav1.CloudStackMachine, group AffinityGroup) (retErr error) {
166-
if groups, err := c.GetCurrentAffinityGroups(csMachine); err != nil {
166+
if groups, err := c.getCurrentAffinityGroups(csMachine); err != nil {
167167
return err
168168
} else {
169-
groups.AddGroup(group)
170-
return c.StopAndModifyAffinityGroups(csMachine, groups)
169+
groups.addGroup(group)
170+
return c.stopAndModifyAffinityGroups(csMachine, groups)
171171
}
172172
}
173173

174174
func (c *client) DissassociateAffinityGroup(csMachine *infrav1.CloudStackMachine, group AffinityGroup) (retErr error) {
175-
if groups, err := c.GetCurrentAffinityGroups(csMachine); err != nil {
175+
if groups, err := c.getCurrentAffinityGroups(csMachine); err != nil {
176176
return err
177177
} else {
178-
groups.RemoveGroup(group)
179-
return c.StopAndModifyAffinityGroups(csMachine, groups)
178+
groups.removeGroup(group)
179+
return c.stopAndModifyAffinityGroups(csMachine, groups)
180180
}
181181
}

pkg/cloud/client.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Client interface {
3636
ResolvePublicIPDetails(*infrav1.CloudStackCluster) (*cloudstack.PublicIpAddress, error)
3737
ResolveLoadBalancerRuleDetails(*infrav1.CloudStackCluster) error
3838
GetOrCreateLoadBalancerRule(*infrav1.CloudStackCluster) error
39-
AffinityGroupIFace
39+
AffinityGroupIface
4040
}
4141

4242
type client struct {
@@ -47,27 +47,27 @@ type client struct {
4747

4848
// cloud-config ini structure.
4949
type config struct {
50-
ApiUrl string `ini:"api-url"`
51-
ApiKey string `ini:"api-key"`
50+
APIURL string `ini:"api-url"`
51+
APIKey string `ini:"api-key"`
5252
SecretKey string `ini:"secret-key"`
5353
VerifySSL bool `ini:"verify-ssl"`
5454
}
5555

56-
func NewClient(cc_path string) (Client, error) {
56+
func NewClient(ccPath string) (Client, error) {
5757
c := &client{}
5858
cfg := &config{VerifySSL: true}
59-
if rawCfg, err := ini.Load(cc_path); err != nil {
60-
return nil, errors.Wrapf(err, "Error encountered while reading config at path: %s", cc_path)
59+
if rawCfg, err := ini.Load(ccPath); err != nil {
60+
return nil, errors.Wrapf(err, "error encountered while reading config at path: %s", ccPath)
6161
} else if g := rawCfg.Section("Global"); len(g.Keys()) == 0 {
62-
return nil, errors.New("Section Global not found.")
62+
return nil, errors.New("section Global not found")
6363
} else if err = rawCfg.Section("Global").StrictMapTo(cfg); err != nil {
64-
return nil, errors.Wrapf(err, "Error encountered while parsing [Global] section from config at path: %s", cc_path)
64+
return nil, errors.Wrapf(err, "error encountered while parsing [Global] section from config at path: %s", ccPath)
6565
}
6666

6767
// This is a placeholder for sending non-blocking requests.
6868
// c.csA = cloudstack.NewClient(apiUrl, apiKey, secretKey, false)
6969
// TODO: attempt a less clunky client liveliness check (not just listing zones).
70-
c.cs = cloudstack.NewAsyncClient(cfg.ApiUrl, cfg.ApiKey, cfg.SecretKey, cfg.VerifySSL)
70+
c.cs = cloudstack.NewAsyncClient(cfg.APIURL, cfg.APIKey, cfg.SecretKey, cfg.VerifySSL)
7171
_, err := c.cs.Zone.ListZones(c.cs.Zone.NewListZonesParams())
7272
if err != nil && strings.Contains(err.Error(), "i/o timeout") {
7373
return c, errors.Wrap(err, "Timeout while checking CloudStack API Client connectivity.")

pkg/cloud/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
// Example cloud-config ini structure.
2828
type Global struct {
29-
ApiUrl string `ini:"api-url"`
29+
APIURL string `ini:"api-url"`
3030
VerifySSL bool `ini:"verify-ssl"`
3131
}
3232

@@ -53,7 +53,7 @@ var _ = Describe("Instance", func() {
5353
Ω(err).ShouldNot(HaveOccurred())
5454
Ω(rawCfg.Section("Global").MapTo(cfg)).Should(Succeed())
5555
Ω(cfg.VerifySSL).Should(BeFalse())
56-
Ω(cfg.ApiUrl).ShouldNot(BeEmpty())
56+
Ω(cfg.APIURL).ShouldNot(BeEmpty())
5757
})
5858
})
5959
})

pkg/cloud/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (c *client) GetOrCreateCluster(csCluster *infrav1.CloudStackCluster) (retEr
7979
return retErr
8080
}
8181
if csCluster.Status.PublicIPID == "" { // Don't try to get public IP again it's already been fetched.
82-
if retErr = c.AssociatePublicIpAddress(csCluster); retErr != nil {
82+
if retErr = c.AssociatePublicIPAddress(csCluster); retErr != nil {
8383
return retErr
8484
}
8585
}

pkg/cloud/instance.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"k8s.io/utils/pointer"
3333
)
3434

35-
const AntiAffinityValue = "anti"
35+
const antiAffinityValue = "anti"
3636

3737
type VMIface interface {
3838
GetOrCreateVMInstance(*infrav1.CloudStackMachine, *capiv1.Machine, *infrav1.CloudStackCluster, string) error
@@ -58,7 +58,7 @@ func (c *client) ResolveVMInstanceDetails(csMachine *infrav1.CloudStackMachine)
5858
if err != nil && !strings.Contains(strings.ToLower(err.Error()), "no match found") {
5959
return err
6060
} else if count > 1 {
61-
return fmt.Errorf("Found more than one VM Instance with ID %s.", *csMachine.Spec.InstanceID)
61+
return fmt.Errorf("found more than one VM Instance with ID %s", *csMachine.Spec.InstanceID)
6262
} else if err == nil {
6363
setMachineDataFromVMMetrics(vmResp, csMachine)
6464
return nil
@@ -71,7 +71,7 @@ func (c *client) ResolveVMInstanceDetails(csMachine *infrav1.CloudStackMachine)
7171
if err != nil && !strings.Contains(strings.ToLower(err.Error()), "no match") {
7272
return err
7373
} else if count > 1 {
74-
return fmt.Errorf("Found more than one VM Instance with name %s.", csMachine.Name)
74+
return fmt.Errorf("found more than one VM Instance with name %s", csMachine.Name)
7575
} else if err == nil {
7676
setMachineDataFromVMMetrics(vmResp, csMachine)
7777
return nil
@@ -170,7 +170,7 @@ func (c *client) GetOrCreateVMInstance(
170170
p.SetAffinitygroupids(csMachine.Spec.AffinityGroupIds)
171171
} else if strings.ToLower(csMachine.Spec.Affinity) != "no" && csMachine.Spec.Affinity != "" {
172172
affinityType := AffinityGroupType
173-
if strings.ToLower(csMachine.Spec.Affinity) == AntiAffinityValue {
173+
if strings.ToLower(csMachine.Spec.Affinity) == antiAffinityValue {
174174
affinityType = AntiAffinityGroupType
175175
}
176176
name, err := csMachine.AffinityGroupName(capiMachine)

pkg/cloud/network.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ func (c *client) GetOrCreateNetwork(csCluster *infrav1.CloudStackCluster) (retEr
6666
} // Network not found.
6767

6868
// Create network since it wasn't found.
69-
offeringId, count, retErr := c.cs.NetworkOffering.GetNetworkOfferingID(NetOffering)
69+
offeringID, count, retErr := c.cs.NetworkOffering.GetNetworkOfferingID(NetOffering)
7070
if retErr != nil {
7171
return retErr
7272
} else if count != 1 {
73-
return errors.New("found more than one network offering.")
73+
return errors.New("found more than one network offering")
7474
}
7575
p := c.cs.Network.NewCreateNetworkParams(
7676
csCluster.Spec.Network,
7777
csCluster.Spec.Network,
78-
offeringId,
78+
offeringID,
7979
csCluster.Status.ZoneID)
8080
setIfNotEmpty(csCluster.Spec.Account, p.SetAccount)
8181
setIfNotEmpty(csCluster.Status.DomainID, p.SetDomainid)
@@ -117,8 +117,8 @@ func (c *client) ResolvePublicIPDetails(csCluster *infrav1.CloudStackCluster) (*
117117
return nil, errors.Errorf(`no public addresses found in network: "%s"`, csCluster.Spec.Network)
118118
}
119119

120-
// AssociatePublicIpAddress Gets a PublicIP and associates it.
121-
func (c *client) AssociatePublicIpAddress(csCluster *infrav1.CloudStackCluster) (retErr error) {
120+
// AssociatePublicIPAddress Gets a PublicIP and associates it.
121+
func (c *client) AssociatePublicIPAddress(csCluster *infrav1.CloudStackCluster) (retErr error) {
122122
publicAddress, err := c.ResolvePublicIPDetails(csCluster)
123123
if err != nil {
124124
return err

0 commit comments

Comments
 (0)