From 1ee9a77928d6eeb0b59c12ad146e99866de69cb0 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Thu, 31 Jan 2019 14:55:37 -0700 Subject: [PATCH 01/11] feat(cmd): override help for all commands Signed-off-by: Leonardo Di Donato --- pkg/cmd/run.go | 12 ++++++------ pkg/cmd/trace.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index ae2be4f6..473d78de 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -53,17 +53,17 @@ type RunOptions struct { namespace string explicitNamespace bool - // Local to this command + // Flags local to this command container string eval string program string - resourceArg string - attach bool - isPod bool - podUID string serviceAccount string - nodeName string + resourceArg string + attach bool + isPod bool + podUID string + nodeName string clientConfig *rest.Config } diff --git a/pkg/cmd/trace.go b/pkg/cmd/trace.go index 255d4afa..7b4ed641 100644 --- a/pkg/cmd/trace.go +++ b/pkg/cmd/trace.go @@ -76,5 +76,18 @@ func NewTraceCommand(streams genericclioptions.IOStreams) *cobra.Command { cmd.AddCommand(NewVersionCommand(streams)) cmd.AddCommand(NewLogCommand(f, streams)) + // Override help on all the commands tree + walk(cmd, func(c *cobra.Command) { + c.Flags().BoolP("help", "h", false, fmt.Sprintf("Help for the %s command", c.Name())) + }) + return cmd } + +// walk calls f for c and all of its children. +func walk(c *cobra.Command, f func(*cobra.Command)) { + f(c) + for _, c := range c.Commands() { + walk(c, f) + } +} From 1ac147bfa07a8d4d71d2ef5506152bcf62f8de20 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Fri, 1 Feb 2019 19:47:11 -0700 Subject: [PATCH 02/11] fix(pkg): tracerunner image is not related to kubectl trace version Signed-off-by: Leonardo Di Donato --- pkg/cmd/version.go | 1 + pkg/version/version.go | 24 +++--------------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index ce1a2dc4..24f26f06 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -8,6 +8,7 @@ import ( "k8s.io/cli-runtime/pkg/genericclioptions" ) +// NewVersionCommand provides the version command. func NewVersionCommand(streams genericclioptions.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "version", diff --git a/pkg/version/version.go b/pkg/version/version.go index 3a0d3ff5..cc0e129b 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -8,34 +8,15 @@ import ( // Populated by makefile var gitCommit string -var imageName 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" - -// 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) -} - +// Time returns the build time func Time() *time.Time { if len(buildTime) == 0 { return nil @@ -48,6 +29,7 @@ func Time() *time.Time { return &t } +// String returns version info as a string func String() string { ts := Time() if ts == nil { From 782c4329c7925120bd27446e2e2e56f15141f6c3 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Fri, 1 Feb 2019 19:49:27 -0700 Subject: [PATCH 03/11] build: provide tracerunner and initcontainer images --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ab082f5b..a1dc071e 100644 --- a/Makefile +++ b/Makefile @@ -11,16 +11,22 @@ GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g") IMAGE_NAME ?= quay.io/fntlnz/kubectl-trace-bpftrace IMAGE_NAME_BASE ?= quay.io/fntlnz/kubectl-trace-bpftrace-base +IMAGE_NAME_INIT ?= quay.io/dalehamel/kubectl-trace-init + IMAGE_TRACERUNNER_BRANCH := $(IMAGE_NAME):$(GIT_BRANCH_CLEAN) IMAGE_TRACERUNNER_COMMIT := $(IMAGE_NAME):$(GIT_COMMIT) IMAGE_TRACERUNNER_LATEST := $(IMAGE_NAME):latest +IMAGE_INITCONTAINER_BRANCH := $(IMAGE_NAME_INIT):$(GIT_BRANCH_CLEAN) +IMAGE_INITCONTAINER_COMMIT := $(IMAGE_NAME_INIT):$(GIT_COMMIT) +IMAGE_INITCONTAINER_LATEST := $(IMAGE_NAME_INIT):latest + BPFTRACESHA ?= 2ae2a53f62622631a304def6c193680e603994e3 IMAGE_BPFTRACE_BASE := $(IMAGE_NAME_BASE):$(BPFTRACESHA) IMAGE_BUILD_FLAGS ?= "--no-cache" -LDFLAGS := -ldflags '-X github.com/iovisor/kubectl-trace/pkg/version.buildTime=$(shell date +%s) -X github.com/iovisor/kubectl-trace/pkg/version.gitCommit=${GIT_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/version.imageName=${IMAGE_NAME}' +LDFLAGS := -ldflags '-X github.com/iovisor/kubectl-trace/pkg/version.buildTime=$(shell date +%s) -X github.com/iovisor/kubectl-trace/pkg/version.gitCommit=${GIT_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/cmd.imageNameTag=${IMAGE_TRACERUNNER_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/cmd.initImageNameTag=${IMAGE_INITCONTAINER_COMMIT}' TESTPACKAGES := $(shell go list ./... | grep -v github.com/iovisor/kubectl-trace/integration) kubectl_trace ?= _output/bin/kubectl-trace From e29e247a531ffe90ce72d8d99fd21933bf3d200a Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Fri, 1 Feb 2019 19:52:16 -0700 Subject: [PATCH 04/11] feat(cmd): support custom images for tracerunner and init container Signed-off-by: Leonardo Di Donato Co-Authored-By: Lorenzo Fontana --- pkg/cmd/get.go | 3 ++- pkg/cmd/run.go | 30 ++++++++++++++++++++++++++---- pkg/tracejob/job.go | 45 +++++++++++++++++++++++---------------------- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/pkg/cmd/get.go b/pkg/cmd/get.go index 4b870b90..65db89d4 100644 --- a/pkg/cmd/get.go +++ b/pkg/cmd/get.go @@ -111,6 +111,7 @@ func (o *GetOptions) Validate(cmd *cobra.Command, args []string) error { return nil } +// Complete completes the setup of the command. func (o *GetOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error { // Prepare namespace var err error @@ -125,7 +126,7 @@ func (o *GetOptions) Complete(factory factory.Factory, cmd *cobra.Command, args o.namespace = "" } - //// Prepare client + // Prepare client o.clientConfig, err = factory.ToRESTConfig() if err != nil { return err diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 473d78de..a55f4efb 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -20,6 +20,11 @@ import ( "k8s.io/client-go/rest" ) +const ( + imageNameTag = "quay.io/fntlnz/kubectl-trace-bpftrace:latest" + initImageNameTag = "quay.io/dalehamel/kubectl-trace-init" +) + var ( runShort = `Execute a bpftrace program on resources` // Wrap with i18n.T() @@ -35,7 +40,10 @@ var ( # Run an bpftrace inline program on a pod container %[1]s trace run pod/nginx -c nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }" %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }" - %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }"` + %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }" + + # Run a bpftrace inline program on a pod container with a custom image for the init container responsible to fetch linux headers + %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); } --init-imagename=quay.io/custom-init-image-name --fetch-headers"` runCommand = "run" usageString = "(POD | TYPE/NAME)" @@ -58,6 +66,9 @@ type RunOptions struct { eval string program string serviceAccount string + imageName string + initImageName string + fetchHeaders bool resourceArg string attach bool @@ -72,6 +83,10 @@ type RunOptions struct { func NewRunOptions(streams genericclioptions.IOStreams) *RunOptions { return &RunOptions{ IOStreams: streams, + + serviceAccount: "default", + imageName: imageNameTag, + initImageName: initImageNameTag, } } @@ -102,9 +117,12 @@ func NewRunCommand(factory factory.Factory, streams genericclioptions.IOStreams) cmd.Flags().StringVarP(&o.container, "container", "c", o.container, "Specify the container") cmd.Flags().BoolVarP(&o.attach, "attach", "a", o.attach, "Wheter or not to attach to the trace program once it is created") - cmd.Flags().StringVarP(&o.eval, "eval", "e", "", "Literal string to be evaluated as a bpftrace program") - cmd.Flags().StringVarP(&o.program, "filename", "f", "", "File containing a bpftrace program") - cmd.Flags().StringVar(&o.serviceAccount, "serviceaccount", "default", "Service account to use to set in the pod spec of the kubectl-trace job") + cmd.Flags().StringVarP(&o.eval, "eval", "e", o.eval, "Literal string to be evaluated as a bpftrace program") + cmd.Flags().StringVarP(&o.program, "filename", "f", o.program, "File containing a bpftrace program") + cmd.Flags().StringVar(&o.serviceAccount, "serviceaccount", o.serviceAccount, "Service account to use to set in the pod spec of the kubectl-trace job") + cmd.Flags().StringVar(&o.imageName, "imagename", o.imageName, "Custom image for the tracerunner") + cmd.Flags().StringVar(&o.initImageName, "init-imagename", o.initImageName, "Custom image for the init container responsible to fetch and prepare linux headers") + cmd.Flags().BoolVar(&o.fetchHeaders, "fetch-headers", o.fetchHeaders, "Wheter to fetch linux headers or not") return cmd } @@ -276,6 +294,10 @@ func (o *RunOptions) Run() error { PodUID: o.podUID, ContainerName: o.container, IsPod: o.isPod, + // todo(dalehamel) > following fields to be used for #48 + ImageNameTag: o.imageName, + InitImageNameTag: o.initImageName, + FetchHeaders: o.fetchHeaders, } job, err := tc.CreateJob(tj) diff --git a/pkg/tracejob/job.go b/pkg/tracejob/job.go index 9fafe77c..82990369 100644 --- a/pkg/tracejob/job.go +++ b/pkg/tracejob/job.go @@ -2,18 +2,15 @@ package tracejob import ( "fmt" - - "github.com/iovisor/kubectl-trace/pkg/version" - "io" "io/ioutil" "github.com/iovisor/kubectl-trace/pkg/meta" batchv1 "k8s.io/api/batch/v1" apiv1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/api/resource" batchv1typed "k8s.io/client-go/kubernetes/typed/batch/v1" corev1typed "k8s.io/client-go/kubernetes/typed/core/v1" ) @@ -24,16 +21,20 @@ type TraceJobClient struct { outStream io.Writer } +// TraceJob is a container of info needed to create the job responsible for tracing. type TraceJob struct { - Name string - ID types.UID - Namespace string - ServiceAccount string - Hostname string - Program string - PodUID string - ContainerName string - IsPod bool + Name string + ID types.UID + Namespace string + ServiceAccount string + Hostname string + Program string + PodUID string + ContainerName string + IsPod bool + ImageNameTag string + InitImageNameTag string + FetchHeaders bool } // WithOutStream setup a file stream to output trace job operation information @@ -252,19 +253,19 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) { Containers: []apiv1.Container{ apiv1.Container{ Name: nj.Name, - Image: version.ImageNameTag(), + Image: nj.ImageNameTag, Command: bpfTraceCmd, TTY: true, Stdin: true, 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"), - }, + 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{ From 6c4c7439976ca524506c577d3830145496e788ca Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Fri, 1 Feb 2019 19:53:41 -0700 Subject: [PATCH 05/11] chore(cmd): typos and little improv --- pkg/cmd/attach.go | 1 + pkg/cmd/delete.go | 1 + pkg/cmd/log.go | 2 ++ pkg/cmd/tracerunner.go | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/attach.go b/pkg/cmd/attach.go index a83653c7..6031106b 100644 --- a/pkg/cmd/attach.go +++ b/pkg/cmd/attach.go @@ -92,6 +92,7 @@ func (o *AttachOptions) Validate(cmd *cobra.Command, args []string) error { return nil } +// Complete completes the setup of the command. func (o *AttachOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error { // Prepare namespace var err error diff --git a/pkg/cmd/delete.go b/pkg/cmd/delete.go index d48d9395..0e6f3211 100644 --- a/pkg/cmd/delete.go +++ b/pkg/cmd/delete.go @@ -102,6 +102,7 @@ func (o *DeleteOptions) Validate(cmd *cobra.Command, args []string) error { return nil } +// Complete completes the setup of the command. func (o *DeleteOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error { // Prepare namespace var err error diff --git a/pkg/cmd/log.go b/pkg/cmd/log.go index d0cf072e..13055402 100644 --- a/pkg/cmd/log.go +++ b/pkg/cmd/log.go @@ -85,6 +85,7 @@ func NewLogCommand(factory factory.Factory, streams genericclioptions.IOStreams) return cmd } +// Validate validates the arguments and flags populating LogOptions accordingly. func (o *LogOptions) Validate(cmd *cobra.Command, args []string) error { if meta.IsObjectName(args[0]) { o.traceName = &args[0] @@ -96,6 +97,7 @@ func (o *LogOptions) Validate(cmd *cobra.Command, args []string) error { return nil } +// Complete completes the setup of the command. func (o *LogOptions) Complete(factory factory.Factory, cmd *cobra.Command, args []string) error { // Prepare namespace var err error diff --git a/pkg/cmd/tracerunner.go b/pkg/cmd/tracerunner.go index 8203ba12..a744b3d0 100644 --- a/pkg/cmd/tracerunner.go +++ b/pkg/cmd/tracerunner.go @@ -50,7 +50,7 @@ func NewTraceRunnerCommand() *cobra.Command { cmd.Flags().StringVarP(&o.podUID, "poduid", "p", o.podUID, "Specify the pod UID") cmd.Flags().StringVarP(&o.programPath, "program", "f", "program.bt", "Specify the bpftrace program path") cmd.Flags().StringVarP(&o.bpftraceBinaryPath, "bpftracebinary", "b", "/bin/bpftrace", "Specify the bpftrace binary path") - cmd.Flags().BoolVar(&o.inPod, "inpod", false, "Wether or not run this bpftrace in a pod's container process namespace") + cmd.Flags().BoolVar(&o.inPod, "inpod", false, "Wheter or not run this bpftrace in a pod's container process namespace") return cmd } @@ -62,6 +62,7 @@ func (o *TraceRunnerOptions) Validate(cmd *cobra.Command, args []string) error { return nil } +// Complete completes the setup of the command. func (o *TraceRunnerOptions) Complete(cmd *cobra.Command, args []string) error { return nil } From 70b0268142b721ee56cf5d1f3495d72533745599 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Sat, 2 Feb 2019 10:53:21 -0700 Subject: [PATCH 06/11] fix(integration): public (default) image name tag Signed-off-by: Leonardo Di Donato --- Makefile | 4 ++-- integration/suite_test.go | 4 ++-- pkg/cmd/run.go | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a1dc071e..80a41397 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ IMAGE_BPFTRACE_BASE := $(IMAGE_NAME_BASE):$(BPFTRACESHA) IMAGE_BUILD_FLAGS ?= "--no-cache" -LDFLAGS := -ldflags '-X github.com/iovisor/kubectl-trace/pkg/version.buildTime=$(shell date +%s) -X github.com/iovisor/kubectl-trace/pkg/version.gitCommit=${GIT_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/cmd.imageNameTag=${IMAGE_TRACERUNNER_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/cmd.initImageNameTag=${IMAGE_INITCONTAINER_COMMIT}' +LDFLAGS := -ldflags '-X github.com/iovisor/kubectl-trace/pkg/version.buildTime=$(shell date +%s) -X github.com/iovisor/kubectl-trace/pkg/version.gitCommit=${GIT_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/cmd.ImageNameTag=${IMAGE_TRACERUNNER_COMMIT} -X github.com/iovisor/kubectl-trace/pkg/cmd.InitImageNameTag=${IMAGE_INITCONTAINER_COMMIT}' TESTPACKAGES := $(shell go list ./... | grep -v github.com/iovisor/kubectl-trace/integration) kubectl_trace ?= _output/bin/kubectl-trace @@ -71,7 +71,7 @@ test: .PHONY: integration integration: - TEST_KUBECTLTRACE_BINARY=$(shell pwd)/$(kubectl_trace) $(GO) test ${LDFLAGS} -v ./integration/... + TEST_KUBECTLTRACE_BINARY=$(shell pwd)/$(kubectl_trace) $(GO) test ${LDFLAGS} -v ./integration/... .PHONY: bpftraceimage/build bpftraceimage/build: diff --git a/integration/suite_test.go b/integration/suite_test.go index 25e401ef..bdc4202a 100644 --- a/integration/suite_test.go +++ b/integration/suite_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/go-check/check" - "github.com/iovisor/kubectl-trace/pkg/version" + "github.com/iovisor/kubectl-trace/pkg/cmd" "gotest.tools/icmd" "sigs.k8s.io/kind/pkg/cluster" "sigs.k8s.io/kind/pkg/cluster/config/encoding" @@ -59,7 +59,7 @@ func (k *KubectlTraceSuite) SetUpSuite(c *check.C) { // copy the bpftrace image to the nodes for _, n := range nodes { - loadcomm := fmt.Sprintf("docker save %s | docker exec -i %s docker load", version.ImageNameTag(), n.String()) + loadcomm := fmt.Sprintf("docker save %s | docker exec -i %s docker load", cmd.ImageNameTag, n.String()) res := icmd.RunCommand("bash", "-c", loadcomm) c.Assert(res.Error, check.IsNil) } diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index a55f4efb..d2f31715 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -21,8 +21,10 @@ import ( ) const ( - imageNameTag = "quay.io/fntlnz/kubectl-trace-bpftrace:latest" - initImageNameTag = "quay.io/dalehamel/kubectl-trace-init" + // ImageNameTag represents the default tracerunner image + ImageNameTag = "quay.io/fntlnz/kubectl-trace-bpftrace:latest" + // InitImageNameTag represents the default init container image + InitImageNameTag = "quay.io/dalehamel/kubectl-trace-init:latest" ) var ( @@ -85,8 +87,8 @@ func NewRunOptions(streams genericclioptions.IOStreams) *RunOptions { IOStreams: streams, serviceAccount: "default", - imageName: imageNameTag, - initImageName: initImageNameTag, + imageName: ImageNameTag, + initImageName: InitImageNameTag, } } From 53d8b8de35b6e621f25059fcaca9b58b31fcc0fb Mon Sep 17 00:00:00 2001 From: Lorenzo Fontana Date: Thu, 7 Feb 2019 00:24:12 +0100 Subject: [PATCH 07/11] fix(pkg/cmd): const can't be updated with ldflags Signed-off-by: Lorenzo Fontana --- pkg/cmd/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index d2f31715..0623d5c8 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -20,7 +20,7 @@ import ( "k8s.io/client-go/rest" ) -const ( +var ( // ImageNameTag represents the default tracerunner image ImageNameTag = "quay.io/fntlnz/kubectl-trace-bpftrace:latest" // InitImageNameTag represents the default init container image From c3e4e1a19ab3477e7bf672c593fb0d72b47602f1 Mon Sep 17 00:00:00 2001 From: Lorenzo Fontana Date: Thu, 7 Feb 2019 01:15:18 +0100 Subject: [PATCH 08/11] feat(pkg/cmd): move images under fntlnz Signed-off-by: Lorenzo Fontana --- Makefile | 2 +- pkg/cmd/run.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 80a41397..8b937dc1 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g") IMAGE_NAME ?= quay.io/fntlnz/kubectl-trace-bpftrace IMAGE_NAME_BASE ?= quay.io/fntlnz/kubectl-trace-bpftrace-base -IMAGE_NAME_INIT ?= quay.io/dalehamel/kubectl-trace-init +IMAGE_NAME_INIT ?= quay.io/fntlnz/kubectl-trace-init IMAGE_TRACERUNNER_BRANCH := $(IMAGE_NAME):$(GIT_BRANCH_CLEAN) IMAGE_TRACERUNNER_COMMIT := $(IMAGE_NAME):$(GIT_COMMIT) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 0623d5c8..dde1676a 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -24,7 +24,7 @@ var ( // ImageNameTag represents the default tracerunner image ImageNameTag = "quay.io/fntlnz/kubectl-trace-bpftrace:latest" // InitImageNameTag represents the default init container image - InitImageNameTag = "quay.io/dalehamel/kubectl-trace-init:latest" + InitImageNameTag = "quay.io/fntlnz/kubectl-trace-init:latest" ) var ( From 3b9e9fe64157e4440a53f0d9f03b77e35ed28866 Mon Sep 17 00:00:00 2001 From: Lorenzo Fontana Date: Thu, 7 Feb 2019 01:25:37 +0100 Subject: [PATCH 09/11] feat(pkg/cmd): add more documentation cases for image and init image flags Signed-off-by: Lorenzo Fontana --- pkg/cmd/run.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index dde1676a..e02700a9 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -42,10 +42,12 @@ var ( # Run an bpftrace inline program on a pod container %[1]s trace run pod/nginx -c nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }" %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }" - %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); }" # Run a bpftrace inline program on a pod container with a custom image for the init container responsible to fetch linux headers - %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); } --init-imagename=quay.io/custom-init-image-name --fetch-headers"` + %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); } --init-imagename=quay.io/custom-init-image-name --fetch-headers" + + # Run a bpftrace inline program on a pod container with a custom image for the bpftrace container that will run your program in the cluster + %[1]s trace run pod/nginx nginx -e "tracepoint:syscalls:sys_enter_* { @[probe] = count(); } --imagename=quay.io/custom-bpftrace-image-name"` runCommand = "run" usageString = "(POD | TYPE/NAME)" From 6ff23309ad1875ac8da1022a85946bb3dc086fa8 Mon Sep 17 00:00:00 2001 From: Lorenzo Fontana Date: Thu, 7 Feb 2019 01:40:59 +0100 Subject: [PATCH 10/11] fix(kubectl-trace): fix typo wether to whether Signed-off-by: Lorenzo Fontana --- pkg/cmd/run.go | 4 ++-- pkg/cmd/tracerunner.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index e02700a9..d9f520d0 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -120,13 +120,13 @@ func NewRunCommand(factory factory.Factory, streams genericclioptions.IOStreams) } cmd.Flags().StringVarP(&o.container, "container", "c", o.container, "Specify the container") - cmd.Flags().BoolVarP(&o.attach, "attach", "a", o.attach, "Wheter or not to attach to the trace program once it is created") + cmd.Flags().BoolVarP(&o.attach, "attach", "a", o.attach, "Whether or not to attach to the trace program once it is created") cmd.Flags().StringVarP(&o.eval, "eval", "e", o.eval, "Literal string to be evaluated as a bpftrace program") cmd.Flags().StringVarP(&o.program, "filename", "f", o.program, "File containing a bpftrace program") cmd.Flags().StringVar(&o.serviceAccount, "serviceaccount", o.serviceAccount, "Service account to use to set in the pod spec of the kubectl-trace job") cmd.Flags().StringVar(&o.imageName, "imagename", o.imageName, "Custom image for the tracerunner") cmd.Flags().StringVar(&o.initImageName, "init-imagename", o.initImageName, "Custom image for the init container responsible to fetch and prepare linux headers") - cmd.Flags().BoolVar(&o.fetchHeaders, "fetch-headers", o.fetchHeaders, "Wheter to fetch linux headers or not") + cmd.Flags().BoolVar(&o.fetchHeaders, "fetch-headers", o.fetchHeaders, "Whether to fetch linux headers or not") return cmd } diff --git a/pkg/cmd/tracerunner.go b/pkg/cmd/tracerunner.go index a744b3d0..c4dffdca 100644 --- a/pkg/cmd/tracerunner.go +++ b/pkg/cmd/tracerunner.go @@ -50,7 +50,7 @@ func NewTraceRunnerCommand() *cobra.Command { cmd.Flags().StringVarP(&o.podUID, "poduid", "p", o.podUID, "Specify the pod UID") cmd.Flags().StringVarP(&o.programPath, "program", "f", "program.bt", "Specify the bpftrace program path") cmd.Flags().StringVarP(&o.bpftraceBinaryPath, "bpftracebinary", "b", "/bin/bpftrace", "Specify the bpftrace binary path") - cmd.Flags().BoolVar(&o.inPod, "inpod", false, "Wheter or not run this bpftrace in a pod's container process namespace") + cmd.Flags().BoolVar(&o.inPod, "inpod", false, "Whether or not run this bpftrace in a pod's container process namespace") return cmd } From 4689c6288fedd82590616d6b8753adc872478a25 Mon Sep 17 00:00:00 2001 From: Lorenzo Fontana Date: Thu, 7 Feb 2019 01:45:39 +0100 Subject: [PATCH 11/11] fix(pkg/cmd): escape bpftrace program in examples Signed-off-by: Lorenzo Fontana --- pkg/cmd/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index d9f520d0..eede7dba 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -34,7 +34,7 @@ var ( runExamples = ` # Count system calls using tracepoints on a specific node - %[1]s trace run node/kubernetes-node-emt8.c.myproject.internal -e 'kprobe:do_sys_open { printf("%s: %s\n", comm, str(arg1)) }' + %[1]s trace run node/kubernetes-node-emt8.c.myproject.internal -e 'kprobe:do_sys_open { printf("%%s: %%s\n", comm, str(arg1)) }' # Execute a bpftrace program from file on a specific node %[1]s trace run node/kubernetes-node-emt8.c.myproject.internal -f read.bt