Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address linter issues while moving to golangci version 1.62.0 #1674

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ramen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
- name: GolangCI Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55.2
version: v1.62.0
working-directory: ${{ matrix.directory }}

unit-test:
Expand Down
22 changes: 11 additions & 11 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ linters:
- asciicheck
- bidichk
- bodyclose
# - copyloopvar // Additional new replacement for go 1.22 (https://go.dev/blog/loopvar-preview) (deprecating exportloopref)
- cyclop
- deadcode
# - deadcode // Fully deprecated, remove this line once an alternative is enabled for the same
- decorder
# - depguard
- dogsled
Expand All @@ -113,9 +114,8 @@ linters:
- errcheck
- errchkjson
# - errorlint
- execinquery
# - execinquery // Fully deprecated, remove this line once an alternative is enabled for the same
- exhaustive
- exportloopref
- forbidigo
- funlen
- gocognit
Expand All @@ -124,24 +124,24 @@ linters:
- gocyclo
- gofmt
- gofumpt
- golint
- gomnd
# - golint // Fully deprecated, remove this line once an alternative is enabled for the same
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- grouper
- ifshort
# - ifshort // Fully deprecated, remove this line once an alternative is enabled for the same
- importas
- ineffassign
- interfacebloat
- lll
- logrlint
- loggercheck
- maintidx
- makezero
- maligned
# - maligned // Fully deprecated, remove this line once an alternative is enabled for the same
- misspell
- mnd
# - nakedret
- nestif
- nilerr
Expand All @@ -155,9 +155,9 @@ linters:
- reassign
- revive
- rowserrcheck
- scopelint
# - scopelint // Fully deprecated, remove this line once an alternative is enabled for the same
- sqlclosecheck
- structcheck
# - structcheck // Fully deprecated, remove this line once an alternative is enabled for the same
- stylecheck
- tenv
- testpackage
Expand All @@ -168,7 +168,7 @@ linters:
- unparam
- unused
- usestdlibvars
- varcheck
# - varcheck // Fully deprecated, remove this line once an alternative is enabled for the same
- wastedassign
- whitespace
- wsl
Expand Down
4 changes: 3 additions & 1 deletion e2e/deployers/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
const (
AppLabelKey = "app"
ClusterSetName = "default"

fMode = 0o600
)

