Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Hans Rakers <h.rakers@global.leaseweb.com>
  • Loading branch information
hrak committed Feb 7, 2024
1 parent 313e1df commit f48e050
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 97 deletions.
5 changes: 1 addition & 4 deletions api/v1beta1/cloudstackaffinitygroup_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ func (dst *CloudStackAffinityGroup) ConvertFrom(srcRaw conversion.Hub) error { /
}

// Preserve Hub data on down-conversion
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}
return nil
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta3_CloudStackAffinityGroupSpec_To_v1beta1_CloudStackAffinityGroupSpec(in *v1beta3.CloudStackAffinityGroupSpec, out *CloudStackAffinityGroupSpec, s machineryconversion.Scope) error { // nolint
Expand Down
5 changes: 1 addition & 4 deletions api/v1beta1/cloudstackisolatednetwork_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ func (dst *CloudStackIsolatedNetwork) ConvertFrom(srcRaw conversion.Hub) error {
}

// Preserve Hub data on down-conversion
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}
return nil
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in *v1beta3.CloudStackIsolatedNetworkSpec, out *CloudStackIsolatedNetworkSpec, s machineryconversion.Scope) error { // nolint
Expand Down
5 changes: 1 addition & 4 deletions api/v1beta1/cloudstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ func (dst *CloudStackMachine) ConvertFrom(srcRaw conversion.Hub) error { // noli
}

// Preserve Hub data on down-conversion
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}
return nil
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta1_CloudStackMachineSpec_To_v1beta3_CloudStackMachineSpec(in *CloudStackMachineSpec, out *v1beta3.CloudStackMachineSpec, scope machineryconversion.Scope) error { // nolint
Expand Down
5 changes: 1 addition & 4 deletions api/v1beta1/cloudstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ func (dst *CloudStackMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
}

// Preserve Hub data on down-conversion
if err := utilconversion.MarshalData(src, dst); err != nil {
return err
}
return nil
return utilconversion.MarshalData(src, dst)
}

