Skip to content

Commit

Permalink
Merge pull request #30 from Leaseweb/develop
Browse files Browse the repository at this point in the history
chore: lint fixes
  • Loading branch information
hrak authored Sep 4, 2024
2 parents db5cf80 + b514c8a commit bb09e9f
Show file tree
Hide file tree
Showing 96 changed files with 1,222 additions and 766 deletions.
87 changes: 77 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
linters-settings:
cyclop:
max-complexity: 20
gci:
sections:
- standard
- default
- prefix(sigs.k8s.io/cluster-api-provider-cloudstack)
gocritic:
enabled-tags:
- diagnostic
- experimental
- performance
disabled-checks:
- appendAssign
- dupImport # https://github.com/go-critic/go-critic/issues/845
- emptyStringTest
- evalOrder
- ifElseChain
- octalLiteral
- regexpSimplify
- sloppyReassign
- truncateCmp
- typeDefFirst
- unnamedResult
- unnecessaryDefer
- whyNoLint
- wrapperFunc
- rangeValCopy
- hugeParam
gocyclo:
min-complexity: 15
goheader:
values:
const:
Expand All @@ -19,8 +50,11 @@ linters-settings:
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
gocyclo:
min-complexity: 15
goimports:
local-prefixes: sigs.k8s.io/cluster-api-provider-cloudstack
nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 8
revive:
rules:
- name: dot-imports
Expand All @@ -31,18 +65,36 @@ linters-settings:
- "github.com/onsi/gomega"

linters:
enable:
- gocyclo
- goheader
- gosec
- misspell
- revive
- staticcheck
disable:
- containedctx
- depguard
- err113
- execinquery
- exhaustruct
- forcetypeassert
- funlen
- gochecknoglobals
- gochecknoinits
- godox
- gomnd
- interfacebloat
- ireturn
- lll
- mnd
- nonamedreturns
- paralleltest
- tagliatelle
- varnamelen
- wrapcheck
- wsl
enable-all: true

run:
issues-exit-code: 1

issues:
max-same-issues: 0
max-issues-per-linter: 0
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-dirs:
- pkg/mocks
Expand All @@ -51,7 +103,22 @@ issues:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- dupl
- gosec
- text: "SA1019: .+LBRuleID is deprecated"
linters:
- staticcheck
- staticcheck
- path: api/v1beta3/webhook_suite_test.go
linters:
- goimports
- linters:
- revive
- stylecheck
path: (test)/.*.go
text: should not use dot imports
- linters:
- stylecheck
text: "ST1003: should not use underscores in Go names;"
path: api\/.*\/.*conversion.*\.go$
exclude-files:
- "zz_generated.*\\.go$"
2 changes: 2 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
domain: cluster.x-k8s.io
layout:
- go.kubebuilder.io/v3
projectName: cluster-api-provider-capc
repo: sigs.k8s.io/cluster-api-provider-cloudstack
resources:
Expand Down
20 changes: 11 additions & 9 deletions api/v1beta1/cloudstackaffinitygroup_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,40 @@ package v1beta1

import (
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
)

func (src *CloudStackAffinityGroup) ConvertTo(dstRaw conversion.Hub) error { // nolint
func (r *CloudStackAffinityGroup) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta3.CloudStackAffinityGroup)
if err := Convert_v1beta1_CloudStackAffinityGroup_To_v1beta3_CloudStackAffinityGroup(src, dst, nil); err != nil {
if err := Convert_v1beta1_CloudStackAffinityGroup_To_v1beta3_CloudStackAffinityGroup(r, dst, nil); err != nil {
return err
}

// Manually restore data
restored := &v1beta3.CloudStackAffinityGroup{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
return err
}
if restored.Spec.FailureDomainName != "" {
dst.Spec.FailureDomainName = restored.Spec.FailureDomainName
}

return nil
}

