Skip to content

Commit ddd1e65

Browse files
authored
Upgrade golint and fix errors (fixes #692) (#693)
* Upgrade golint and fix errors (fixes #692) * Fix failing test
1 parent af6648a commit ddd1e65

9 files changed

Lines changed: 27 additions & 19 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.15.0
245245
OPERATOR_SDK_VERSION ?= 1.35.0
246246
HELM_VERSION ?= 3.14.2
247247
OPM_VERSION ?= 1.38.0
248-
GOLINT_VERSION ?= 1.59.1
248+
GOLINT_VERSION ?= 1.60.3
249249

250250
.PHONY: cert-manager
251251
cert-manager: ## Install cert-manager to the cluster

apis/cassandra/v1beta1/cassandradatacenter_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ func ValidateDatacenterFieldChanges(oldDc CassandraDatacenter, newDc CassandraDa
212212

213213
if int(newSizeDifference) < minSizeAdjustment {
214214
return attemptedTo(
215-
fmt.Sprintf("add racks without increasing size enough to prevent existing"+
215+
"add racks without increasing size enough to prevent existing"+
216216
" nodes from moving to new racks to maintain balance.\n"+
217217
"New racks added: %d, size increased by: %d. Expected size increase to be at least %d",
218-
newRackCount, newSizeDifference, minSizeAdjustment))
218+
newRackCount, newSizeDifference, minSizeAdjustment)
219219
}
220220
}
221221

pkg/httphelper/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func (client *NodeMgmtClient) CallCreateRoleEndpoint(pod *corev1.Pod, username s
318318
if _, err = callNodeMgmtEndpoint(client, request, ""); err != nil {
319319
// The error could include a password, strip it
320320
strippedErrMsg := strings.ReplaceAll(err.Error(), password, "******")
321-
return fmt.Errorf(strippedErrMsg)
321+
return errors.New(strippedErrMsg)
322322
}
323323
return nil
324324
}

pkg/reconciliation/construct_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func newServiceForCassandraDatacenter(dc *api.CassandraDatacenter) *corev1.Servi
7979
}
8080

8181
func addAdditionalOptions(service *corev1.Service, serviceConfig *api.ServiceConfigAdditions) {
82-
if serviceConfig.Labels != nil && len(serviceConfig.Labels) > 0 {
82+
if len(serviceConfig.Labels) > 0 {
8383
if service.Labels == nil {
8484
service.Labels = make(map[string]string, len(serviceConfig.Labels))
8585
}
@@ -88,7 +88,7 @@ func addAdditionalOptions(service *corev1.Service, serviceConfig *api.ServiceCon
8888
}
8989
}
9090

91-
if serviceConfig.Annotations != nil && len(serviceConfig.Annotations) > 0 {
91+
if len(serviceConfig.Annotations) > 0 {
9292
if service.Annotations == nil {
9393
service.Annotations = make(map[string]string, len(serviceConfig.Annotations))
9494
}

pkg/reconciliation/decommission_node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func (rc *ReconciliationContext) EnsurePodsCanAbsorbDecommData(decommPod *corev1
398398
msg := fmt.Sprintf("Not enough free space available to decommission. %s has %d free space, but %d is needed.",
399399
pod.Name, free, int64(spaceUsedByDecommPod),
400400
)
401-
rc.ReqLogger.Error(fmt.Errorf(msg), msg)
401+
rc.ReqLogger.Error(errors.New(msg), msg)
402402
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeWarning, events.InvalidDatacenterSpec, msg)
403403

404404
if err := rc.setCondition(
@@ -409,7 +409,7 @@ func (rc *ReconciliationContext) EnsurePodsCanAbsorbDecommData(decommPod *corev1
409409
return errors.Wrap(err, msg)
410410
}
411411

412-
return fmt.Errorf(msg)
412+
return errors.New(msg)
413413
}
414414
}
415415

pkg/reconciliation/reconcile_racks.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/k8ssandra/cass-operator/pkg/monitoring"
3131
"github.com/k8ssandra/cass-operator/pkg/oplabels"
3232
"github.com/k8ssandra/cass-operator/pkg/utils"
33+
pkgerrors "github.com/pkg/errors"
3334
)
3435

3536
var (
@@ -230,15 +231,15 @@ func (rc *ReconciliationContext) CheckVolumeClaimSizes(statefulSet, desiredSts *
230231
}
231232

232233
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeWarning, events.InvalidDatacenterSpec, "Shrinking CassandraDatacenter PVCs is not supported")
233-
return result.Error(fmt.Errorf(msg))
234+
return result.Error(pkgerrors.New(msg))
234235
}
235236

236237
if currentSize.Cmp(createdSize) < 0 {
237238
rc.ReqLogger.Info("PVC resize request detected", "pvc", claim.Name, "currentSize", currentSize.String(), "createdSize", createdSize.String())
238239
if !metav1.HasAnnotation(rc.Datacenter.ObjectMeta, api.AllowStorageChangesAnnotation) || rc.Datacenter.Annotations[api.AllowStorageChangesAnnotation] != "true" {
239240
msg := fmt.Sprintf("PVC resize requested, but %s annotation is not set to 'true'", api.AllowStorageChangesAnnotation)
240241
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeWarning, events.InvalidDatacenterSpec, msg)
241-
return result.Error(fmt.Errorf(msg))
242+
return result.Error(pkgerrors.New(msg))
242243
}
243244

244245
supportsExpansion, err := rc.storageExpansion()
@@ -255,7 +256,7 @@ func (rc *ReconciliationContext) CheckVolumeClaimSizes(statefulSet, desiredSts *
255256
)); err != nil {
256257
return result.Error(err)
257258
}
258-
return result.Error(fmt.Errorf(msg))
259+
return result.Error(pkgerrors.New(msg))
259260
}
260261

