Skip to content

Commit

Permalink
Make downloading headers conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
dalehamel committed Mar 10, 2019
1 parent 54900f5 commit 64b7616
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 116 deletions.
194 changes: 105 additions & 89 deletions pkg/tracejob/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,79 +253,6 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
},
},
},
apiv1.Volume{
Name: "lsb-release",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/etc/lsb-release",
},
},
},
apiv1.Volume{
Name: "os-release",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/etc/os-release",
},
},
},
apiv1.Volume{
Name: "modules-dir",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/var/cache/linux-headers/modules_dir",
},
},
},
apiv1.Volume{
Name: "linux-headers-generated",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/var/cache/linux-headers/generated",
},
},
},
},
InitContainers: []apiv1.Container{
apiv1.Container{
Name: "kubectl-trace-init",
Image: version.InitImageNameTag(),
Resources: apiv1.ResourceRequirements{
Requests: apiv1.ResourceList{
apiv1.ResourceCPU: resource.MustParse("100m"),
apiv1.ResourceMemory: resource.MustParse("100Mi"),
},
Limits: apiv1.ResourceList{
apiv1.ResourceCPU: resource.MustParse("1"),
apiv1.ResourceMemory: resource.MustParse("1G"),
},
},
VolumeMounts: []apiv1.VolumeMount{
apiv1.VolumeMount{
Name: "lsb-release",
MountPath: "/etc/lsb-release.host",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "os-release",
MountPath: "/etc/os-release.host",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "modules-dir",
MountPath: "/lib/modules",
},
apiv1.VolumeMount{
Name: "modules-host",
MountPath: "/lib/modules.host",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "linux-headers-generated",
MountPath: "/usr/src/",
},
},
},
},
Containers: []apiv1.Container{
apiv1.Container{
Expand Down Expand Up @@ -355,21 +282,6 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
MountPath: "/sys",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "modules-dir",
MountPath: "/lib/modules",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "modules-host",
MountPath: "/lib/modules.host",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "linux-headers-generated",
MountPath: "/usr/src/",
ReadOnly: true,
},
},
SecurityContext: &apiv1.SecurityContext{
Privileged: boolPtr(true),
Expand Down Expand Up @@ -399,6 +311,110 @@ 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
job.Spec.Template.Spec.InitContainers = []apiv1.Container{
apiv1.Container{
Name: "kubectl-trace-init",
Image: nj.InitImageNameTag,
Resources: apiv1.ResourceRequirements{
Requests: apiv1.ResourceList{
apiv1.ResourceCPU: resource.MustParse("100m"),
apiv1.ResourceMemory: resource.MustParse("100Mi"),
},
Limits: apiv1.ResourceList{
apiv1.ResourceCPU: resource.MustParse("1"),
apiv1.ResourceMemory: resource.MustParse("1G"),
},
},
VolumeMounts: []apiv1.VolumeMount{
apiv1.VolumeMount{
Name: "lsb-release",
MountPath: "/etc/lsb-release.host",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "os-release",
MountPath: "/etc/os-release.host",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "modules-dir",
MountPath: "/lib/modules",
},
apiv1.VolumeMount{
Name: "modules-host",
MountPath: "/lib/modules.host",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "linux-headers-generated",
MountPath: "/usr/src/",
},
},
},
}

job.Spec.Template.Spec.Volumes = append(job.Spec.Template.Spec.Volumes,
apiv1.Volume{
Name: "lsb-release",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/etc/lsb-release",
},
},
},
apiv1.Volume{
Name: "os-release",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/etc/os-release",
},
},
},
apiv1.Volume{
Name: "modules-dir",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/var/cache/linux-headers/modules_dir",
},
},
},
apiv1.Volume{
Name: "linux-headers-generated",
VolumeSource: apiv1.VolumeSource{
HostPath: &apiv1.HostPathVolumeSource{
Path: "/var/cache/linux-headers/generated",
},
},
})

job.Spec.Template.Spec.Containers[0].VolumeMounts = append(job.Spec.Template.Spec.Containers[0].VolumeMounts,
apiv1.VolumeMount{
Name: "modules-dir",
MountPath: "/lib/modules",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "modules-host",
MountPath: "/lib/modules.host",
ReadOnly: true,
},
apiv1.VolumeMount{
Name: "linux-headers-generated",
MountPath: "/usr/src/",
ReadOnly: true,
})

} else {
// If we aren't downloading headers, unconditionally used the ones linked in /lib/modules
job.Spec.Template.Spec.Containers[0].VolumeMounts = append(job.Spec.Template.Spec.Containers[0].VolumeMounts,
apiv1.VolumeMount{
Name: "modules-host",
MountPath: "/lib/modules",
ReadOnly: true,
})
}
if _, err := t.ConfigClient.Create(cm); err != nil {
return nil, err
}
Expand Down Expand Up @@ -476,4 +492,4 @@ func jobStatus(j batchv1.Job) TraceJobStatus {
return TraceJobFailed
}
return TraceJobUnknown
}
}
27 changes: 0 additions & 27 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,12 @@ import (
var gitCommit string
var buildTime string
var versionFormat = "git commit: %s\nbuild date: %s"
var imageNameTagFormat = "%s:%s"
var defaultImageName = "quay.io/fntlnz/kubectl-trace-bpftrace"
var defaultImageTag = "latest"
var defaultInitImageName = "quay.io/dalehamel/kubectl-trace-init"
var defaultInitImageTag = "latest"

// ImageName returns the container image name defined in Makefile
func ImageName() string {
return imageName
}

// GitCommit returns the git commit
func GitCommit() string {
return gitCommit
}

func ImageNameTag() string {
imageName := ImageName()
tag := GitCommit()
if len(tag) == 0 {
tag = defaultImageTag
}
if len(imageName) == 0 {
imageName = defaultImageName
}
return fmt.Sprintf(imageNameTagFormat, imageName, tag)
}

// InitImageNameTag returns the full image path and tag for the initContainer
func InitImageNameTag() string {
return fmt.Sprintf(imageNameTagFormat, defaultInitImageName, defaultInitImageTag)
}

// Time returns the build time
func Time() *time.Time {
if len(buildTime) == 0 {
Expand Down

0 comments on commit 64b7616

Please sign in to comment.