Skip to content

Commit

Permalink
chore(cmd/driver,pkg/driver): printenv should print fixed up kernelre…
Browse files Browse the repository at this point in the history
…lease info.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Nov 9, 2023
1 parent aa26925 commit 79000a9
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 13 deletions.
8 changes: 5 additions & 3 deletions cmd/driver/printenv/printenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ func (o *driverPrintenvOptions) RunDriverPrintenv(_ context.Context) error {
if err != nil {
return err
}
fmt.Printf("ARCH=%s\n", kr.Architecture.ToNonDeb())
fmt.Printf("KERNEL_RELEASE=%s\n", kr.String())
fmt.Printf("KERNEL_VERSION=%s\n", kr.KernelVersion)

d, err := driverdistro.DiscoverDistro(kr, driver.HostRoot)
if err != nil {
return err
}
fmt.Printf("TARGET_ID=%s\n", d.String())

fixedKr := d.FixupKernel(kr)
fmt.Printf("ARCH=%s\n", fixedKr.Architecture.ToNonDeb())
fmt.Printf("KERNEL_RELEASE=%s\n", fixedKr.String())
fmt.Printf("KERNEL_VERSION=%s\n", fixedKr.KernelVersion)

return nil
}
2 changes: 1 addition & 1 deletion pkg/driver/distro/bottlerocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (b *bottlerocket) init(kr kernelrelease.KernelRelease, id string, cfg *ini.
}

//nolint:gocritic // the method shall not be able to modify kr
func (b *bottlerocket) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
func (b *bottlerocket) FixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
kr.KernelVersion = fmt.Sprintf("1_%s-%s", b.versionID, b.variantID)
return kr
}
2 changes: 1 addition & 1 deletion pkg/driver/distro/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (d *debian) check(hostRoot string) bool {
}

//nolint:gocritic // the method shall not be able to modify kr
func (d *debian) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
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
// providing the compatible kernel ABI
Expand Down
6 changes: 3 additions & 3 deletions pkg/driver/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var ErrUnsupported = fmt.Errorf("failed to determine distro")
// Most of the distro-specific only partially override the default `generic` implementation.
type Distro interface {
init(kr kernelrelease.KernelRelease, id string, cfg *ini.File) error // private
fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease // private
FixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease // private
customizeBuild(printer *output.Printer, driverType drivertype.DriverType, kr kernelrelease.KernelRelease, hostRoot string) (map[string]string, error)
PreferredDriver(kr kernelrelease.KernelRelease) drivertype.DriverType
fmt.Stringer
Expand Down Expand Up @@ -126,7 +126,7 @@ func toLocalPath(driverVer, fileName, arch string) string {

func toFilename(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 Down Expand Up @@ -158,7 +158,7 @@ func Build(d Distro,
if err != nil {
return "", err
}
path, err := driverType.Build(printer, d.fixupKernel(kr), driverName, driverVer, env)
path, err := driverType.Build(printer, d.FixupKernel(kr), driverName, driverVer, env)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/distro/flatcar.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (f *flatcar) init(kr kernelrelease.KernelRelease, id string, cfg *ini.File)
}

//nolint:gocritic // the method shall not be able to modify kr
func (f *flatcar) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
func (f *flatcar) FixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
kr.Version = semver.MustParse(f.versionID)
return kr
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/distro/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (g *generic) String() string {
}

//nolint:gocritic // the method shall not be able to modify kr
func (g *generic) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
func (g *generic) FixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
return kr
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/distro/minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m *minikube) check(hostRoot string) bool {
}

//nolint:gocritic // the method shall not be able to modify kr
func (m *minikube) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
func (m *minikube) FixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
kr.KernelVersion = fmt.Sprintf("1_%s", m.version)
return kr
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/distro/talos.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (t *talos) init(kr kernelrelease.KernelRelease, id string, cfg *ini.File) e
}

//nolint:gocritic // the method shall not be able to modify kr
func (t *talos) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
func (t *talos) FixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
kr.KernelVersion = fmt.Sprintf("1_%s", t.versionID)
return kr
}
2 changes: 1 addition & 1 deletion pkg/driver/distro/ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (u *ubuntu) init(kr kernelrelease.KernelRelease, _ string, f *ini.File) err
}

//nolint:gocritic // the method shall not be able to modify kr
func (u *ubuntu) fixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
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`.
// E.g.:
Expand Down

0 comments on commit 79000a9

Please sign in to comment.