Skip to content

Commit

Permalink
chore(pkg/driver): disable hugeParam lint.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 7, 2023
1 parent 1d0e7f5 commit 9ec20f3
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/driver/distro/amzn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/distro/bottlerocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/distro/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions pkg/driver/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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())
}

Expand All @@ -132,16 +134,18 @@ 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,
driverName string,
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()
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/distro/flatcar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/driver/distro/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/distro/minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/distro/talos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/distro/ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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`.
Expand Down

0 comments on commit 9ec20f3

Please sign in to comment.