Skip to content

Commit 978216a

Browse files
authored
Merge pull request #2173 from shiftstack/linter
🌱 Bump golangci-lint to v1.61.0
2 parents a84b1b4 + d6c93e7 commit 978216a

11 files changed

+27
-21
lines changed

.golangci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ linters:
55
- asciicheck
66
- bidichk
77
- bodyclose
8+
- copyloopvar
89
- cyclop
9-
# - depguard
1010
- dogsled
1111
- dupword
1212
- durationcheck
1313
- errcheck
14-
- exportloopref
1514
- forbidigo
1615
- gci
1716
- goconst

controllers/openstackcluster_controller.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"math"
2324
"time"
2425

2526
"github.com/gophercloud/gophercloud/v2/openstack/networking/v2/networks"
@@ -759,7 +760,10 @@ func reconcileProvisionedNetworkComponents(networkingService *networking.Service
759760
// cluster spec.
760761
func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *networking.Service, openStackCluster *infrav1.OpenStackCluster, clusterResourceName string) error {
761762
// Calculate the port that we will use for the API server
762-
apiServerPort := getAPIServerPort(openStackCluster)
763+
apiServerPort, err := getAPIServerPort(openStackCluster)
764+
if err != nil {
765+
return err
766+
}
763767

764768
// host must be set by a matching control plane endpoint provider below
765769
var host string
@@ -774,7 +778,7 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
774778
return err
775779
}
776780

