Skip to content

Commit

Permalink
linter issues
Browse files Browse the repository at this point in the history
Signed-off-by: Benny Zlotnik <[email protected]>
  • Loading branch information
bennyz committed Feb 22, 2024
1 parent 9063c64 commit f46e6d2
Show file tree
Hide file tree
Showing 116 changed files with 483 additions and 515 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters:
- nilnil
- bodyclose
- gofmt
- goimports
linters-settings:
ginkgolinter:
forbid-focus-container: true
1 change: 1 addition & 0 deletions pkg/controller/hook/regexp.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:unused
package hook

import (
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/host/handler/vsphere/handler.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package vsphere

import (
"path"
"strings"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/vsphere"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"golang.org/x/net/context"
"path"
"sigs.k8s.io/controller-runtime/pkg/event"
"strings"
)

// Package logger.
Expand Down Expand Up @@ -79,6 +80,7 @@ func (r *Handler) changed(models ...*vsphere.Host) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list Host CRs")
return
}
for i := range list.Items {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/host/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
adapter "github.com/konveyor/forklift-controller/pkg/controller/plan/adapter/vsphere"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web"
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/map/network/handler/ocp/handler.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package ocp

import (
"path"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/ocp"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"golang.org/x/net/context"
"path"
"sigs.k8s.io/controller-runtime/pkg/event"
)

Expand Down Expand Up @@ -70,6 +71,7 @@ func (r *Handler) changed(network *ocp.NetworkAttachmentDefinition) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list NetworkMap CRs")
return
}
for i := range list.Items {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/map/network/handler/openstack/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (r *Handler) changed(models ...*openstack.Network) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list NetworkMap CRs")
return
}
for i := range list.Items {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/map/network/handler/ova/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (r *Handler) changed(models ...*ova.Network) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list NetworkMap CRs")
return
}
for i := range list.Items {
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/map/network/handler/ovirt/handler.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package ovirt

import (
"path"
"strings"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/ovirt"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"golang.org/x/net/context"
"path"
"sigs.k8s.io/controller-runtime/pkg/event"
"strings"
)

// Package logger.
Expand Down Expand Up @@ -79,6 +80,7 @@ func (r *Handler) changed(models ...*ovirt.Network) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list NetworkMap CRs")
return
}
for i := range list.Items {
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/map/network/handler/vsphere/handler.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package vsphere

import (
"path"
"strings"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/vsphere"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"golang.org/x/net/context"
"path"
"sigs.k8s.io/controller-runtime/pkg/event"
"strings"
)

// Package logger.
Expand Down Expand Up @@ -79,6 +80,7 @@ func (r *Handler) changed(models ...*vsphere.Network) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list NetworkMap CRs")
return
}
for i := range list.Items {
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/map/storage/handler/ocp/handler.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package ocp

import (
"path"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/ocp"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"golang.org/x/net/context"
"path"
"sigs.k8s.io/controller-runtime/pkg/event"
)

Expand Down Expand Up @@ -68,6 +69,7 @@ func (r *Handler) changed(storageClass *ocp.StorageClass) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list StorageMap CRs")
return
}
for i := range list.Items {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/map/storage/handler/openstack/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (r *Handler) changed(models ...*openstack.VolumeType) {
err := r.List(context.TODO(), storageMapList)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list StorageMap CRs")
return
}
for _, storageMap := range storageMapList.Items {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/map/storage/handler/ova/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (r *Handler) changed(models ...*ova.Disk) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list StorageMap CRs")
return
}
for i := range list.Items {
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/map/storage/handler/ovirt/handler.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package ovirt

import (
"path"
"strings"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/ovirt"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"golang.org/x/net/context"
"path"
"sigs.k8s.io/controller-runtime/pkg/event"
"strings"
)

// Package logger.
Expand Down Expand Up @@ -79,6 +80,7 @@ func (r *Handler) changed(models ...*ovirt.StorageDomain) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list StorageMap CRs")
return
}
for i := range list.Items {
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/map/storage/handler/vsphere/handler.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package vsphere

import (
"path"
"strings"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web/vsphere"
"github.com/konveyor/forklift-controller/pkg/controller/watch/handler"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
libweb "github.com/konveyor/forklift-controller/pkg/lib/inventory/web"
"github.com/konveyor/forklift-controller/pkg/lib/logging"
"golang.org/x/net/context"
"path"
"sigs.k8s.io/controller-runtime/pkg/event"
"strings"
)

// Package logger.
Expand Down Expand Up @@ -79,6 +80,7 @@ func (r *Handler) changed(models ...*vsphere.Datastore) {
err := r.List(context.TODO(), &list)
if err != nil {
err = liberr.Wrap(err)
log.Error(err, "failed to list StorageMap CRs")
return
}
for i := range list.Items {
Expand Down
6 changes: 1 addition & 5 deletions pkg/controller/migration/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ func (r PlanPredicate) Update(e event.UpdateEvent) bool {

func (r PlanPredicate) Delete(e event.DeleteEvent) bool {
_, cast := e.Object.(*api.Plan)
if cast {
return true
}

return false
return cast
}

func (r PlanPredicate) Generic(e event.GenericEvent) bool {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/migration/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package migration
import (
"context"
"errors"

api "github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1"
plancnt "github.com/konveyor/forklift-controller/pkg/controller/plan"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web"
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/plan/adapter/ocp/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const (

type Builder struct {
*plancontext.Context
macConflictsMap map[string]string
sourceClient client.Client
sourceClient client.Client
}

// ConfigMap implements base.Builder
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/plan/adapter/openstack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels",
"//vendor/k8s.io/apimachinery/pkg/types",
"//vendor/k8s.io/apimachinery/pkg/util/wait",
"//vendor/k8s.io/utils/pointer",
"//vendor/k8s.io/utils/ptr",
"//vendor/kubevirt.io/api/core/v1:core",
"//vendor/kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client",
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/plan/adapter/openstack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
cnv "kubevirt.io/api/core/v1"
cdi "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -539,7 +539,7 @@ func (r *Builder) mapDisks(vm *model.Workload, persistentVolumeClaims []*core.Pe
}
if bootable, err := strconv.ParseBool(volume.Bootable); err == nil && bootable {
r.Log.Info("bootable volume found", "volumeID", volumeID)
bootOrder = pointer.Uint(1)
bootOrder = ptr.To[uint](1)

Check warning on line 542 in pkg/controller/plan/adapter/openstack/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/openstack/builder.go#L542

Added line #L542 was not covered by tests
}
}

Expand Down Expand Up @@ -592,7 +592,7 @@ func (r *Builder) mapDisks(vm *model.Workload, persistentVolumeClaims []*core.Pe
r.Log.Info("No bootable volume found, falling back to image", "image", imagePVC.Name)
for i, disk := range kDisks {
if disk.Name == fmt.Sprintf("vol-%s", imagePVC.Annotations[AnnImportDiskId]) {
kDisks[i].BootOrder = pointer.Uint(1)
kDisks[i].BootOrder = ptr.To[uint](1)

Check warning on line 595 in pkg/controller/plan/adapter/openstack/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/openstack/builder.go#L595

Added line #L595 was not covered by tests
r.Log.Info("Boot order set to 1 on", "disk", kDisks[i], "ann", imagePVC.Annotations[AnnImportDiskId])
break
}
Expand Down Expand Up @@ -1236,6 +1236,7 @@ func (r *Builder) PopulatorTransferredBytes(persistentVolumeClaim *core.Persiste
if err != nil {
transferredBytes = 0
err = nil
//nolint:nilerr

Check warning on line 1239 in pkg/controller/plan/adapter/openstack/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/openstack/builder.go#L1239

Added line #L1239 was not covered by tests
return
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/plan/adapter/openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,9 @@ func (r *Client) getImageFromVolume(vm *libclient.VM, volumeID string) (image *l
volume, err := r.getVolume(volumeRef)
if err != nil {
err = liberr.Wrap(err)
return

Check warning on line 585 in pkg/controller/plan/adapter/openstack/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/openstack/client.go#L585

Added line #L585 was not covered by tests
}

originalVolumeID := volume.Metadata[forkliftPropertyOriginalVolumeID]
imageName := getImageFromVolumeName(r.Context, vm.ID, originalVolumeID)
images := []libclient.Image{}
Expand Down
3 changes: 0 additions & 3 deletions pkg/controller/plan/adapter/openstack/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const (
forkliftPropertyOriginalImageID = "forklift_original_image_id"
)

func getMigrationName(ctx *plancontext.Context) string {
return ctx.Migration.GetName()
}
func getMigrationID(ctx *plancontext.Context) string {
return string(ctx.Migration.GetUID())
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/plan/adapter/ova/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const (

// Regex which matches the snapshot identifier suffix of a
// OVA disk backing file.
var backingFilePattern = regexp.MustCompile("-\\d\\d\\d\\d\\d\\d.vmdk")
var backingFilePattern = regexp.MustCompile(`-\d\d\d\d\d\d.vmdk`)

// OVA builder.
type Builder struct {
Expand Down Expand Up @@ -161,8 +161,7 @@ func (r *Builder) DataVolumes(vmRef ref.Ref, secret *core.Secret, _ *core.Config
return nil, err
}
storageClass := mapped.Destination.StorageClass
var dvSource cdi.DataVolumeSource
dvSource = cdi.DataVolumeSource{
dvSource := cdi.DataVolumeSource{

Check warning on line 164 in pkg/controller/plan/adapter/ova/builder.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/adapter/ova/builder.go#L164

Added line #L164 was not covered by tests
Blank: &cdi.DataVolumeBlankImage{},
}
dvSpec := cdi.DataVolumeSpec{
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/plan/adapter/ova/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func (r *Client) DetachDisks(vmRef ref.Ref) (err error) {
}

func (r Client) Finalize(vms []*planapi.VMStatus, planName string) {
return
}

func (r *Client) PreTransferActions(vmRef ref.Ref) (ready bool, err error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/plan/adapter/ova/ova_capacity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetResourceCapacity(t *testing.T) {
if testCase.expectError {
g.Expect(err).To(gomega.HaveOccurred(), fmt.Sprintf("expected an error for input: %v", testCase.units))
} else {
g.Expect(err).To(gomega.BeNil(), fmt.Sprintf("did not expect an error for input: %v, but got: %v", testCase.units, err))
g.Expect(err).ToNot(gomega.HaveOccurred(), fmt.Sprintf("did not expect an error for input: %v, but got: %v", testCase.units, err))
g.Expect(result).To(gomega.Equal(testCase.expected), fmt.Sprintf("expected %v, but got %v", testCase.expected, result))
}
})
Expand Down
Loading

0 comments on commit f46e6d2

Please sign in to comment.