Skip to content

Commit 64b7616

Browse files
committed
Make downloading headers conditional
1 parent 54900f5 commit 64b7616

File tree

2 files changed

+105
-116
lines changed

2 files changed

+105
-116
lines changed

pkg/tracejob/job.go

+105-89
Original file line numberDiff line numberDiff line change
@@ -253,79 +253,6 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
253253
},
254254
},
255255
},
256-
apiv1.Volume{
257-
Name: "lsb-release",
258-
VolumeSource: apiv1.VolumeSource{
259-
HostPath: &apiv1.HostPathVolumeSource{
260-
Path: "/etc/lsb-release",
261-
},
262-
},
263-
},
264-
apiv1.Volume{
265-
Name: "os-release",
266-
VolumeSource: apiv1.VolumeSource{
267-
HostPath: &apiv1.HostPathVolumeSource{
268-
Path: "/etc/os-release",
269-
},
270-
},
271-
},
272-
apiv1.Volume{
273-
Name: "modules-dir",
274-
VolumeSource: apiv1.VolumeSource{
275-
HostPath: &apiv1.HostPathVolumeSource{
276-
Path: "/var/cache/linux-headers/modules_dir",
277-
},
278-
},
279-
},
280-
apiv1.Volume{
281-
Name: "linux-headers-generated",
282-
VolumeSource: apiv1.VolumeSource{
283-
HostPath: &apiv1.HostPathVolumeSource{
284-
Path: "/var/cache/linux-headers/generated",
285-
},
286-
},
287-
},
288-
},
289-
InitContainers: []apiv1.Container{
290-
apiv1.Container{
291-
Name: "kubectl-trace-init",
292-
Image: version.InitImageNameTag(),
293-
Resources: apiv1.ResourceRequirements{
294-
Requests: apiv1.ResourceList{
295-
apiv1.ResourceCPU: resource.MustParse("100m"),
296-
apiv1.ResourceMemory: resource.MustParse("100Mi"),
297-
},
298-
Limits: apiv1.ResourceList{
299-
apiv1.ResourceCPU: resource.MustParse("1"),
300-
apiv1.ResourceMemory: resource.MustParse("1G"),
301-
},
302-
},
303-
VolumeMounts: []apiv1.VolumeMount{
304-
apiv1.VolumeMount{
305-
Name: "lsb-release",
306-
MountPath: "/etc/lsb-release.host",
307-
ReadOnly: true,
308-
},
309-
apiv1.VolumeMount{
310-
Name: "os-release",
311-
MountPath: "/etc/os-release.host",
312-
ReadOnly: true,
313-
},
314-
apiv1.VolumeMount{
315-
Name: "modules-dir",
316-
MountPath: "/lib/modules",
317-
},
318-
apiv1.VolumeMount{
319-
Name: "modules-host",
320-
MountPath: "/lib/modules.host",
321-
ReadOnly: true,
322-
},
323-
apiv1.VolumeMount{
324-
Name: "linux-headers-generated",
325-
MountPath: "/usr/src/",
326-
},
327-
},
328-
},
329256
},
330257
Containers: []apiv1.Container{
331258
apiv1.Container{
@@ -355,21 +282,6 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
355282
MountPath: "/sys",
356283
ReadOnly: true,
357284
},
358-
apiv1.VolumeMount{
359-
Name: "modules-dir",
360-
MountPath: "/lib/modules",
361-
ReadOnly: true,
362-
},
363-
apiv1.VolumeMount{
364-
Name: "modules-host",
365-
MountPath: "/lib/modules.host",
366-
ReadOnly: true,
367-
},
368-
apiv1.VolumeMount{
369-
Name: "linux-headers-generated",
370-
MountPath: "/usr/src/",
371-
ReadOnly: true,
372-
},
373285
},
374286
SecurityContext: &apiv1.SecurityContext{
375287
Privileged: boolPtr(true),
@@ -399,6 +311,110 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
399311
},
400312
}
401313

