Skip to content

Commit

Permalink
Cleanup for passing the linter (nutanix-cloud-native#336)
Browse files Browse the repository at this point in the history
* Delete unused code from pkg/context

* Run gofumpt on the code

* Add lint fixes to test package

* Skip linting the conversion functions

The conversion functions are infinitely recursive and cause
linting errors.

* Remove unnecessary statement in lint target

* Revert file-scope licenses
  • Loading branch information
thunderboltsid authored Nov 29, 2023
1 parent 3154cb0 commit 266c300
Showing 26 changed files with 113 additions and 141 deletions.
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -118,10 +118,9 @@ CONVERSION_VERIFIER := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_VERIFIER_BIN))
TILT_PREPARE_BIN := tilt-prepare
TILT_PREPARE := $(abspath $(TOOLS_BIN_DIR)/$(TILT_PREPARE_BIN))

GOLANGCI_LINT_VER := v1.44.0
GOLANGCI_LINT_VER := v1.55.2
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN))
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint

# CRD_OPTIONS define options to add to the CONTROLLER_GEN
CRD_OPTIONS ?= "crd:crdVersions=v1"
@@ -553,24 +552,24 @@ $(TILT_PREPARE): $(TOOLS_DIR)/go.mod # Build tilt-prepare from tools folder.
$(KPROMO):
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KPROMO_PKG) $(KPROMO_BIN) ${KPROMO_VER}

$(GOLANGCI_LINT): # Build golangci-lint from tools folder
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
$(GOLANGCI_LINT): # building golanci-lint from source is not recommended, so we are using the install script
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN_DIR) $(GOLANGCI_LINT_VER)

## --------------------------------------
## Lint / Verify
## --------------------------------------

##@ Lint and Verify

GOLANGCI_LINT_EXTRA_ARGS := --enable gofumpt --build-tags e2e

.PHONY: lint
lint: $(GOLANGCI_LINT) ## Lint the codebase
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)
cd $(TEST_DIR); $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)
cd $(TOOLS_DIR); $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)

.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint
GOLANGCI_LINT_EXTRA_ARGS="$(GOLANGCI_LINT_EXTRA_ARGS) --fix" $(MAKE) lint

## --------------------------------------
## Clean
2 changes: 1 addition & 1 deletion api/v1alpha4/conditions.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ const (
)

const (
//PrismCentralClientCondition indicates the status of the client used to connect to Prism Central
// PrismCentralClientCondition indicates the status of the client used to connect to Prism Central
PrismCentralClientCondition capiv1.ConditionType = "PrismClientInit"

PrismCentralClientInitializationFailed = "PrismClientInitFailed"
16 changes: 13 additions & 3 deletions api/v1alpha4/nutanixcluster_conversion.go
Original file line number Diff line number Diff line change
@@ -31,52 +31,62 @@ func (src *NutanixCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint
}

// ConvertFrom converts from the Hub version (v1beta1) to this NutanixCluster.
func (dst *NutanixCluster) ConvertFrom(srcRaw conversion.Hub) error { // nolint
func (dst *NutanixCluster) ConvertFrom(srcRaw conversion.Hub) error { //nolint
src := srcRaw.(*infrav1beta1.NutanixCluster)
return Convert_v1beta1_NutanixCluster_To_v1alpha4_NutanixCluster(src, dst, nil)
}

// ConvertTo converts this NutanixClusterList to the Hub version (v1beta1).
func (src *NutanixClusterList) ConvertTo(dstRaw conversion.Hub) error { // nolint
func (src *NutanixClusterList) ConvertTo(dstRaw conversion.Hub) error { //nolint
dst := dstRaw.(*infrav1beta1.NutanixClusterList)
return Convert_v1alpha4_NutanixClusterList_To_v1beta1_NutanixClusterList(src, dst, nil)
}

// ConvertFrom converts from the Hub version(v1beta1) to this NutanixClusterList.
func (dst *NutanixClusterList) ConvertFrom(srcRaw conversion.Hub) error { // nolint
func (dst *NutanixClusterList) ConvertFrom(srcRaw conversion.Hub) error { //nolint
src := srcRaw.(*infrav1beta1.NutanixClusterList)
return Convert_v1beta1_NutanixClusterList_To_v1alpha4_NutanixClusterList(src, dst, nil)
}

// Convert_v1alpha4_NutanixClusterSpec_To_v1beta1_NutanixClusterSpec converts NutanixClusterSpec in NutanixClusterResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1alpha4_NutanixClusterSpec_To_v1beta1_NutanixClusterSpec(in *NutanixClusterSpec, out *infrav1beta1.NutanixClusterSpec, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return Convert_v1alpha4_NutanixClusterSpec_To_v1beta1_NutanixClusterSpec(in, out, s)
}

// Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint converts APIEndpoint in NutanixClusterResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint(in *capiv1alpha4.APIEndpoint, out *capiv1beta1.APIEndpoint, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint(in, out, s)
}

// Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint converts APIEndpoint in NutanixClusterResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in *capiv1beta1.APIEndpoint, out *capiv1alpha4.APIEndpoint, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in, out, s)
}

// Convert_v1beta1_NutanixClusterSpec_To_v1alpha4_NutanixClusterSpec converts NutanixClusterSpec in NutanixClusterResource from v1beta1 to v1alpha4 version.
//
//nolint:all
func Convert_v1beta1_NutanixClusterSpec_To_v1alpha4_NutanixClusterSpec(in *infrav1beta1.NutanixClusterSpec, out *NutanixClusterSpec, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return Convert_v1beta1_NutanixClusterSpec_To_v1alpha4_NutanixClusterSpec(in, out, s)
}

// Convert_v1alpha4_NutanixClusterStatus_To_v1beta1_NutanixClusterStatus converts NutanixClusterStatus in NutanixClusterResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1alpha4_NutanixClusterStatus_To_v1beta1_NutanixClusterStatus(in *NutanixClusterStatus, out *infrav1beta1.NutanixClusterStatus, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
6 changes: 6 additions & 0 deletions api/v1alpha4/nutanixmachine_conversion.go
Original file line number Diff line number Diff line change
@@ -47,20 +47,26 @@ func (dst *NutanixMachineList) ConvertFrom(srcRaw conversion.Hub) error { // nol
}

// Convert_v1alpha4_NutanixMachineSpec_To_v1beta1_NutanixMachineSpec converts NutanixMachineSpec in NutanixMachineResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1alpha4_NutanixMachineSpec_To_v1beta1_NutanixMachineSpec(in *NutanixMachineSpec, out *infrav1beta1.NutanixMachineSpec, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return Convert_v1alpha4_NutanixMachineSpec_To_v1beta1_NutanixMachineSpec(in, out, s)
}

