Skip to content

Fix linting issues reported by golanci-lint #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions api/v1beta1/cloudstackaffinitygroup_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ 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
err := utilconversion.MarshalData(src, dst)
return err
}

func Convert_v1beta3_CloudStackAffinityGroupSpec_To_v1beta1_CloudStackAffinityGroupSpec(in *v1beta3.CloudStackAffinityGroupSpec, out *CloudStackAffinityGroupSpec, s machineryconversion.Scope) error { // nolint
Expand Down
6 changes: 2 additions & 4 deletions api/v1beta1/cloudstackisolatednetwork_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ 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
err := utilconversion.MarshalData(src, dst)
return err
}

func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in *v1beta3.CloudStackIsolatedNetworkSpec, out *CloudStackIsolatedNetworkSpec, s machineryconversion.Scope) error { // nolint
Expand Down
6 changes: 2 additions & 4 deletions api/v1beta1/cloudstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ 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
err := utilconversion.MarshalData(src, dst)
return err
}

func Convert_v1beta3_CloudStackMachineSpec_To_v1beta1_CloudStackMachineSpec(in *v1beta3.CloudStackMachineSpec, out *CloudStackMachineSpec, s machineryconversion.Scope) error { // nolint
Expand Down
21 changes: 11 additions & 10 deletions api/v1beta1/cloudstackmachine_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,31 @@ limitations under the License.
package v1beta1_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
"time"
)