314+
if nj.FetchHeaders {
315+
// If we aren't downloading headers, add the initContainer and set up mounts
316+
job.Spec.Template.Spec.InitContainers = []apiv1.Container{
317+
apiv1.Container{
318+
Name: "kubectl-trace-init",
319+
Image: nj.InitImageNameTag,
320+
Resources: apiv1.ResourceRequirements{
321+
Requests: apiv1.ResourceList{
322+
apiv1.ResourceCPU: resource.MustParse("100m"),
323+
apiv1.ResourceMemory: resource.MustParse("100Mi"),
324+
},
325+
Limits: apiv1.ResourceList{
326+
apiv1.ResourceCPU: resource.MustParse("1"),
327+
apiv1.ResourceMemory: resource.MustParse("1G"),
328+
},
329+
},
330+
VolumeMounts: []apiv1.VolumeMount{
331+
apiv1.VolumeMount{
332+
Name: "lsb-release",
333+
MountPath: "/etc/lsb-release.host",
334+
ReadOnly: true,
335+
},
336+
apiv1.VolumeMount{
337+
Name: "os-release",
338+
MountPath: "/etc/os-release.host",
339+
ReadOnly: true,
340+
},
341+
apiv1.VolumeMount{
342+
Name: "modules-dir",
343+
MountPath: "/lib/modules",
344+
},
345+
apiv1.VolumeMount{
346+
Name: "modules-host",
347+
MountPath: "/lib/modules.host",
348+
ReadOnly: true,
349+
},
350+
apiv1.VolumeMount{
351+
Name: "linux-headers-generated",
352+
MountPath: "/usr/src/",
353+
},
354+
},
355+
},
356+
}
357+
358+
job.Spec.Template.Spec.Volumes = append(job.Spec.Template.Spec.Volumes,
359+
apiv1.Volume{
360+
Name: "lsb-release",
361+
VolumeSource: apiv1.VolumeSource{
362+
HostPath: &apiv1.HostPathVolumeSource{
363+
Path: "/etc/lsb-release",
364+
},
365+
},
366+
},
367+
apiv1.Volume{
368+
Name: "os-release",
369+
VolumeSource: apiv1.VolumeSource{
370+
HostPath: &apiv1.HostPathVolumeSource{
371+
Path: "/etc/os-release",
372+
},
373+
},
374+
},
375+
apiv1.Volume{
376+
Name: "modules-dir",
377+
VolumeSource: apiv1.VolumeSource{
378+
HostPath: &apiv1.HostPathVolumeSource{
379+
Path: "/var/cache/linux-headers/modules_dir",
380+
},
381+
},
382+
},
383+
apiv1.Volume{
384+
Name: "linux-headers-generated",
385+
VolumeSource: apiv1.VolumeSource{
386+
HostPath: &apiv1.HostPathVolumeSource{
387+
Path: "/var/cache/linux-headers/generated",
388+
},
389+
},
390+
})
391+
392+
job.Spec.Template.Spec.Containers[0].VolumeMounts = append(job.Spec.Template.Spec.Containers[0].VolumeMounts,
393+
apiv1.VolumeMount{
394+
Name: "modules-dir",
395+
MountPath: "/lib/modules",
396+
ReadOnly: true,
397+
},
398+
apiv1.VolumeMount{
399+
Name: "modules-host",
400+
MountPath: "/lib/modules.host",
401+
ReadOnly: true,
402+
},
403+
apiv1.VolumeMount{
404+
Name: "linux-headers-generated",
405+
MountPath: "/usr/src/",
406+
ReadOnly: true,
407+
})
408+
409+
} else {
410+
// If we aren't downloading headers, unconditionally used the ones linked in /lib/modules
411+
job.Spec.Template.Spec.Containers[0].VolumeMounts = append(job.Spec.Template.Spec.Containers[0].VolumeMounts,
412+
apiv1.VolumeMount{
413+
Name: "modules-host",
414+
MountPath: "/lib/modules",
415+
ReadOnly: true,
416+
})
417+
}
402418
if _, err := t.ConfigClient.Create(cm); err != nil {
403419
return nil, err
404420
}
@@ -476,4 +492,4 @@ func jobStatus(j batchv1.Job) TraceJobStatus {
476492
return TraceJobFailed
477493
}
478494
return TraceJobUnknown
479-
}
495+
}

pkg/version/version.go

-27
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,12 @@ import (
1010
var gitCommit string
1111
var buildTime string
1212
var versionFormat = "git commit: %s\nbuild date: %s"
13-
var imageNameTagFormat = "%s:%s"
14-
var defaultImageName = "quay.io/fntlnz/kubectl-trace-bpftrace"
15-
var defaultImageTag = "latest"
16-
var defaultInitImageName = "quay.io/dalehamel/kubectl-trace-init"
17-
var defaultInitImageTag = "latest"
18-
19-
// ImageName returns the container image name defined in Makefile
20-
func ImageName() string {
21-
return imageName
22-
}
2313

2414
// GitCommit returns the git commit
2515
func GitCommit() string {
2616
return gitCommit
2717
}
2818

29-
func ImageNameTag() string {
30-
imageName := ImageName()
31-
tag := GitCommit()
32-
if len(tag) == 0 {
33-
tag = defaultImageTag
34-
}
35-
if len(imageName) == 0 {
36-
imageName = defaultImageName
37-
}
38-
return fmt.Sprintf(imageNameTagFormat, imageName, tag)
39-
}
40-
41-
// InitImageNameTag returns the full image path and tag for the initContainer
42-
func InitImageNameTag() string {
43-
return fmt.Sprintf(imageNameTagFormat, defaultInitImageName, defaultInitImageTag)
44-
}
45-
4619
// Time returns the build time
4720
func Time() *time.Time {
4821
if len(buildTime) == 0 {

0 commit comments

Comments
 (0)