// Convert_v1beta1_NutanixMachineSpec_To_v1alpha4_NutanixMachineSpec converts NutanixMachineSpec in NutanixMachineResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1beta1_NutanixMachineSpec_To_v1alpha4_NutanixMachineSpec(in *infrav1beta1.NutanixMachineSpec, out *NutanixMachineSpec, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return Convert_v1beta1_NutanixMachineSpec_To_v1alpha4_NutanixMachineSpec(in, out, s)
}

// Convert_v1alpha4_NutanixMachineStatus_To_v1beta1_NutanixMachineStatus converts NutanixMachineStatus in NutanixMachineResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1alpha4_NutanixMachineStatus_To_v1beta1_NutanixMachineStatus(in *NutanixMachineStatus, out *infrav1beta1.NutanixMachineStatus, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
8 changes: 8 additions & 0 deletions api/v1alpha4/nutanixmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
@@ -59,27 +59,35 @@ func (dst *NutanixMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error
}

// Convert_v1alpha4_ObjectMeta_To_v1beta1_ObjectMeta converts ObjectMeta in NutanixMachineTemplateResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1alpha4_ObjectMeta_To_v1beta1_ObjectMeta(in *capiv1alpha4.ObjectMeta, out *capiv1beta1.ObjectMeta, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return capiv1alpha4.Convert_v1alpha4_ObjectMeta_To_v1beta1_ObjectMeta(in, out, s)
}

// Convert_v1beta1_ObjectMeta_To_v1alpha4_ObjectMeta converts ObjectMeta in NutanixMachineTemplateResource from v1beta1 to v1alpha4 version.
//
//nolint:all
func Convert_v1beta1_ObjectMeta_To_v1alpha4_ObjectMeta(in *capiv1beta1.ObjectMeta, out *capiv1alpha4.ObjectMeta, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return capiv1alpha4.Convert_v1beta1_ObjectMeta_To_v1alpha4_ObjectMeta(in, out, s)
}

// Convert_v1alpha4_NutanixMachineTemplateResource_To_v1beta1_NutanixMachineTemplateResource converts NutanixMachineTemplateResource in NutanixMachineTemplateResource from v1alpha4 to v1beta1 version.
//
//nolint:all
func Convert_v1alpha4_NutanixMachineTemplateResource_To_v1beta1_NutanixMachineTemplateResource(in *NutanixMachineTemplateResource, out *infrav1beta1.NutanixMachineTemplateResource, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
return Convert_v1alpha4_NutanixMachineTemplateResource_To_v1beta1_NutanixMachineTemplateResource(in, out, s)
}