var _ = Describe("CloudStackMachine types", func() {
var _ = ginkgo.Describe("CloudStackMachine types", func() {
var cloudStackMachine infrav1.CloudStackMachine

BeforeEach(func() { // Reset test vars to initial state.
ginkgo.BeforeEach(func() { // Reset test vars to initial state.
cloudStackMachine = infrav1.CloudStackMachine{}
})

Context("When calculating time since state change", func() {
It("Return the correct value when the last state update time is known", func() {
ginkgo.Context("When calculating time since state change", func() {
ginkgo.It("Return the correct value when the last state update time is known", func() {
delta := time.Duration(10 * time.Minute)
lastUpdated := time.Now().Add(-delta)
cloudStackMachine.Status.InstanceStateLastUpdated = metav1.NewTime(lastUpdated)
Ω(cloudStackMachine.Status.TimeSinceLastStateChange()).Should(BeNumerically("~", delta, time.Second))
gomega.Expect(cloudStackMachine.Status.TimeSinceLastStateChange()).Should(gomega.BeNumerically("~", delta, time.Second))
})

It("Return a negative value when the last state update time is unknown", func() {
Ω(cloudStackMachine.Status.TimeSinceLastStateChange()).Should(BeNumerically("<", 0))
ginkgo.It("Return a negative value when the last state update time is unknown", func() {
gomega.Expect(cloudStackMachine.Status.TimeSinceLastStateChange()).Should(gomega.BeNumerically("<", 0))
})
})
})
6 changes: 2 additions & 4 deletions api/v1beta1/cloudstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ 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
err := utilconversion.MarshalData(src, dst)
return err
}

func Convert_v1beta1_CloudStackMachineTemplateSpec_To_v1beta3_CloudStackMachineTemplateSpec(in *CloudStackMachineTemplateSpec, out *v1beta3.CloudStackMachineTemplateSpec, s machineryconversion.Scope) error { // nolint
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
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, _ string, zoneID string, zoneName string) (string, error) {
if len(zoneID) > 0 {
return zoneID, nil
}
Expand Down
28 changes: 14 additions & 14 deletions api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ limitations under the License.
package v1beta1_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1beta1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

var _ = Describe("Conversion", func() {
BeforeEach(func() { // Reset test vars to initial state.
var _ = ginkgo.Describe("Conversion", func() {
ginkgo.BeforeEach(func() { // Reset test vars to initial state.
})

Context("GetFailureDomains function", func() {
It("Converts v1beta1 cluster spec to v1beta3 failure domains", func() {
ginkgo.Context("GetFailureDomains function", func() {
ginkgo.It("Converts v1beta1 cluster spec to v1beta3 failure domains", func() {
csCluster := &v1beta1.CloudStackCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Expand Down Expand Up @@ -71,13 +71,13 @@ var _ = Describe("Conversion", func() {
},
},
}
Ω(err).ShouldNot(HaveOccurred())
Ω(failureDomains).Should(Equal(expectedResult))
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(failureDomains).Should(gomega.Equal(expectedResult))
})
})

Context("v1beta3 to v1beta1 function", func() {
It("Converts v1beta3 cluster spec to v1beta1 zone based cluster spec", func() {
ginkgo.Context("v1beta3 to v1beta1 function", func() {
ginkgo.It("Converts v1beta3 cluster spec to v1beta1 zone based cluster spec", func() {
csCluster := &v1beta3.CloudStackCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Expand Down Expand Up @@ -132,11 +132,11 @@ var _ = Describe("Conversion", func() {
Status: v1beta1.CloudStackClusterStatus{},
}

Ω(err).ShouldNot(HaveOccurred())
Ω(converted).Should(Equal(expectedResult))
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(converted).Should(gomega.Equal(expectedResult))
})

It("Returns error when len(failureDomains) < 1", func() {
ginkgo.It("Returns error when len(failureDomains) < 1", func() {
csCluster := &v1beta3.CloudStackCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Expand All @@ -151,7 +151,7 @@ var _ = Describe("Conversion", func() {
Status: v1beta3.CloudStackClusterStatus{},
}
err := v1beta1.Convert_v1beta3_CloudStackCluster_To_v1beta1_CloudStackCluster(csCluster, nil, nil)
Ω(err).Should(HaveOccurred())
gomega.Expect(err).Should(gomega.HaveOccurred())
})
})
})
10 changes: 5 additions & 5 deletions api/v1beta2/cloudstackmachine_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"k8s.io/utils/pointer"
capcv1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)

var _ = Describe("CloudStackMachineConfig_CompressUserdata", func() {
var _ = ginkgo.Describe("CloudStackMachineConfig_CompressUserdata", func() {
for _, tc := range []struct {
Name string
Machine capcv1.CloudStackMachine
Expand Down Expand Up @@ -59,9 +59,9 @@ var _ = Describe("CloudStackMachineConfig_CompressUserdata", func() {
},
} {
tc := tc
It(tc.Name, func() {
ginkgo.It(tc.Name, func() {
result := tc.Machine.CompressUserdata()
Expect(result).To(Equal(tc.Expect))
gomega.Expect(result).To(gomega.Equal(tc.Expect))
})
}
})
50 changes: 25 additions & 25 deletions api/v1beta3/cloudstackcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,66 +19,66 @@ package v1beta3_test
import (
"context"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
dummies "sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies/v1beta3"
)

var _ = Describe("CloudStackCluster webhooks", func() {
var _ = ginkgo.Describe("CloudStackCluster webhooks", func() {
var ctx context.Context
forbiddenRegex := "admission webhook.*denied the request.*Forbidden\\: %s"
requiredRegex := "admission webhook.*denied the request.*Required value\\: %s"

BeforeEach(func() { // Reset test vars to initial state.
ginkgo.BeforeEach(func() { // Reset test vars to initial state.
ctx = context.Background()
dummies.SetDummyVars() // Reset cluster var.
_ = k8sClient.Delete(ctx, dummies.CSCluster) // Delete any remnants.
dummies.SetDummyVars() // Reset again since the k8s client can set this on delete.
})

Context("When creating a CloudStackCluster", func() {
It("Should accept a CloudStackCluster with all attributes present", func() {
Ω(k8sClient.Create(ctx, dummies.CSCluster)).Should(Succeed())
ginkgo.Context("When creating a CloudStackCluster", func() {
ginkgo.It("Should accept a CloudStackCluster with all attributes present", func() {
gomega.Expect(k8sClient.Create(ctx, dummies.CSCluster)).Should(gomega.Succeed())
})

It("Should reject a CloudStackCluster with missing Zones.Network attribute", func() {
ginkgo.It("Should reject a CloudStackCluster with missing Zones.Network attribute", func() {
dummies.CSCluster.Spec.FailureDomains = []infrav1.CloudStackFailureDomainSpec{{}}
dummies.CSCluster.Spec.FailureDomains[0].Zone.Name = "ZoneWNoNetwork"
Ω(k8sClient.Create(ctx, dummies.CSCluster)).Should(
MatchError(MatchRegexp(requiredRegex, "each Zone requires a Network specification")))
gomega.Expect(k8sClient.Create(ctx, dummies.CSCluster)).Should(
gomega.MatchError(gomega.MatchRegexp(requiredRegex, "each Zone requires a Network specification")))
})

It("Should reject a CloudStackCluster with missing Zone attribute", func() {
ginkgo.It("Should reject a CloudStackCluster with missing Zone attribute", func() {
dummies.CSCluster.Spec.FailureDomains[0].Zone = infrav1.CloudStackZoneSpec{}
Ω(k8sClient.Create(ctx, dummies.CSCluster)).Should(MatchError(MatchRegexp(requiredRegex,
gomega.Expect(k8sClient.Create(ctx, dummies.CSCluster)).Should(gomega.MatchError(gomega.MatchRegexp(requiredRegex,
"each Zone requires a Network specification")))
})
})

Context("When updating a CloudStackCluster", func() {
BeforeEach(func() {
Ω(k8sClient.Create(ctx, dummies.CSCluster)).Should(Succeed())
ginkgo.Context("When updating a CloudStackCluster", func() {
ginkgo.BeforeEach(func() {
gomega.Expect(k8sClient.Create(ctx, dummies.CSCluster)).Should(gomega.Succeed())
})

It("Should reject updates to CloudStackCluster FailureDomains", func() {
ginkgo.It("Should reject updates to CloudStackCluster FailureDomains", func() {
dummies.CSCluster.Spec.FailureDomains[0].Zone.Name = "SomeRandomUpdate"
Ω(k8sClient.Update(ctx, dummies.CSCluster)).Should(MatchError(MatchRegexp(forbiddenRegex, "Cannot change FailureDomain")))
gomega.Expect(k8sClient.Update(ctx, dummies.CSCluster)).Should(gomega.MatchError(gomega.MatchRegexp(forbiddenRegex, "Cannot change FailureDomain")))
})
It("Should reject updates to Networks specified in CloudStackCluster Zones", func() {
ginkgo.It("Should reject updates to Networks specified in CloudStackCluster Zones", func() {
dummies.CSCluster.Spec.FailureDomains[0].Zone.Network.Name = "ArbitraryUpdateNetworkName"
Ω(k8sClient.Update(ctx, dummies.CSCluster)).Should(MatchError(MatchRegexp(forbiddenRegex, "Cannot change FailureDomain")))
gomega.Expect(k8sClient.Update(ctx, dummies.CSCluster)).Should(gomega.MatchError(gomega.MatchRegexp(forbiddenRegex, "Cannot change FailureDomain")))
})
It("Should reject updates to CloudStackCluster controlplaneendpoint.host", func() {
ginkgo.It("Should reject updates to CloudStackCluster controlplaneendpoint.host", func() {
dummies.CSCluster.Spec.ControlPlaneEndpoint.Host = "1.1.1.1"
Ω(k8sClient.Update(ctx, dummies.CSCluster)).
Should(MatchError(MatchRegexp(forbiddenRegex, "controlplaneendpoint\\.host")))
gomega.Expect(k8sClient.Update(ctx, dummies.CSCluster)).
Should(gomega.MatchError(gomega.MatchRegexp(forbiddenRegex, "controlplaneendpoint\\.host")))
})

It("Should reject updates to CloudStackCluster controlplaneendpoint.port", func() {
ginkgo.It("Should reject updates to CloudStackCluster controlplaneendpoint.port", func() {
dummies.CSCluster.Spec.ControlPlaneEndpoint.Port = int32(1234)
Ω(k8sClient.Update(ctx, dummies.CSCluster)).
Should(MatchError(MatchRegexp(forbiddenRegex, "controlplaneendpoint\\.port")))
gomega.Expect(k8sClient.Update(ctx, dummies.CSCluster)).
Should(gomega.MatchError(gomega.MatchRegexp(forbiddenRegex, "controlplaneendpoint\\.port")))
})
})
})
Loading