Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pkg/driver): do not call FixupKernel when building drivers. #373

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cmd/driver/printenv/printenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ func (o *driverPrintenvOptions) RunDriverPrintenv(_ context.Context) error {
}
o.Printer.DefaultText.Printf("TARGET_ID=%q\n", d.String())

o.Printer.DefaultText.Printf("ARCH=%q\n", kr.Architecture.ToNonDeb())
o.Printer.DefaultText.Printf("KERNEL_RELEASE=%q\n", kr.String())
o.Printer.DefaultText.Printf("KERNEL_VERSION=%q\n", kr.KernelVersion)

fixedKr := d.FixupKernel(kr)
o.Printer.DefaultText.Printf("ARCH=%q\n", fixedKr.Architecture.ToNonDeb())
o.Printer.DefaultText.Printf("KERNEL_RELEASE=%q\n", fixedKr.String())
o.Printer.DefaultText.Printf("KERNEL_VERSION=%q\n", fixedKr.KernelVersion)
o.Printer.DefaultText.Printf("FIXED_KERNEL_RELEASE=%q\n", fixedKr.String())
o.Printer.DefaultText.Printf("FIXED_KERNEL_VERSION=%q\n", fixedKr.KernelVersion)

return nil
}
2 changes: 1 addition & 1 deletion pkg/driver/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func Build(ctx context.Context,
if err != nil {
return "", err
}
path, err := driverType.Build(ctx, printer, d.FixupKernel(kr), driverName, driverVer, env)
path, err := driverType.Build(ctx, printer, kr, driverName, driverVer, env)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing up the kenrel is only useful when downloading.

if err != nil {
return "", err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/driver/distro/flatcar.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (f *flatcar) init(kr kernelrelease.KernelRelease, id string, cfg *ini.File)
func (f *flatcar) FixupKernel(kr kernelrelease.KernelRelease) kernelrelease.KernelRelease {
kr.Version = semver.MustParse(f.versionID)
kr.Fullversion = kr.Version.String()
return kr
kr.FullExtraversion = ""
return f.generic.FixupKernel(kr)
}

//nolint:gocritic // the method shall not be able to modify kr
Expand All @@ -93,6 +94,9 @@ func (f *flatcar) customizeBuild(ctx context.Context,
return nil, nil
}
printer.Logger.Info("Flatcar detected; relocating kernel tools.", printer.Logger.Args("version", f.versionID))
_, err := exec.CommandContext(ctx, "/bin/bash", "-c", flatcarRelocateScript).Output()
out, err := exec.CommandContext(ctx, "/bin/bash", "-c", flatcarRelocateScript).Output()
if err != nil {
printer.DefaultText.Print(string(out))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print the error in case this step fails.

}
return nil, err
}
31 changes: 31 additions & 0 deletions pkg/driver/distro/flatcar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,34 @@ func TestDistroFlatcarInitFixup(t *testing.T) {
}
}
}

func TestDistroFlatcarFixup(t *testing.T) {
type testCase struct {
krInput string
kvInput string
krExpected string
kvExpected string
}
testCases := []testCase{
{
krInput: "6.1.62-flatcar",
kvInput: "#1 SMP PREEMPT_DYNAMIC Mon Nov 20 22:57:52 -00 2023",
krExpected: "3794.0.0",
kvExpected: "1",
},
{
krInput: "6.1.62-flatcar",
kvInput: "#27 SMP PREEMPT_DYNAMIC Mon Nov 20 22:57:52 -00 2023",
krExpected: "3794.0.0",
kvExpected: "27",
},
}
for _, tCase := range testCases {
flat := &flatcar{generic: &generic{}, versionID: "3794.0.0"}
kr := kernelrelease.FromString(tCase.krInput)
kr.KernelVersion = tCase.kvInput
fixedKr := flat.FixupKernel(kr)
assert.Equal(t, tCase.krExpected, fixedKr.String())
assert.Equal(t, tCase.kvExpected, fixedKr.KernelVersion)
}
}