// Convert_v1beta1_NutanixMachineTemplateResource_To_v1alpha4_NutanixMachineTemplateResource converts NutanixMachineTemplateResource in NutanixMachineTemplateResource from v1beta1 to v1alpha4 version.
//
//nolint:all
func Convert_v1beta1_NutanixMachineTemplateResource_To_v1alpha4_NutanixMachineTemplateResource(in *infrav1beta1.NutanixMachineTemplateResource, out *NutanixMachineTemplateResource, s apiconversion.Scope) error {
// Wrapping the conversion function to avoid compilation errors due to compileErrorOnMissingConversion()
// Ref: https://github.com/kubernetes/kubernetes/issues/98380
25 changes: 0 additions & 25 deletions pkg/context/context.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ package context

import (
"context"
"errors"
"fmt"
"sync"

@@ -71,30 +70,6 @@ func IsControlPlaneMachine(nma *infrav1.NutanixMachine) bool {
return ok
}

// ErrNoMachineIPAddr indicates that no valid IP addresses were found in a machine context
var ErrNoMachineIPAddr = errors.New("no IP addresses found for machine")

// GetMachinePreferredIPAddress returns the preferred IP address associated with the NutanixMachine
func GetMachinePreferredIPAddress(nma *infrav1.NutanixMachine) (string, error) {
var internalIP, externalIP string
for _, addr := range nma.Status.Addresses {
if addr.Type == capiv1.MachineExternalIP {
externalIP = addr.Address
} else if addr.Type == capiv1.MachineInternalIP {
internalIP = addr.Address
}
}

if len(externalIP) > 0 {
return externalIP, nil
}
if len(internalIP) > 0 {
return internalIP, nil
}

return "", ErrNoMachineIPAddr
}

// GetNutanixMachinesInCluster gets a cluster's NutanixMachine resources.
func (clctx *ClusterContext) GetNutanixMachinesInCluster(client ctlclient.Client) ([]*infrav1.NutanixMachine, error) {
clusterName := clctx.NutanixCluster.Name
1 change: 0 additions & 1 deletion test/e2e/basic_uuid_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

/*
Copyright 2022 Nutanix
1 change: 0 additions & 1 deletion test/e2e/capx_quick_start_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

/*
Copyright 2020 The Kubernetes Authors.
18 changes: 5 additions & 13 deletions test/e2e/capx_regression.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

/*
Copyright 2022 Nutanix
@@ -22,28 +21,21 @@ package e2e
import (
"context"

infrav1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"

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

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/controller-runtime/pkg/client"

infrav1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
)

var _ = Describe("Nutanix regression tests", Label("capx-regression-test", "regression", "slow", "network"), func() {
const (
specName = "capx-regression"

controlplaneEndpointIPKey = envVarControlPlaneEndpointIP
controlplaneEndpointPortKey = envVarControlPlaneEndpointPort
defaultControlPlaneEndpointPort = 6443
)
const specName = "capx-regression"

var (
namespace *corev1.Namespace
@@ -188,7 +180,7 @@ var _ = Describe("Nutanix regression tests", Label("capx-regression-test", "regr
}, e2eConfig.GetIntervals(specName, "wait-delete-cluster")...)
})

//Check if secret is deleted
// Check if secret is deleted
By("Checking if secret is deleted", func() {
err := bootstrapClusterProxy.GetClient().Get(ctx,
client.ObjectKey{
@@ -199,7 +191,7 @@ var _ = Describe("Nutanix regression tests", Label("capx-regression-test", "regr
Expect(apierrors.IsNotFound(err)).To(BeTrue())
})

//Check if cluster is deleted
// Check if cluster is deleted
By("Checking if cluster is deleted", func() {
err := bootstrapClusterProxy.GetClient().Get(ctx,
client.ObjectKey{
1 change: 0 additions & 1 deletion test/e2e/categories_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

/*
Copyright 2022 Nutanix
1 change: 0 additions & 1 deletion test/e2e/ccm_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

/*
Copyright 2022 Nutanix
1 change: 0 additions & 1 deletion test/e2e/cluster_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

/*
Copyright 2022 Nutanix, Inc
1 change: 0 additions & 1 deletion test/e2e/clusterctl_upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

/*
Copyright 2020 The Kubernetes Authors.
2 changes: 2 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build e2e

/*
Copyright 2020 The Kubernetes Authors.
1 change: 0 additions & 1 deletion test/e2e/csi_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

/*
Copyright 2022 Nutanix
Loading

0 comments on commit 266c300

Please sign in to comment.