From 51aa6c25fb7c27225ae8a4cc246db40e54193ac9 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Fri, 3 Nov 2023 17:22:35 +0100 Subject: [PATCH] chore(internal,pkg): fixup some linting issues. Signed-off-by: Federico Di Pierro --- internal/config/config.go | 1 + pkg/driver/distro/amzn.go | 14 +++++++------- pkg/driver/distro/distro.go | 5 +++++ pkg/driver/kernel/kernel.go | 1 + pkg/driver/type/type.go | 2 ++ 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 3d05ea4b..fa0238d0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -526,6 +526,7 @@ func Driverer() (Driver, error) { }, nil } +// SelectDriver stores a driver as selected in config file. func SelectDriver(driverType, configFile string) error { if err := UpdateConfigFile(DriverSelectedKey, driverType, configFile); err != nil { return fmt.Errorf("unable to update selected driver in the config file %q: %w", configFile, err) diff --git a/pkg/driver/distro/amzn.go b/pkg/driver/distro/amzn.go index 2bc29e68..2a84929e 100644 --- a/pkg/driver/distro/amzn.go +++ b/pkg/driver/distro/amzn.go @@ -14,23 +14,23 @@ type amzn struct { *generic } -func (a *amzn) init(printer *output.Printer, id string, cfg *ini.File) error { +func (a *amzn) init(printer *output.Printer, _ string, cfg *ini.File) error { idKey := cfg.Section("").Key("VERSION_ID") if idKey == nil { // OS-release without `VERSION_ID` (can it happen?) return fmt.Errorf("no VERSION_ID present for amzn") } // overwrite id - newId := "" + newID := "" switch idKey.String() { case "2": - newId = "amazonlinux2" + newID = "amazonlinux2" case "2022": - newId = "amazonlinux2022" + newID = "amazonlinux2022" case "2023": - newId = "amazonlinux2023" + newID = "amazonlinux2023" default: - newId = "amazonlinux" + newID = "amazonlinux" } - return a.generic.init(printer, newId, cfg) + return a.generic.init(printer, newID, cfg) } diff --git a/pkg/driver/distro/distro.go b/pkg/driver/distro/distro.go index 55d37039..9efa8511 100644 --- a/pkg/driver/distro/distro.go +++ b/pkg/driver/distro/distro.go @@ -12,8 +12,11 @@ import ( var distros = map[string]Distro{} +// ErrUnsupported is the error returned when the target distro is not supported. var ErrUnsupported = fmt.Errorf("failed to determine distro") +// Distro is the common interface used by distro-specific implementations. +// Most of the distro-specific only partially override the default `generic` implementation. type Distro interface { init(printer *output.Printer, id string, cfg *ini.File) error // private GetTargetID(i driverkernel.Info) string @@ -27,6 +30,8 @@ type checker interface { check(hostRoot string) bool // private } +// 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. func DiscoverDistro(printer *output.Printer, hostRoot string) (Distro, error) { distro, err := getOSReleaseDistro(printer, hostRoot) if err == nil { diff --git a/pkg/driver/kernel/kernel.go b/pkg/driver/kernel/kernel.go index ca3a43e2..5776decc 100644 --- a/pkg/driver/kernel/kernel.go +++ b/pkg/driver/kernel/kernel.go @@ -6,6 +6,7 @@ import ( "strings" ) +// Info is the struct that holds all the kernel related information that are needed. type Info struct { Architecture string KernelRelease string diff --git a/pkg/driver/type/type.go b/pkg/driver/type/type.go index 2d142694..f63cc072 100644 --- a/pkg/driver/type/type.go +++ b/pkg/driver/type/type.go @@ -4,6 +4,7 @@ import "fmt" var driverTypes = map[string]DriverType{} +// DriverType is the interface that wraps driver types. type DriverType interface { String() string Prepare() error @@ -11,6 +12,7 @@ type DriverType interface { HasArtifacts() bool } +// Parse parses a driver type string and returns the corresponding DriverType object or an error. func Parse(driverType string) (DriverType, error) { if dType, ok := driverTypes[driverType]; ok { return dType, nil