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): fixup kernel headers download #499

Merged
merged 2 commits into from
Apr 3, 2024
Merged
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
21 changes: 19 additions & 2 deletions pkg/driver/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package driverdistro

import (
"bufio"
"bytes"
"compress/gzip"
"errors"
"fmt"
Expand Down Expand Up @@ -140,8 +142,18 @@ func loadKernelHeadersFromDk(distro string, kr kernelrelease.KernelRelease) (str
if err != nil {
return "", nil, err
}
script += "\necho $KERNELDIR"
out, err := exec.Command("bash", "-c", script).Output() //nolint:gosec // false positive
path := strings.TrimSuffix(string(out), "\n")
var path string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if err == nil {
// Scan all stdout line by line and
// store last line as KERNELDIR path.
reader := bytes.NewReader(out)
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
path = scanner.Text()
}
}
return path, func() {
_ = os.RemoveAll("/tmp/kernel-download")
_ = os.RemoveAll(path)
Expand Down Expand Up @@ -208,7 +220,12 @@ func Build(ctx context.Context,
// try to load kernel headers urls from driverkit.
if _, found := env[drivertype.KernelDirEnv]; !found {
printer.Logger.Debug("Trying to automatically fetch kernel headers.")
kernelHeadersPath, cleaner, err := loadKernelHeadersFromDk(d.String(), kr)
// KernelVersion needs to be fixed up; it is only used by driverkit Ubuntu builder
Copy link
Contributor Author

Choose a reason for hiding this comment

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

// and we must ensure that it is correctly set.
fixedKr := d.FixupKernel(kr)
kVerFixedKr := kr
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't overwrite kr here, instead use a copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While this is a bit ugly rn, it will be much better once #356 lands.

kVerFixedKr.KernelVersion = fixedKr.KernelVersion
kernelHeadersPath, cleaner, err := loadKernelHeadersFromDk(d.String(), kVerFixedKr)
if cleaner != nil {
defer cleaner()
}
Expand Down
Loading