Skip to content

Commit

Permalink
support Amazon Linux when fetching headers
Browse files Browse the repository at this point in the history
* check /boot on host for kernel config in addition to /proc/config.gz
* improve kernel version splitting when downloading kernel sources
* use elfutils-dev instead of libelf-dev to support preparing headers
  with kernel version used by Amazon Linux

RPMs for kernel source/headers are available, somehow, but it seems
older versions are not kept around or are hard to track down.
  • Loading branch information
danp authored and fntlnz committed Apr 2, 2020
1 parent 2e97e64 commit 12bac8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build/Dockerfile.initcontainer
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk add --update \
bc \
build-base \
curl \
libelf-dev \
elfutils-dev \
linux-headers \
make

Expand Down
11 changes: 9 additions & 2 deletions build/init/fetch-linux-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ generate_headers()
echo "Generating kernel headers"

cd "${BUILD_DIR}"
zcat /proc/config.gz > .config
if [ -e /proc/config.gz ]; then
zcat /proc/config.gz > .config
elif [ -e "/boot.host/config-${KERNEL_VERSION}" ]; then
cp "/boot.host/config-${KERNEL_VERSION}" .config
fi
make ARCH=x86 oldconfig > /dev/null
make ARCH=x86 prepare > /dev/null

Expand All @@ -32,7 +36,10 @@ fetch_cos_linux_sources()

fetch_generic_linux_sources()
{
kernel_version="$(echo "${KERNEL_VERSION}" | awk -vFS=+ '{ print $1 }')"
# 4.19.76-linuxkit -> 4.19.76
# 4.14.154-128.181.amzn2.x86_64 -> 4.14.154
# 4.19.76+gcp-something -> 4.19.76
kernel_version="$(echo "${KERNEL_VERSION}" | awk -vFS='[-+]' '{ print $1 }')"
major_version="$(echo "${KERNEL_VERSION}" | awk -vFS=. '{ print $1 }')"

echo "Fetching upstream kernel sources for ${kernel_version}."
Expand Down
14 changes: 13 additions & 1 deletion pkg/tracejob/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
}

if nj.FetchHeaders {
// If we aren't downloading headers, add the initContainer and set up mounts
// If we are downloading headers, add the initContainer and set up mounts
job.Spec.Template.Spec.InitContainers = []apiv1.Container{
apiv1.Container{
Name: "kubectl-trace-init",
Expand Down Expand Up @@ -388,6 +388,10 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
Name: "linux-headers-generated",
MountPath: "/usr/src/",
},
apiv1.VolumeMount{
Name: "boot-host",
MountPath: "/boot.host",
},
},
},
}
Expand Down Expand Up @@ -424,6 +428,14 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
Path: "/var/cache/linux-headers/generated",
},
},
},
apiv1.Volume{
Name: "boot-host",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/boot",
},
},
})

job.Spec.Template.Spec.Containers[0].VolumeMounts = append(job.Spec.Template.Spec.Containers[0].VolumeMounts,
Expand Down

0 comments on commit 12bac8f

Please sign in to comment.