func (dst *CloudStackAffinityGroup) ConvertFrom(srcRaw conversion.Hub) error { // nolint
func (r *CloudStackAffinityGroup) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta3.CloudStackAffinityGroup)
if err := Convert_v1beta3_CloudStackAffinityGroup_To_v1beta1_CloudStackAffinityGroup(src, dst, nil); err != nil {
if err := Convert_v1beta3_CloudStackAffinityGroup_To_v1beta1_CloudStackAffinityGroup(src, r, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion
return utilconversion.MarshalData(src, dst)
// Preserve Hub data on down-conversion.
return utilconversion.MarshalData(src, r)
}

func Convert_v1beta3_CloudStackAffinityGroupSpec_To_v1beta1_CloudStackAffinityGroupSpec(in *v1beta3.CloudStackAffinityGroupSpec, out *CloudStackAffinityGroupSpec, s machineryconversion.Scope) error { // nolint
func Convert_v1beta3_CloudStackAffinityGroupSpec_To_v1beta1_CloudStackAffinityGroupSpec(in *v1beta3.CloudStackAffinityGroupSpec, out *CloudStackAffinityGroupSpec, s machineryconversion.Scope) error {
return autoConvert_v1beta3_CloudStackAffinityGroupSpec_To_v1beta1_CloudStackAffinityGroupSpec(in, out, s)
}
8 changes: 4 additions & 4 deletions api/v1beta1/cloudstackaffinitygroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
AffinityGroupFinalizer = "affinitygroup.infrastructure.cluster.x-k8s.io"
)

// CloudStackAffinityGroupSpec defines the desired state of CloudStackAffinityGroup
// CloudStackAffinityGroupSpec defines the desired state of CloudStackAffinityGroup.
type CloudStackAffinityGroupSpec struct {
// Mutually exclusive parameter with AffinityGroupIDs.
// Can be "host affinity", "host anti-affinity", "non-strict host affinity"or "non-strict host anti-affinity". Will create an affinity group per machine set.
Expand All @@ -38,7 +38,7 @@ type CloudStackAffinityGroupSpec struct {
ID string `json:"id,omitempty"`
}

// CloudStackAffinityGroupStatus defines the observed state of CloudStackAffinityGroup
// CloudStackAffinityGroupStatus defines the observed state of CloudStackAffinityGroup.
type CloudStackAffinityGroupStatus struct {
// Reflects the readiness of the CS Affinity Group.
Ready bool `json:"ready"`
Expand All @@ -47,7 +47,7 @@ type CloudStackAffinityGroupStatus struct {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// CloudStackAffinityGroup is the Schema for the cloudstackaffinitygroups API
// CloudStackAffinityGroup is the Schema for the cloudstackaffinitygroups API.
type CloudStackAffinityGroup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -58,7 +58,7 @@ type CloudStackAffinityGroup struct {

//+kubebuilder:object:root=true

// CloudStackAffinityGroupList contains a list of CloudStackAffinityGroup
// CloudStackAffinityGroupList contains a list of CloudStackAffinityGroup.
type CloudStackAffinityGroupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
13 changes: 8 additions & 5 deletions api/v1beta1/cloudstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ limitations under the License.
package v1beta1

import (
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
"sigs.k8s.io/controller-runtime/pkg/conversion"

"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
)

func (src *CloudStackCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint
func (r *CloudStackCluster) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta3.CloudStackCluster)
return Convert_v1beta1_CloudStackCluster_To_v1beta3_CloudStackCluster(src, dst, nil)

return Convert_v1beta1_CloudStackCluster_To_v1beta3_CloudStackCluster(r, dst, nil)
}

func (dst *CloudStackCluster) ConvertFrom(srcRaw conversion.Hub) error { // nolint
func (r *CloudStackCluster) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta3.CloudStackCluster)
return Convert_v1beta3_CloudStackCluster_To_v1beta1_CloudStackCluster(src, dst, nil)

return Convert_v1beta3_CloudStackCluster_To_v1beta1_CloudStackCluster(src, r, nil)
}
10 changes: 5 additions & 5 deletions api/v1beta1/cloudstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const (
NetworkTypeShared = "Shared"
)

// CloudStackIdentityReference is a reference to an infrastructure
// CloudStackIdentityReference is a reference to an infrastructure.
// provider identity to be used to provision cluster resources.
type CloudStackIdentityReference struct {
// Kind of the identity. Must be supported by the infrastructure provider
// Kind of the identity. Must be supported by the infrastructure provider,
// and may be either cluster or namespace-scoped.
// +kubebuilder:validation:MinLength=1
Kind string `json:"kind"`
Expand Down Expand Up @@ -78,6 +78,7 @@ func (z *Zone) MetaName() string {
if s == "" {
s = z.ID
}

return strings.ToLower(s)
}

Expand All @@ -104,7 +105,6 @@ type CloudStackClusterSpec struct {
// +k8s:conversion-gen=false
// The status of the abstract CS k8s (not an actual Cloudstack Cluster) cluster.
type CloudStackClusterStatus struct {

// The status of the cluster's ACS Zones.
// +optional
Zones ZoneStatusMap `json:"zones,omitempty"`
Expand Down Expand Up @@ -133,7 +133,7 @@ type CloudStackClusterStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +k8s:conversion-gen=false
// CloudStackCluster is the Schema for the cloudstackclusters API
// CloudStackCluster is the Schema for the cloudstackclusters API.
type CloudStackCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -146,7 +146,7 @@ type CloudStackCluster struct {

// +kubebuilder:object:root=true
// +k8s:conversion-gen=false
// CloudStackClusterList contains a list of CloudStackCluster
// CloudStackClusterList contains a list of CloudStackCluster.
type CloudStackClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
35 changes: 19 additions & 16 deletions api/v1beta1/cloudstackisolatednetwork_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,58 @@ package v1beta1

import (
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
)

func (src *CloudStackIsolatedNetwork) ConvertTo(dstRaw conversion.Hub) error { // nolint
dst := dstRaw.(*v1beta3.CloudStackIsolatedNetwork)
if err := Convert_v1beta1_CloudStackIsolatedNetwork_To_v1beta3_CloudStackIsolatedNetwork(src, dst, nil); err != nil {
func (r *CloudStackIsolatedNetwork) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1.CloudStackIsolatedNetwork)
if err := Convert_v1beta1_CloudStackIsolatedNetwork_To_v1beta3_CloudStackIsolatedNetwork(r, dst, nil); err != nil {
return err
}

// Manually restore data
restored := &v1beta3.CloudStackIsolatedNetwork{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
// Manually restore data.
restored := &infrav1.CloudStackIsolatedNetwork{}
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
return err
}
if restored.Spec.FailureDomainName != "" {
dst.Spec.FailureDomainName = restored.Spec.FailureDomainName
}

return nil
}

func (dst *CloudStackIsolatedNetwork) ConvertFrom(srcRaw conversion.Hub) error { // nolint
src := srcRaw.(*v1beta3.CloudStackIsolatedNetwork)
if err := Convert_v1beta3_CloudStackIsolatedNetwork_To_v1beta1_CloudStackIsolatedNetwork(src, dst, nil); err != nil {
func (r *CloudStackIsolatedNetwork) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.CloudStackIsolatedNetwork)
if err := Convert_v1beta3_CloudStackIsolatedNetwork_To_v1beta1_CloudStackIsolatedNetwork(src, r, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion
return utilconversion.MarshalData(src, dst)
// Preserve Hub data on down-conversion.
return utilconversion.MarshalData(src, r)
}

func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in *v1beta3.CloudStackIsolatedNetworkSpec, out *CloudStackIsolatedNetworkSpec, s machineryconversion.Scope) error { // nolint
func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in *infrav1.CloudStackIsolatedNetworkSpec, out *CloudStackIsolatedNetworkSpec, s machineryconversion.Scope) error {
return autoConvert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in, out, s)
}

func Convert_v1beta1_CloudStackIsolatedNetworkStatus_To_v1beta3_CloudStackIsolatedNetworkStatus(in *CloudStackIsolatedNetworkStatus, out *v1beta3.CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
func Convert_v1beta1_CloudStackIsolatedNetworkStatus_To_v1beta3_CloudStackIsolatedNetworkStatus(in *CloudStackIsolatedNetworkStatus, out *infrav1.CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.APIServerLoadBalancer = &infrav1.LoadBalancer{}
out.LoadBalancerRuleIDs = []string{in.LBRuleID}
out.Ready = in.Ready

return nil
}

func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta1_CloudStackIsolatedNetworkStatus(in *v1beta3.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta1_CloudStackIsolatedNetworkStatus(in *infrav1.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.Ready = in.Ready

return nil
}
Loading

0 comments on commit bb09e9f

Please sign in to comment.