777-
terminalFailure, err := loadBalancerService.ReconcileLoadBalancer(openStackCluster, clusterResourceName, apiServerPort)
781+
terminalFailure, err := loadBalancerService.ReconcileLoadBalancer(openStackCluster, clusterResourceName, int(apiServerPort))
778782
if err != nil {
779783
handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to reconcile load balancer: %w", err), terminalFailure)
780784
return fmt.Errorf("failed to reconcile load balancer: %w", err)
@@ -819,21 +823,27 @@ func reconcileControlPlaneEndpoint(scope *scope.WithLogger, networkingService *n
819823

820824
openStackCluster.Spec.ControlPlaneEndpoint = &clusterv1.APIEndpoint{
821825
Host: host,
822-
Port: int32(apiServerPort),
826+
Port: apiServerPort,
823827
}
824828

825829
return nil
826830
}
827831

828832
// getAPIServerPort returns the port to use for the API server based on the cluster spec.
829-
func getAPIServerPort(openStackCluster *infrav1.OpenStackCluster) int {
833+
func getAPIServerPort(openStackCluster *infrav1.OpenStackCluster) (int32, error) {
830834
switch {
831835
case openStackCluster.Spec.ControlPlaneEndpoint != nil && openStackCluster.Spec.ControlPlaneEndpoint.IsValid():
832-
return int(openStackCluster.Spec.ControlPlaneEndpoint.Port)
836+
return openStackCluster.Spec.ControlPlaneEndpoint.Port, nil
833837
case openStackCluster.Spec.APIServerPort != nil:
834-
return *openStackCluster.Spec.APIServerPort
838+
// XXX: This highlights that we have missing validation on
839+
// APIServerPort. We should ideally add validation and change its type
840+
// to int32.
841+
if *openStackCluster.Spec.APIServerPort > math.MaxInt32 {
842+
return 0, fmt.Errorf("value of apiServerPort is larger than %d", math.MaxInt32)
843+
}
844+
return int32(*openStackCluster.Spec.APIServerPort), nil //nolint:gosec
835845
}
836-
return 6443
846+
return 6443, nil
837847
}
838848

839849
func (r *OpenStackClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {

controllers/openstackcluster_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func Test_getAPIServerPort(t *testing.T) {
467467
tests := []struct {
468468
name string
469469
openStackCluster *infrav1.OpenStackCluster
470-
want int
470+
want int32
471471
}{
472472
{
473473
name: "default",
@@ -498,7 +498,7 @@ func Test_getAPIServerPort(t *testing.T) {
498498
}
499499
for _, tt := range tests {
500500
t.Run(tt.name, func(t *testing.T) {
501-
if got := getAPIServerPort(tt.openStackCluster); got != tt.want {
501+
if got, _ := getAPIServerPort(tt.openStackCluster); got != tt.want {
502502
t.Errorf("getAPIServerPort() = %v, want %v", got, tt.want)
503503
}
504504
})

controllers/openstackfloatingippool_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ func (r *OpenStackFloatingIPPoolReconciler) Reconcile(ctx context.Context, req c
125125
}
126126

127127
for _, claim := range claims.Items {
128-
claim := claim
129128
log := log.WithValues("claim", claim.Name)
130129
if !claim.ObjectMeta.DeletionTimestamp.IsZero() {
131130
continue

controllers/openstackserver_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (r *OpenStackServerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
117117
// Propagate terminal errors
118118
terminalError := &capoerrors.TerminalError{}
119119
if errors.As(reterr, &terminalError) {
120-
conditions.MarkFalse(openStackServer, infrav1.InstanceReadyCondition, terminalError.Reason, clusterv1.ConditionSeverityError, terminalError.Message)
120+
conditions.MarkFalse(openStackServer, infrav1.InstanceReadyCondition, terminalError.Reason, clusterv1.ConditionSeverityError, "%s", terminalError.Message)
121121
}
122122

123123
if err := patchServer(ctx, patchHelper, openStackServer); err != nil {
@@ -465,7 +465,7 @@ func (r *OpenStackServerReconciler) getOrCreateServer(ctx context.Context, logge
465465
instanceStatus, err = computeService.GetInstanceStatus(*openStackServer.Status.InstanceID)
466466
if err != nil {
467467
logger.Info("Unable to get OpenStack instance", "name", openStackServer.Name)
468-
conditions.MarkFalse(openStackServer, infrav1.InstanceReadyCondition, infrav1.OpenStackErrorReason, clusterv1.ConditionSeverityError, err.Error())
468+
conditions.MarkFalse(openStackServer, infrav1.InstanceReadyCondition, infrav1.OpenStackErrorReason, clusterv1.ConditionSeverityError, "%s", err.Error())
469469
return nil, err
470470
}
471471
}
@@ -494,7 +494,7 @@ func (r *OpenStackServerReconciler) getOrCreateServer(ctx context.Context, logge
494494
instanceSpec.Name = openStackServer.Name
495495
instanceStatus, err = computeService.CreateInstance(openStackServer, instanceSpec, portIDs)
496496
if err != nil {
497-
conditions.MarkFalse(openStackServer, infrav1.InstanceReadyCondition, infrav1.InstanceCreateFailedReason, clusterv1.ConditionSeverityError, err.Error())
497+
conditions.MarkFalse(openStackServer, infrav1.InstanceReadyCondition, infrav1.InstanceCreateFailedReason, clusterv1.ConditionSeverityError, "%s", err.Error())
498498
openStackServer.Status.InstanceState = &infrav1.InstanceStateError
499499
return nil, fmt.Errorf("create OpenStack instance: %w", err)
500500
}

hack/tools/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ROOT_DIR_RELATIVE := ../..
1616
include $(ROOT_DIR_RELATIVE)/common.mk
1717

18-
GOLANGCI_LINT_VERSION ?= v1.57.2
18+
GOLANGCI_LINT_VERSION ?= v1.61.0
1919

2020
# GOTESTSUM version without the leading 'v'
2121
GOTESTSUM_VERSION ?= 1.11.0

orc/.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ issues:
1919
linters:
2020
disable-all: true
2121
enable:
22+
- copyloopvar
2223
- dupl
2324
- errcheck
24-
- exportloopref
2525
- ginkgolinter
2626
- goconst
2727
- gocyclo

orc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
177177
KUSTOMIZE_VERSION ?= v5.4.2
178178
CONTROLLER_TOOLS_VERSION ?= v0.15.0
179179
ENVTEST_VERSION ?= release-0.18
180-
GOLANGCI_LINT_VERSION ?= v1.59.1
180+
GOLANGCI_LINT_VERSION ?= v1.61.0
181181

182182
.PHONY: kustomize
183183
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.

pkg/webhooks/openstackmachinetemplate_webhook_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
184184
}
185185

186186
for _, tt := range tests {
187-
tt := tt
188187
t.Run(tt.name, func(t *testing.T) {
189188
t.Parallel()
190189

pkg/webhooks/openstackserver_webhook_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ func TestOpenStackServer_ValidateUpdate(t *testing.T) {
112112
}
113113

114114
for _, tt := range tests {
115-
tt := tt
116115
t.Run(tt.name, func(t *testing.T) {
117116
t.Parallel()
118117

test/e2e/shared/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func executeCommand(ctx context.Context, p commandParameter) error {
146146
return fmt.Errorf("unable to send command %q: %s", "sudo "+p.cmd.cmd, err)
147147
}
148148
result := strings.TrimSuffix(stdoutBuf.String(), "\n") + "\n" + strings.TrimSuffix(stderrBuf.String(), "\n")
149-
if err := os.WriteFile(logFile, []byte(result), os.ModePerm); err != nil {
149+
if err := os.WriteFile(logFile, []byte(result), 0o600); err != nil {
150150
return fmt.Errorf("error writing log file: %s", err)
151151
}
152152
Debugf(p.debug, "finished executing cmd %q on machine %s", p.cmd.cmd, p.machineIP)

0 commit comments

Comments
 (0)