func CreateManagedClusterSetBinding(name, namespace string) error {
Expand Down Expand Up @@ -460,5 +462,5 @@ func CreateKustomizationFile(w workloads.Workload, dir string) error {
// Write the combined content to a new YAML file
outputFile := dir + "/kustomization.yaml"

return os.WriteFile(outputFile, combinedYAML, os.ModePerm)
return os.WriteFile(outputFile, combinedYAML, fMode)
}
1 change: 1 addition & 0 deletions e2e/dractions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func EnableProtection(w workloads.Workload, d deployers.Deployer) error {
if placement.Annotations == nil {
placement.Annotations = make(map[string]string)
}

placement.Annotations[OcmSchedulingDisable] = "true"

return updatePlacement(util.Ctx.Hub.CtrlClient, placement)
Expand Down
2 changes: 1 addition & 1 deletion hack/install-golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
script_dir="$(cd "$(dirname "$0")" && pwd)"

source_url="https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh"
required_version="1.55.2"
required_version="1.62.0"
target_dir="${script_dir}/../testbin"
target_path="${target_dir}/golangci-lint"
tool="golangci-lint"
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/cephfscg/volumegroupsourcehandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,15 @@ func CreateRS(rsName string) {
func UpdateRS(rsName string) {
retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
rs := &volsyncv1alpha1.ReplicationSource{}

err := k8sClient.Get(context.TODO(), types.NamespacedName{
Name: rsName,
Namespace: "default",
}, rs)
if err != nil {
return err
}

rs.Status = &volsyncv1alpha1.ReplicationSourceStatus{
LastManualSync: manualString,
}
Expand Down Expand Up @@ -249,13 +251,15 @@ func GenerateReplicationGroupSource(
func UpdateVGS(rgs *v1alpha1.ReplicationGroupSource, vsName, pvcName string) {
retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
volumeGroupSnapshot := &vgsv1alphfa1.VolumeGroupSnapshot{}

err := k8sClient.Get(context.TODO(), types.NamespacedName{
Name: fmt.Sprintf(cephfscg.VolumeGroupSnapshotNameFormat, rgs.Name),
Namespace: rgs.Namespace,
}, volumeGroupSnapshot)
if err != nil {
return err
}

ready := true
volumeGroupSnapshot.Status = &vgsv1alphfa1.VolumeGroupSnapshotStatus{
ReadyToUse: &ready,
Expand Down
7 changes: 6 additions & 1 deletion internal/controller/controllers_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ func drclusterConditionExpect(

matchElements := MatchElements(
func(element interface{}) string {
return element.(metav1.Condition).Type
cond, ok := element.(metav1.Condition)
if !ok {
return ""
}

return cond.Type
},
IgnoreExtras,
Elements{
Expand Down
16 changes: 13 additions & 3 deletions internal/controller/drcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,17 @@ func drpcPred() predicate.Funcs {
return false
},
UpdateFunc: func(e event.UpdateEvent) bool {
return DRPCUpdateOfInterest(e.ObjectOld.(*ramen.DRPlacementControl), e.ObjectNew.(*ramen.DRPlacementControl))
drpcOld, ok := e.ObjectOld.(*ramen.DRPlacementControl)
if !ok {
return false
}

drpcNew, ok := e.ObjectNew.(*ramen.DRPlacementControl)
if !ok {
return false
}

return DRPCUpdateOfInterest(drpcOld, drpcNew)
},
GenericFunc: func(e event.GenericEvent) bool {
return false
Expand Down Expand Up @@ -465,11 +475,11 @@ func (u *drclusterInstance) initializeStatus() {
func (u *drclusterInstance) getDRClusterDeployedStatus(drcluster *ramen.DRCluster) error {
mw, err := u.mwUtil.GetDrClusterManifestWork(drcluster.Name)
if err != nil {
return fmt.Errorf(fmt.Sprintf("error in fetching DRCluster ManifestWork %v", err))
return fmt.Errorf("error in fetching DRCluster ManifestWork %v", err)
}

if mw == nil {
return fmt.Errorf(fmt.Sprintf("missing DRCluster ManifestWork resource %v", err))
return fmt.Errorf("missing DRCluster ManifestWork resource %v", err)
}

deployed := util.IsManifestInAppliedState(mw)
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/drclusterconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (r *DRClusterConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
rateLimiter := workqueue.NewTypedMaxOfRateLimiter(
workqueue.NewTypedItemExponentialFailureRateLimiter[reconcile.Request](1*time.Second, maxReconcileBackoff),
// defaults from client-go
//nolint: gomnd
//nolint: mnd
&workqueue.TypedBucketRateLimiter[reconcile.Request]{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
)

Expand Down
3 changes: 2 additions & 1 deletion internal/controller/drplacementcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ func (d *DRPCInstance) RunFailover() (bool, error) {
const done = true

if d.instance.Spec.FailoverCluster == "" {
msg := "missing value for spec.FailoverCluster"
const msg = "missing value for spec.FailoverCluster"

addOrUpdateCondition(&d.instance.Status.Conditions, rmn.ConditionAvailable, d.instance.Generation,
d.getConditionStatusForTypeAvailable(), string(d.instance.Status.Phase), msg)

Expand Down
3 changes: 2 additions & 1 deletion internal/controller/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ func isBeingDeleted(drpc *rmn.DRPlacementControl, usrPl client.Object) bool {
(usrPl != nil && rmnutil.ResourceIsDeleted(usrPl))
}

//nolint:unparam
func (r *DRPlacementControlReconciler) reconcileDRPCInstance(d *DRPCInstance, log logr.Logger) (ctrl.Result, error) {
// Last status update time BEFORE we start processing
var beforeProcessing metav1.Time
Expand Down Expand Up @@ -1096,7 +1097,6 @@ func getVRGsFromManagedClusters(
vrgs := map[string]*rmn.VolumeReplicationGroup{}

annotations := make(map[string]string)

annotations[DRPCNameAnnotation] = drpc.Name
annotations[DRPCNamespaceAnnotation] = drpc.Namespace

Expand All @@ -1112,6 +1112,7 @@ func getVRGsFromManagedClusters(
// Only NotFound error is accepted
if errors.IsNotFound(err) {
log.Info(fmt.Sprintf("VRG not found on %q", drCluster.Name))

numClustersQueriedSuccessfully++

continue
Expand Down
24 changes: 22 additions & 2 deletions internal/controller/drplacementcontrol_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,17 @@ func DRClusterPredicateFunc() predicate.Funcs {
UpdateFunc: func(e event.UpdateEvent) bool {
log.Info("Update event")

return DRClusterUpdateOfInterest(e.ObjectOld.(*rmn.DRCluster), e.ObjectNew.(*rmn.DRCluster))
drcOld, ok := e.ObjectOld.(*rmn.DRCluster)
if !ok {
return false
}

drcNew, ok := e.ObjectNew.(*rmn.DRCluster)
if !ok {
return false
}

return DRClusterUpdateOfInterest(drcOld, drcNew)
},
}

Expand All @@ -245,7 +255,17 @@ func DRPolicyPredicateFunc() predicate.Funcs {
UpdateFunc: func(e event.UpdateEvent) bool {
log.Info("Update event")

return RequiresDRPCReconciliation(e.ObjectOld.(*rmn.DRPolicy), e.ObjectNew.(*rmn.DRPolicy))
drpOld, ok := e.ObjectOld.(*rmn.DRPolicy)
if !ok {
return false
}

drpNew, ok := e.ObjectNew.(*rmn.DRPolicy)
if !ok {
return false
}

return RequiresDRPCReconciliation(drpOld, drpNew)
nirs marked this conversation as resolved.
Show resolved Hide resolved
},
}

Expand Down
1 change: 1 addition & 0 deletions internal/controller/drpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (r *DRPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return r.reconcile(u, drclusters, secretsUtil, ramenConfig)
}

//nolint:unparam
func (r *DRPolicyReconciler) reconcile(
u *drpolicyUpdater,
drclusters *ramen.DRClusterList,
Expand Down
7 changes: 6 additions & 1 deletion internal/controller/drpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ var _ = Describe("DRPolicyController", func() {
)).To(Succeed())
g.Expect(drpolicy.Status.Conditions).To(MatchElements(
func(element interface{}) string {
return element.(metav1.Condition).Type
cond, ok := element.(metav1.Condition)
if !ok {
return ""
}

return cond.Type
},
IgnoreExtras,
Elements{
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/util/drpolicy_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func DRPolicyS3Profiles(drpolicy *rmn.DRPolicy, drclusters []rmn.DRCluster) sets
return mustHaveS3Profiles
}

//nolint:gomnd
//nolint:mnd
func GetSecondsFromSchedulingInterval(drpolicy *rmn.DRPolicy) (float64, error) {
schedulingInterval := drpolicy.Spec.SchedulingInterval
if schedulingInterval == "" {
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/util/json_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ func TestXYZ(t *testing.T) {

t.Run(strconv.Itoa(i), func(t *testing.T) {
var jsonData map[string]interface{}

err := json.Unmarshal(jsonText1, &jsonData)
if err != nil {
t.Error(err)
}

_, err = util.EvaluateCheckHookExp(test.jsonPathExprs, jsonData)
if (err == nil) != test.result {
t.Errorf("EvaluateCheckHookExp() = %v, want %v", err, test.result)
Expand Down
16 changes: 14 additions & 2 deletions internal/controller/util/pvcs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ func IndexFieldsForVSHandler(ctx context.Context, fieldIndexer client.FieldIndex
// Index on pods - used to be able to check if a pvc is mounted to a pod
err := fieldIndexer.IndexField(ctx, &corev1.Pod{}, PodVolumePVCClaimIndexName, func(o client.Object) []string {
var res []string
for _, vol := range o.(*corev1.Pod).Spec.Volumes {

pod, ok := o.(*corev1.Pod)
if !ok {
return res
}

for _, vol := range pod.Spec.Volumes {
if vol.PersistentVolumeClaim == nil {
continue
}
Expand All @@ -211,7 +217,13 @@ func IndexFieldsForVSHandler(ctx context.Context, fieldIndexer client.FieldIndex
return fieldIndexer.IndexField(ctx, &storagev1.VolumeAttachment{}, VolumeAttachmentToPVIndexName,
func(o client.Object) []string {
var res []string
sourcePVName := o.(*storagev1.VolumeAttachment).Spec.Source.PersistentVolumeName

va, ok := o.(*storagev1.VolumeAttachment)
if !ok {
return res
}

sourcePVName := va.Spec.Source.PersistentVolumeName
if sourcePVName != nil {
res = append(res, *sourcePVName)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/controller/volsync/vshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ func (v *VSHandler) createOrUpdateRS(rsSpec ramendrv1alpha1.VolSyncReplicationSo

return err
}

rs.Spec.Trigger = &volsyncv1alpha1.ReplicationSourceTriggerSpec{
Schedule: scheduleCronSpec,
}
Expand Down Expand Up @@ -1220,6 +1221,7 @@ func (v *VSHandler) ensurePVCFromSnapshot(rdSpec ramendrv1alpha1.VolSyncReplicat

return nil
}

if pvc.Status.Phase == corev1.ClaimBound {
// PVC already bound at this point
l.V(1).Info("PVC already bound")
Expand Down Expand Up @@ -1406,15 +1408,14 @@ func (v *VSHandler) ModifyRSSpecForCephFS(rsSpec *ramendrv1alpha1.VolSyncReplica
readOnlyPVCStorageClass.Provisioner = storageClass.Provisioner

// Copy other parameters from the original storage class
// Note - not copying volumebindingmode or reclaim policy from the source storageclass will leave defaults
readOnlyPVCStorageClass.Parameters = map[string]string{}
for k, v := range storageClass.Parameters {
readOnlyPVCStorageClass.Parameters[k] = v
}

// Set backingSnapshot parameter to true
readOnlyPVCStorageClass.Parameters["backingSnapshot"] = "true"

// Note - not copying volumebindingmode or reclaim policy from the source storageclass will leave defaults
}

return nil
Expand Down
Loading