From 9ec20f3e38aadae7f640a552dc744f4cfdbfc453 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Tue, 7 Nov 2023 12:15:08 +0100 Subject: [PATCH] chore(pkg/driver): disable `hugeParam` lint. Signed-off-by: Federico Di Pierro --- pkg/driver/distro/amzn.go | 1 + pkg/driver/distro/bottlerocket.go | 2 ++ pkg/driver/distro/debian.go | 1 + pkg/driver/distro/distro.go | 24 ++++++++++++++---------- pkg/driver/distro/flatcar.go | 2 ++ pkg/driver/distro/generic.go | 3 +++ pkg/driver/distro/minikube.go | 1 + pkg/driver/distro/talos.go | 2 ++ pkg/driver/distro/ubuntu.go | 2 ++ 9 files changed, 28 insertions(+), 10 deletions(-) diff --git a/pkg/driver/distro/amzn.go b/pkg/driver/distro/amzn.go index ae9e7b845..4f3a487d6 100644 --- a/pkg/driver/distro/amzn.go +++ b/pkg/driver/distro/amzn.go @@ -30,6 +30,7 @@ type amzn struct { *generic } +//nolint:gocritic // the method shall not be able to modify kr func (a *amzn) init(kr kernelrelease.KernelRelease, _ string, cfg *ini.File) error { idKey := cfg.Section("").Key("VERSION_ID") if idKey == nil { diff --git a/pkg/driver/distro/bottlerocket.go b/pkg/driver/distro/bottlerocket.go index 03938f8c3..0abb09984 100644 --- a/pkg/driver/distro/bottlerocket.go +++ b/pkg/driver/distro/bottlerocket.go @@ -33,6 +33,7 @@ type bottlerocket struct { versionID string } +//nolint:gocritic // the method shall not be able to modify kr func (b *bottlerocket) init(kr kernelrelease.KernelRelease, id string, cfg *ini.File) error { idKey := cfg.Section("").Key("VERSION_ID") if idKey == nil { @@ -50,6 +51,7 @@ func (b *bottlerocket) init(kr kernelrelease.KernelRelease, id string, cfg *ini. return b.generic.init(kr, id, cfg) } +//nolint:gocritic // the method shall not be able to modify kr func (b *bottlerocket) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease { kr.KernelVersion = fmt.Sprintf("1_%s-%s", b.versionID, b.variantID) return kr diff --git a/pkg/driver/distro/debian.go b/pkg/driver/distro/debian.go index bd8df3b07..be35df75e 100644 --- a/pkg/driver/distro/debian.go +++ b/pkg/driver/distro/debian.go @@ -45,6 +45,7 @@ func (d *debian) check(hostRoot string) bool { return false } +//nolint:gocritic // the method shall not be able to modify kr func (d *debian) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease { // Workaround: debian kernelreleases might not be actual kernel running; // instead, they might be the Debian kernel package diff --git a/pkg/driver/distro/distro.go b/pkg/driver/distro/distro.go index dc98b343c..ca71674f9 100644 --- a/pkg/driver/distro/distro.go +++ b/pkg/driver/distro/distro.go @@ -56,8 +56,10 @@ type checker interface { // DiscoverDistro tries to fetch the correct Distro by looking at /etc/os-release or // by cycling on all supported distros and checking them one by one. +// +//nolint:gocritic // the method shall not be able to modify kr func DiscoverDistro(kr kernelrelease.KernelRelease, hostRoot string) (Distro, error) { - distro, err := getOSReleaseDistro(kr, hostRoot) + distro, err := getOSReleaseDistro(&kr, hostRoot) if err == nil { return distro, nil } @@ -79,7 +81,7 @@ func DiscoverDistro(kr kernelrelease.KernelRelease, hostRoot string) (Distro, er return distro, ErrUnsupported } -func getOSReleaseDistro(kr kernelrelease.KernelRelease, hostRoot string) (Distro, error) { +func getOSReleaseDistro(kr *kernelrelease.KernelRelease, hostRoot string) (Distro, error) { cfg, err := ini.Load(hostRoot + "/etc/os-release") if err != nil { return nil, err @@ -102,23 +104,23 @@ func getOSReleaseDistro(kr kernelrelease.KernelRelease, hostRoot string) (Distro if !exist { distro = &generic{} } - if err = distro.init(kr, id, cfg); err != nil { + if err = distro.init(*kr, id, cfg); err != nil { return nil, err } return distro, nil } -func toURL(repo, driverVer, fileName string, kr kernelrelease.KernelRelease) string { +func toURL(repo, driverVer, fileName string, kr *kernelrelease.KernelRelease) string { return fmt.Sprintf("%s/%s/%s/%s", repo, driverVer, kr.Architecture.ToNonDeb(), fileName) } -func toLocalPath(driverVer, fileName string, kr kernelrelease.KernelRelease) string { +func toLocalPath(driverVer, fileName string, kr *kernelrelease.KernelRelease) string { return fmt.Sprintf("%s/.falco/%s/%s/%s", homedir.Get(), driverVer, kr.Architecture.ToNonDeb(), fileName) } -func driverToFilename(d Distro, kr kernelrelease.KernelRelease, driverName string, driverType drivertype.DriverType) string { +func driverToFilename(d Distro, kr *kernelrelease.KernelRelease, driverName string, driverType drivertype.DriverType) string { // Fixup kernel information before attempting to download - fixedKR := d.fixupKernel(kr) + fixedKR := d.fixupKernel(*kr) return fmt.Sprintf("%s_%s_%s_%s%s", driverName, d, fixedKR.String(), fixedKR.KernelVersion, driverType.Extension()) } @@ -132,6 +134,8 @@ func Build(_ Distro, _ *output.Printer) (string, error) { } // Download will try to download drivers for a distro trying specified repos. +// +//nolint:gocritic // the method shall not be able to modify kr func Download(d Distro, printer *output.Printer, kr kernelrelease.KernelRelease, @@ -139,9 +143,9 @@ func Download(d Distro, driverType drivertype.DriverType, driverVer string, repos []string, ) (string, error) { - driverFileName := driverToFilename(d, kr, driverName, driverType) + driverFileName := driverToFilename(d, &kr, driverName, driverType) // Skip if existent - destination := toLocalPath(driverVer, driverFileName, kr) + destination := toLocalPath(driverVer, driverFileName, &kr) f, err := os.Open(destination) //nolint:gosec // false positive if err == nil { _ = f.Close() @@ -152,7 +156,7 @@ func Download(d Distro, // Try to download from any specified repository, // stopping at first successful http GET. for _, repo := range repos { - url := toURL(repo, driverVer, driverFileName, kr) + url := toURL(repo, driverVer, driverFileName, &kr) printer.Logger.Info("Trying to download a driver", printer.Logger.Args("url", url)) resp, err := http.Get(url) //nolint:gosec,noctx // false positive diff --git a/pkg/driver/distro/flatcar.go b/pkg/driver/distro/flatcar.go index 3ed1cdefb..446a97c4b 100644 --- a/pkg/driver/distro/flatcar.go +++ b/pkg/driver/distro/flatcar.go @@ -32,6 +32,7 @@ type flatcar struct { versionID string } +//nolint:gocritic // the method shall not be able to modify kr func (f *flatcar) init(kr kernelrelease.KernelRelease, id string, cfg *ini.File) error { idKey := cfg.Section("").Key("VERSION_ID") if idKey == nil { @@ -42,6 +43,7 @@ func (f *flatcar) init(kr kernelrelease.KernelRelease, id string, cfg *ini.File) return f.generic.init(kr, id, cfg) } +//nolint:gocritic // the method shall not be able to modify kr func (f *flatcar) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease { kr.Version = semver.MustParse(f.versionID) return kr diff --git a/pkg/driver/distro/generic.go b/pkg/driver/distro/generic.go index 24d5459d8..2c516692f 100644 --- a/pkg/driver/distro/generic.go +++ b/pkg/driver/distro/generic.go @@ -27,6 +27,7 @@ type generic struct { targetID string } +//nolint:gocritic // the method shall not be able to modify kr func (g *generic) init(_ kernelrelease.KernelRelease, id string, _ *ini.File) error { g.targetID = id return nil @@ -36,10 +37,12 @@ func (g *generic) String() string { return g.targetID } +//nolint:gocritic // the method shall not be able to modify kr func (g *generic) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease { return kr } +//nolint:gocritic // the method shall not be able to modify kr func (g *generic) PreferredDriver(kr kernelrelease.KernelRelease) drivertype.DriverType { // Deadly simple default automatic selection var dType drivertype.DriverType diff --git a/pkg/driver/distro/minikube.go b/pkg/driver/distro/minikube.go index f6605f651..d3c40766c 100644 --- a/pkg/driver/distro/minikube.go +++ b/pkg/driver/distro/minikube.go @@ -63,6 +63,7 @@ func (m *minikube) check(hostRoot string) bool { return false } +//nolint:gocritic // the method shall not be able to modify kr func (m *minikube) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease { kr.KernelVersion = fmt.Sprintf("1_%s", m.version) return kr diff --git a/pkg/driver/distro/talos.go b/pkg/driver/distro/talos.go index 72f542e38..1ad6b6926 100644 --- a/pkg/driver/distro/talos.go +++ b/pkg/driver/distro/talos.go @@ -31,6 +31,7 @@ type talos struct { versionID string } +//nolint:gocritic // the method shall not be able to modify kr func (t *talos) init(kr kernelrelease.KernelRelease, id string, cfg *ini.File) error { idKey := cfg.Section("").Key("VERSION_ID") if idKey == nil { @@ -42,6 +43,7 @@ func (t *talos) init(kr kernelrelease.KernelRelease, id string, cfg *ini.File) e return t.generic.init(kr, id, cfg) } +//nolint:gocritic // the method shall not be able to modify kr func (t *talos) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease { kr.KernelVersion = fmt.Sprintf("1_%s", t.versionID) return kr diff --git a/pkg/driver/distro/ubuntu.go b/pkg/driver/distro/ubuntu.go index 06580011b..0d52da0c3 100644 --- a/pkg/driver/distro/ubuntu.go +++ b/pkg/driver/distro/ubuntu.go @@ -33,6 +33,7 @@ type ubuntu struct { var ubuntuTargetIDRegex = regexp.MustCompile(`-([a-zA-Z]+)(-.*)?$`) +//nolint:gocritic // the method shall not be able to modify kr func (u *ubuntu) init(kr kernelrelease.KernelRelease, _ string, f *ini.File) error { // # Extract the flavor from the kernelrelease // # Examples: @@ -45,6 +46,7 @@ func (u *ubuntu) init(kr kernelrelease.KernelRelease, _ string, f *ini.File) err return u.generic.init(kr, "ubuntu-"+flavor, f) } +//nolint:gocritic // the method shall not be able to modify kr func (u *ubuntu) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease { // In the case that the kernelversion isn't just a number // we keep also the remaining part excluding `-Ubuntu`.