Skip to content

Commit

Permalink
Upgrade golint and fix errors (fixes #692)
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t committed Aug 28, 2024
1 parent af6648a commit 635f9c0
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.15.0
OPERATOR_SDK_VERSION ?= 1.35.0
HELM_VERSION ?= 3.14.2
OPM_VERSION ?= 1.38.0
GOLINT_VERSION ?= 1.59.1
GOLINT_VERSION ?= 1.60.3

.PHONY: cert-manager
cert-manager: ## Install cert-manager to the cluster
Expand Down
4 changes: 2 additions & 2 deletions apis/cassandra/v1beta1/cassandradatacenter_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ func ValidateDatacenterFieldChanges(oldDc CassandraDatacenter, newDc CassandraDa

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/httphelper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (client *NodeMgmtClient) CallCreateRoleEndpoint(pod *corev1.Pod, username s
if _, err = callNodeMgmtEndpoint(client, request, ""); err != nil {
// The error could include a password, strip it
strippedErrMsg := strings.ReplaceAll(err.Error(), password, "******")
return fmt.Errorf(strippedErrMsg)
return errors.New(strippedErrMsg)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciliation/construct_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func newServiceForCassandraDatacenter(dc *api.CassandraDatacenter) *corev1.Servi
}

func addAdditionalOptions(service *corev1.Service, serviceConfig *api.ServiceConfigAdditions) {
if serviceConfig.Labels != nil && len(serviceConfig.Labels) > 0 {
if len(serviceConfig.Labels) > 0 {
if service.Labels == nil {
service.Labels = make(map[string]string, len(serviceConfig.Labels))
}
Expand All @@ -88,7 +88,7 @@ func addAdditionalOptions(service *corev1.Service, serviceConfig *api.ServiceCon
}
}

if serviceConfig.Annotations != nil && len(serviceConfig.Annotations) > 0 {
if len(serviceConfig.Annotations) > 0 {
if service.Annotations == nil {
service.Annotations = make(map[string]string, len(serviceConfig.Annotations))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciliation/decommission_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (rc *ReconciliationContext) EnsurePodsCanAbsorbDecommData(decommPod *corev1
msg := fmt.Sprintf("Not enough free space available to decommission. %s has %d free space, but %d is needed.",
pod.Name, free, int64(spaceUsedByDecommPod),
)
rc.ReqLogger.Error(fmt.Errorf(msg), msg)
rc.ReqLogger.Error(errors.New(msg), msg)
rc.Recorder.Eventf(rc.Datacenter, corev1.EventTypeWarning, events.InvalidDatacenterSpec, msg)

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

return fmt.Errorf(msg)
return errors.New(msg)
}
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/reconciliation/reconcile_racks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/k8ssandra/cass-operator/pkg/monitoring"
"github.com/k8ssandra/cass-operator/pkg/oplabels"
"github.com/k8ssandra/cass-operator/pkg/utils"
pkgerrors "github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -230,15 +231,15 @@ func (rc *ReconciliationContext) CheckVolumeClaimSizes(statefulSet, desiredSts *
}

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

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

supportsExpansion, err := rc.storageExpansion()
Expand All @@ -255,7 +256,7 @@ func (rc *ReconciliationContext) CheckVolumeClaimSizes(statefulSet, desiredSts *
)); err != nil {
return result.Error(err)
}
return result.Error(fmt.Errorf(msg))
return result.Error(pkgerrors.New(msg))
}

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

if pod.Spec.Volumes == nil || len(pod.Spec.Volumes) == 0 || pod.Spec.Volumes[0].PersistentVolumeClaim == nil {
if len(pod.Spec.Volumes) == 0 || pod.Spec.Volumes[0].PersistentVolumeClaim == nil {
continue
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciliation/reconcile_racks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package reconciliation
import (
"context"
"fmt"
"github.com/pkg/errors"
"io"
"net/http"
"reflect"
Expand Down Expand Up @@ -1643,7 +1644,7 @@ func TestStripPassword(t *testing.T) {
func(req *http.Request) bool {
return req != nil
})).
Return(nil, fmt.Errorf(password)).
Return(nil, errors.New(password)).
Once()

client := httphelper.NodeMgmtClient{
Expand Down
3 changes: 2 additions & 1 deletion tests/util/ginkgo/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ginkgo_util
import (
"encoding/base64"
"fmt"
"github.com/pkg/errors"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -567,7 +568,7 @@ func (ns NsWrapper) ExpectKeyValue(m map[string]interface{}, key string, expecte
tryFloat64, ok := m[key].(float64)
if !ok {
msg := fmt.Sprintf("Actual value for key %s is not expected type", key)
err := fmt.Errorf(msg)
err := errors.New(msg)
Expect(err).ToNot(HaveOccurred())
}
actualValue = fmt.Sprintf("%f", tryFloat64)
Expand Down
3 changes: 2 additions & 1 deletion tests/util/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package kubectl

import (
"fmt"
"github.com/pkg/errors"
"os"
"os/user"
"regexp"
Expand Down Expand Up @@ -321,7 +322,7 @@ func waitForOutputPattern(k KCmd, pattern string, seconds int) error {
if err != nil {
msg = fmt.Sprintf("%s\nThe following error occurred while querying k8s: %v", msg, err)
}
e := fmt.Errorf(msg)
e := errors.New(msg)
return e
case <-c:
return nil
Expand Down

0 comments on commit 635f9c0

Please sign in to comment.