func Convert_v1beta1_CloudStackMachineTemplateSpec_To_v1beta3_CloudStackMachineTemplateSpec(in *CloudStackMachineTemplateSpec, out *v1beta3.CloudStackMachineTemplateSpec, s machineryconversion.Scope) error { // nolint
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func GetFailureDomains(csCluster *CloudStackCluster) ([]v1beta3.CloudStackFailur
var failureDomains []v1beta3.CloudStackFailureDomainSpec
namespace := csCluster.Namespace
for _, zone := range csCluster.Spec.Zones {
name, err := GetDefaultFailureDomainName(namespace, csCluster.Name, zone.ID, zone.Name)
name, err := GetDefaultFailureDomainName(namespace, zone.ID, zone.Name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func GetFailureDomains(csCluster *CloudStackCluster) ([]v1beta3.CloudStackFailur
// When upgrading cluster using eks-a, a secret named global will be created by eks-a, and it is used by following
// method to get zoneID by calling cloudstack API.
// When upgrading cluster using clusterctl directly, zoneID is fetched directly from kubernetes cluster in cloudstackzones.
func GetDefaultFailureDomainName(namespace string, clusterName string, zoneID string, zoneName string) (string, error) {
func GetDefaultFailureDomainName(namespace string, zoneID string, zoneName string) (string, error) {
if len(zoneID) > 0 {
return zoneID, nil
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloudstackisolatednetwork_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *CloudStackIsoNetReconciliationRunner) Reconcile() (retRes ctrl.Result,

func (r *CloudStackIsoNetReconciliationRunner) ReconcileDelete() (retRes ctrl.Result, retErr error) {
r.Log.Info("Deleting IsolatedNetwork.")
if err := r.CSUser.DisposeIsoNetResources(r.FailureDomain, r.ReconciliationSubject, r.CSCluster); err != nil {
if err := r.CSUser.DisposeIsoNetResources(r.ReconciliationSubject, r.CSCluster); err != nil {
if !strings.Contains(strings.ToLower(err.Error()), "no match found") {
return ctrl.Result{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/cloudstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
}

userData := processCustomMetadata(data, r)
err := r.CSUser.GetOrCreateVMInstance(r.ReconciliationSubject, r.CAPIMachine, r.CSCluster, r.FailureDomain, r.AffinityGroup, userData)
err := r.CSUser.GetOrCreateVMInstance(r.ReconciliationSubject, r.CAPIMachine, r.FailureDomain, r.AffinityGroup, userData)
if err != nil {
r.Log.Error(err, "GetOrCreateVMInstance returned error")
r.Recorder.Eventf(r.ReconciliationSubject, "Warning", "Creating", CSMachineCreationFailed, err.Error())
Expand Down Expand Up @@ -358,7 +358,7 @@ func (r *CloudStackMachineReconciliationRunner) ReconcileDelete() (retRes ctrl.R
// SetupWithManager registers the machine reconciler to the CAPI controller manager.
func (reconciler *CloudStackMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opts controller.Options) error {
reconciler.Recorder = mgr.GetEventRecorderFor("capc-machine-controller")
CloudStackClusterToCloudStackMachines, err := utils.CloudStackClusterToCloudStackMachines(ctx, reconciler.K8sClient, &infrav1.CloudStackMachineList{}, reconciler.Scheme, ctrl.LoggerFrom(ctx))
CloudStackClusterToCloudStackMachines, err := utils.CloudStackClusterToCloudStackMachines(reconciler.K8sClient, &infrav1.CloudStackMachineList{}, reconciler.Scheme, ctrl.LoggerFrom(ctx))
if err != nil {
return errors.Wrap(err, "failed to create CloudStackClusterToCloudStackMachines mapper")
}
Expand Down
20 changes: 10 additions & 10 deletions controllers/cloudstackmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var _ = Describe("CloudStackMachineReconciler", func() {
// Mock a call to GetOrCreateVMInstance and set the machine to running.
mockCloudClient.EXPECT().GetOrCreateVMInstance(
gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _, _ interface{}) {
gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _ interface{}) {
arg1.(*infrav1.CloudStackMachine).Status.InstanceState = "Running"
}).AnyTimes()

Expand All @@ -85,8 +85,8 @@ var _ = Describe("CloudStackMachineReconciler", func() {
// Mock a call to GetOrCreateVMInstance and set the machine to running.
mockCloudClient.EXPECT().GetOrCreateVMInstance(
gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _, _ interface{}) {
gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _ interface{}) {
arg1.(*infrav1.CloudStackMachine).Status.InstanceState = "Running"
controllerutil.AddFinalizer(arg1.(*infrav1.CloudStackMachine), infrav1.MachineFinalizer)
}).AnyTimes()
Expand Down Expand Up @@ -125,8 +125,8 @@ var _ = Describe("CloudStackMachineReconciler", func() {
// Mock a call to GetOrCreateVMInstance and set the machine to running.
mockCloudClient.EXPECT().GetOrCreateVMInstance(
gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _, _ interface{}) {
gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _ interface{}) {
arg1.(*infrav1.CloudStackMachine).Status.InstanceState = "Running"
controllerutil.AddFinalizer(arg1.(*infrav1.CloudStackMachine), infrav1.MachineFinalizer)
}).AnyTimes()
Expand Down Expand Up @@ -174,8 +174,8 @@ var _ = Describe("CloudStackMachineReconciler", func() {
// Mock a call to GetOrCreateVMInstance and set the machine to running.
mockCloudClient.EXPECT().GetOrCreateVMInstance(
gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _, userdata interface{}) {
gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, userdata interface{}) {
expectedUserdata := fmt.Sprintf("%s{{%s}}", dummies.CAPIMachine.Name, dummies.CSMachine1.Spec.FailureDomainName)
Ω(userdata == expectedUserdata).Should(BeTrue())
arg1.(*infrav1.CloudStackMachine).Status.InstanceState = "Running"
Expand Down Expand Up @@ -236,8 +236,8 @@ var _ = Describe("CloudStackMachineReconciler", func() {
})
mockCloudClient.EXPECT().GetOrCreateVMInstance(
gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _, _ interface{}) {
gomock.Any(), gomock.Any()).Do(
func(arg1, _, _, _, _ interface{}) {
arg1.(*infrav1.CloudStackMachine).Status.InstanceState = "Running"
}).AnyTimes()
Ω(fakeCtrlClient.Get(ctx, key, dummies.CSCluster)).Should(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func GetOwnerClusterName(obj metav1.ObjectMeta) (string, error) {

// CloudStackClusterToCloudStackMachines is a handler.ToRequestsFunc to be used to enqeue requests for reconciliation
// of CloudStackMachines.
func CloudStackClusterToCloudStackMachines(ctx context.Context, c client.Client, obj runtime.Object, scheme *runtime.Scheme, log logr.Logger) (handler.MapFunc, error) {
func CloudStackClusterToCloudStackMachines(c client.Client, obj runtime.Object, scheme *runtime.Scheme, log logr.Logger) (handler.MapFunc, error) {
gvk, err := apiutil.GVKForObject(obj, scheme)
if err != nil {
return nil, errors.Wrap(err, "failed to find GVK for CloudStackMachine")
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/affinity_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ var _ = Describe("AffinityGroup Unit Tests", func() {
dummies.CSMachine1.Spec.DiskOffering.Name = ""

Ω(client.GetOrCreateVMInstance(
dummies.CSMachine1, dummies.CAPIMachine, dummies.CSCluster, dummies.CSFailureDomain1, dummies.CSAffinityGroup, "",
dummies.CSMachine1, dummies.CAPIMachine, dummies.CSFailureDomain1, dummies.CSAffinityGroup, "",
)).Should(Succeed())

Ω(client.GetOrCreateAffinityGroup(dummies.AffinityGroup)).Should(Succeed())
Expand Down
20 changes: 8 additions & 12 deletions pkg/cloud/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

type VMIface interface {
GetOrCreateVMInstance(*infrav1.CloudStackMachine, *clusterv1.Machine, *infrav1.CloudStackCluster, *infrav1.CloudStackFailureDomain, *infrav1.CloudStackAffinityGroup, string) error
GetOrCreateVMInstance(*infrav1.CloudStackMachine, *clusterv1.Machine, *infrav1.CloudStackFailureDomain, *infrav1.CloudStackAffinityGroup, string) error
ResolveVMInstanceDetails(*infrav1.CloudStackMachine) error
DestroyVMInstance(*infrav1.CloudStackMachine) error
}
Expand Down Expand Up @@ -117,7 +117,6 @@ func (c *client) ResolveServiceOffering(csMachine *infrav1.CloudStackMachine, zo
}

func (c *client) ResolveTemplate(
csCluster *infrav1.CloudStackCluster,
csMachine *infrav1.CloudStackMachine,
zoneID string,
) (templateID string, retErr error) {
Expand Down Expand Up @@ -211,7 +210,7 @@ func verifyDiskoffering(csMachine *infrav1.CloudStackMachine, c *client, diskOff
}

// CheckAccountLimits Checks the account's limit of VM, CPU & Memory
func (c *client) CheckAccountLimits(fd *infrav1.CloudStackFailureDomain, offering *cloudstack.ServiceOffering) error {
func (c *client) CheckAccountLimits(offering *cloudstack.ServiceOffering) error {
if c.user.Account.CPUAvailable != "Unlimited" {
cpuAvailable, err := strconv.ParseInt(c.user.Account.CPUAvailable, 10, 0)
if err == nil && int64(offering.Cpunumber) > cpuAvailable {
Expand All @@ -236,7 +235,7 @@ func (c *client) CheckAccountLimits(fd *infrav1.CloudStackFailureDomain, offerin
}

// CheckDomainLimits Checks the domain's limit of VM, CPU & Memory
func (c *client) CheckDomainLimits(fd *infrav1.CloudStackFailureDomain, offering *cloudstack.ServiceOffering) error {
func (c *client) CheckDomainLimits(offering *cloudstack.ServiceOffering) error {
if c.user.Account.Domain.CPUAvailable != "Unlimited" {
cpuAvailable, err := strconv.ParseInt(c.user.Account.Domain.CPUAvailable, 10, 0)
if err == nil && int64(offering.Cpunumber) > cpuAvailable {
Expand All @@ -262,15 +261,14 @@ func (c *client) CheckDomainLimits(fd *infrav1.CloudStackFailureDomain, offering

// CheckLimits will check the account & domain limits
func (c *client) CheckLimits(
fd *infrav1.CloudStackFailureDomain,
offering *cloudstack.ServiceOffering,
) error {
err := c.CheckAccountLimits(fd, offering)
err := c.CheckAccountLimits(offering)
if err != nil {
return err
}

err = c.CheckDomainLimits(fd, offering)
err = c.CheckDomainLimits(offering)
if err != nil {
return err
}
Expand All @@ -283,13 +281,12 @@ func (c *client) CheckLimits(
func (c *client) DeployVM(
csMachine *infrav1.CloudStackMachine,
capiMachine *clusterv1.Machine,
csCluster *infrav1.CloudStackCluster,
fd *infrav1.CloudStackFailureDomain,
affinity *infrav1.CloudStackAffinityGroup,
offering *cloudstack.ServiceOffering,
userData string,
) error {
templateID, err := c.ResolveTemplate(csCluster, csMachine, fd.Spec.Zone.ID)
templateID, err := c.ResolveTemplate(csMachine, fd.Spec.Zone.ID)
if err != nil {
return err
}
Expand Down Expand Up @@ -363,7 +360,6 @@ func (c *client) DeployVM(
func (c *client) GetOrCreateVMInstance(
csMachine *infrav1.CloudStackMachine,
capiMachine *clusterv1.Machine,
csCluster *infrav1.CloudStackCluster,
fd *infrav1.CloudStackFailureDomain,
affinity *infrav1.CloudStackAffinityGroup,
userData string,
Expand All @@ -379,12 +375,12 @@ func (c *client) GetOrCreateVMInstance(
return err
}

err = c.CheckLimits(fd, &offering)
err = c.CheckLimits(&offering)
if err != nil {
return err
}

if err := c.DeployVM(csMachine, capiMachine, csCluster, fd, affinity, &offering, userData); err != nil {
if err := c.DeployVM(csMachine, capiMachine, fd, affinity, &offering, userData); err != nil {
return err
}

Expand Down
Loading

0 comments on commit f48e050

Please sign in to comment.