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 6, 2019
1 parent aac3243 commit 9730065
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 84 deletions.
125 changes: 68 additions & 57 deletions pkg/tracejob/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,47 +286,6 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
},
},
},
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{
Name: nj.Name,
Expand Down Expand Up @@ -355,21 +314,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 +343,73 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
},
}

if nj.FetchHeaders {
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.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 {
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 +487,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 9730065

Please sign in to comment.