Skip to content

Commit

Permalink
Require all tracejobs to have a deadline, allow overriding this
Browse files Browse the repository at this point in the history
  • Loading branch information
dalehamel committed Sep 16, 2019
1 parent a38c074 commit 56b8dab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var (
ImageNameTag = "quay.io/iovisor/kubectl-trace-bpftrace:latest"
// InitImageNameTag represents the default init container image
InitImageNameTag = "quay.io/iovisor/kubectl-trace-init:latest"
// By default do not allow traces to run for longer than one hour
DefaultDeadline = 3600
)

var (
Expand Down Expand Up @@ -73,6 +75,7 @@ type RunOptions struct {
imageName string
initImageName string
fetchHeaders bool
deadline int64

resourceArg string
attach bool
Expand All @@ -91,6 +94,7 @@ func NewRunOptions(streams genericclioptions.IOStreams) *RunOptions {
serviceAccount: "default",
imageName: ImageNameTag,
initImageName: InitImageNameTag,
deadline: int64(DefaultDeadline),
}
}

Expand Down Expand Up @@ -127,6 +131,7 @@ func NewRunCommand(factory factory.Factory, streams genericclioptions.IOStreams)
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, "Whether to fetch linux headers or not")
cmd.Flags().Int64Var(&o.deadline, "deadline", o.deadline, "Maximum time to allow trace to run in seconds")

return cmd
}
Expand Down Expand Up @@ -289,19 +294,19 @@ func (o *RunOptions) Run() error {
}

tj := tracejob.TraceJob{
Name: fmt.Sprintf("%s%s", meta.ObjectNamePrefix, string(juid)),
Namespace: o.namespace,
ServiceAccount: o.serviceAccount,
ID: juid,
Hostname: o.nodeName,
Program: o.program,
PodUID: o.podUID,
ContainerName: o.container,
IsPod: o.isPod,
// todo(dalehamel) > following fields to be used for #48
Name: fmt.Sprintf("%s%s", meta.ObjectNamePrefix, string(juid)),
Namespace: o.namespace,
ServiceAccount: o.serviceAccount,
ID: juid,
Hostname: o.nodeName,
Program: o.program,
PodUID: o.podUID,
ContainerName: o.container,
IsPod: o.isPod,
ImageNameTag: o.imageName,
InitImageNameTag: o.initImageName,
FetchHeaders: o.fetchHeaders,
Deadline: o.deadline,
}

job, err := tc.CreateJob(tj)
Expand Down
2 changes: 2 additions & 0 deletions pkg/tracejob/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type TraceJob struct {
ImageNameTag string
InitImageNameTag string
FetchHeaders bool
Deadline int64
StartTime metav1.Time
Status TraceJobStatus
}
Expand Down Expand Up @@ -217,6 +218,7 @@ func (t *TraceJobClient) CreateJob(nj TraceJob) (*batchv1.Job, error) {
job := &batchv1.Job{
ObjectMeta: commonMeta,
Spec: batchv1.JobSpec{
ActiveDeadlineSeconds: int64Ptr(nj.Deadline),
TTLSecondsAfterFinished: int32Ptr(5),
Parallelism: int32Ptr(1),
Completions: int32Ptr(1),
Expand Down

0 comments on commit 56b8dab

Please sign in to comment.