261262
if err := rc.setConditionStatus(api.DatacenterResizingVolumes, corev1.ConditionTrue); err != nil {
@@ -1688,7 +1689,7 @@ func (rc *ReconciliationContext) ReconcilePods(statefulSet *appsv1.StatefulSet)
16881689
"Update rack labels for Pod %s", podName)
16891690
}
16901691

1691-
if pod.Spec.Volumes == nil || len(pod.Spec.Volumes) == 0 || pod.Spec.Volumes[0].PersistentVolumeClaim == nil {
1692+
if len(pod.Spec.Volumes) == 0 || pod.Spec.Volumes[0].PersistentVolumeClaim == nil {
16921693
continue
16931694
}
16941695

pkg/reconciliation/reconcile_racks_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package reconciliation
66
import (
77
"context"
88
"fmt"
9+
"github.com/pkg/errors"
910
"io"
1011
"net/http"
1112
"reflect"
@@ -1643,7 +1644,7 @@ func TestStripPassword(t *testing.T) {
16431644
func(req *http.Request) bool {
16441645
return req != nil
16451646
})).
1646-
Return(nil, fmt.Errorf(password)).
1647+
Return(nil, errors.New(password)).
16471648
Once()
16481649

16491650
client := httphelper.NodeMgmtClient{
@@ -2472,13 +2473,15 @@ func TestCheckVolumeClaimSizesValidation(t *testing.T) {
24722473
require.NoErrorf(err, "error occurred creating statefulset")
24732474

24742475
res = rc.CheckVolumeClaimSizes(originalStatefulSet, desiredStatefulSet)
2475-
require.Equal(result.Error(fmt.Errorf("PVC resize requested, but cassandra.datastax.com/allow-storage-changes annotation is not set to 'true'")), res, "We should have an error, feature flag is not set")
2476+
_, err = res.Output()
2477+
require.EqualError(err, "PVC resize requested, but cassandra.datastax.com/allow-storage-changes annotation is not set to 'true'", "We should have an error, feature flag is not set")
24762478

24772479
metav1.SetMetaDataAnnotation(&rc.Datacenter.ObjectMeta, api.AllowStorageChangesAnnotation, "true")
24782480
require.NoError(rc.Client.Update(rc.Ctx, rc.Datacenter))
24792481

24802482
res = rc.CheckVolumeClaimSizes(originalStatefulSet, desiredStatefulSet)
2481-
require.Equal(result.Error(fmt.Errorf("PVC resize requested, but StorageClass standard does not support expansion")), res, "We should have an error, StorageClass does not allow expansion")
2483+
_, err = res.Output()
2484+
require.EqualError(err, "PVC resize requested, but StorageClass standard does not support expansion", "We should have an error, StorageClass does not allow expansion")
24822485
cond, found := rc.Datacenter.GetCondition(api.DatacenterValid)
24832486
require.True(found)
24842487
require.Equal(corev1.ConditionFalse, cond.Status)
@@ -2494,7 +2497,8 @@ func TestCheckVolumeClaimSizesValidation(t *testing.T) {
24942497
desiredStatefulSet, err = newStatefulSetForCassandraDatacenter(nil, "default", rc.Datacenter, 2)
24952498
require.NoErrorf(err, "error occurred creating statefulset")
24962499
res = rc.CheckVolumeClaimSizes(originalStatefulSet, desiredStatefulSet)
2497-
require.Equal(result.Error(fmt.Errorf("shrinking PVC %s is not supported", originalStatefulSet.Spec.VolumeClaimTemplates[0].Name)), res, "We should have an error, shrinking is disabled")
2500+
_, err = res.Output()
2501+
require.EqualError(err, fmt.Sprintf("shrinking PVC %s is not supported", originalStatefulSet.Spec.VolumeClaimTemplates[0].Name), "We should have an error, shrinking is disabled")
24982502
cond, found = rc.Datacenter.GetCondition(api.DatacenterValid)
24992503
require.True(found)
25002504
require.Equal(corev1.ConditionFalse, cond.Status)
@@ -2714,7 +2718,8 @@ func TestCheckRackPodTemplateWithVolumeExpansion(t *testing.T) {
27142718
rc.Datacenter.Spec.StorageConfig.CassandraDataVolumeClaimSpec.Resources.Requests = map[corev1.ResourceName]resource.Quantity{corev1.ResourceStorage: resource.MustParse("2Gi")}
27152719
require.NoError(rc.Client.Update(rc.Ctx, rc.Datacenter))
27162720
res = rc.CheckRackPodTemplate()
2717-
require.Equal(result.Error(fmt.Errorf("PVC resize requested, but StorageClass standard does not support expansion")), res, "We should have an error, storageClass does not support expansion")
2721+
_, err := res.Output()
2722+
require.EqualError(err, "PVC resize requested, but StorageClass standard does not support expansion", "We should have an error, storageClass does not support expansion")
27182723

27192724
// Mark the StorageClass as allowing expansion
27202725
storageClass := &storagev1.StorageClass{}

tests/util/ginkgo/lib.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package ginkgo_util
66
import (
77
"encoding/base64"
88
"fmt"
9+
"github.com/pkg/errors"
910
"os"
1011
"path/filepath"
1112
"regexp"
@@ -567,7 +568,7 @@ func (ns NsWrapper) ExpectKeyValue(m map[string]interface{}, key string, expecte
567568
tryFloat64, ok := m[key].(float64)
568569
if !ok {
569570
msg := fmt.Sprintf("Actual value for key %s is not expected type", key)
570-
err := fmt.Errorf(msg)
571+
err := errors.New(msg)
571572
Expect(err).ToNot(HaveOccurred())
572573
}
573574
actualValue = fmt.Sprintf("%f", tryFloat64)

tests/util/kubectl/kubectl.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package kubectl
55

66
import (
77
"fmt"
8+
"github.com/pkg/errors"
89
"os"
910
"os/user"
1011
"regexp"
@@ -321,7 +322,7 @@ func waitForOutputPattern(k KCmd, pattern string, seconds int) error {
321322
if err != nil {
322323
msg = fmt.Sprintf("%s\nThe following error occurred while querying k8s: %v", msg, err)
323324
}
324-
e := fmt.Errorf(msg)
325+
e := errors.New(msg)
325326
return e
326327
case <-c:
327328
return nil

0 commit comments

Comments
 (0)