From 9730065da98ec25474136f4a017bb6ab210d0b33 Mon Sep 17 00:00:00 2001 From: Dale Hamel Date: Wed, 6 Mar 2019 10:54:23 -0500 Subject: [PATCH] Make downloading headers conditional --- pkg/tracejob/job.go | 125 ++++++++++++++++++++++------------------- pkg/version/version.go | 27 --------- 2 files changed, 68 insertions(+), 84 deletions(-) diff --git a/pkg/tracejob/job.go b/pkg/tracejob/job.go index f4f63d7c..fe6dd1e4 100644 --- a/pkg/tracejob/job.go +++ b/pkg/tracejob/job.go @@ -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, @@ -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), @@ -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 } @@ -476,4 +487,4 @@ func jobStatus(j batchv1.Job) TraceJobStatus { return TraceJobFailed } return TraceJobUnknown -} \ No newline at end of file +} diff --git a/pkg/version/version.go b/pkg/version/version.go index d367ed40..cc0e129b 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -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 {