Skip to content

Commit

Permalink
fix(tekton): Allow configuring Pipeline timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
  • Loading branch information
abayer committed Jun 12, 2019
1 parent d6d194e commit 5ce3c83
Show file tree
Hide file tree
Showing 11 changed files with 506 additions and 8 deletions.
10 changes: 9 additions & 1 deletion pkg/jx/cmd/step/create/step_create_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,15 @@ func (o *StepCreateTaskOptions) GenerateTektonCRDs(packsDir string, projectConfi

tasks, pipeline = o.EnhanceTasksAndPipeline(tasks, pipeline, pipelineConfig.Env)
resources := []*pipelineapi.PipelineResource{tekton.GenerateSourceRepoResource(pipelineResourceName, o.GitInfo, o.Revision)}
run := tekton.CreatePipelineRun(resources, pipeline.Name, pipeline.APIVersion, o.labels, o.Trigger, o.ServiceAccount, o.pipelineParams)

var timeout *metav1.Duration
if parsed.Options != nil && parsed.Options.Timeout != nil {
timeout, err = parsed.Options.Timeout.ToDuration()
if err != nil {
return nil, errors.Wrapf(err, "parsing of pipeline timeout failed")
}
}
run := tekton.CreatePipelineRun(resources, pipeline.Name, pipeline.APIVersion, o.labels, o.Trigger, o.ServiceAccount, o.pipelineParams, timeout)

tektonCRDs, err := tekton.NewCRDWrapper(pipeline, tasks, resources, structure, run)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/jx/cmd/step/create/step_create_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ func TestGenerateTektonCRDs(t *testing.T) {
branch: "really-long",
kind: "release",
},
{
name: "pipeline-timeout",
language: "none",
repoName: "js-test-repo",
organization: "abayer",
branch: "really-long",
kind: "release",
},
}

k8sObjects := []runtime.Object{
Expand Down Expand Up @@ -380,8 +388,6 @@ func TestGenerateTektonCRDs(t *testing.T) {
}

if d := cmp.Diff(tekton_helpers_test.AssertLoadPipelineRun(t, caseDir), crds.PipelineRun()); d != "" {
pry, _ := yaml.Marshal(crds.PipelineRun())
t.Logf("PR: %s", pry)
t.Errorf("Generated PipelineRun did not match expected: %s", d)
}
if d := cmp.Diff(tekton_helpers_test.AssertLoadPipelineStructure(t, caseDir), crds.Structure()); d != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ spec:
name: abayer-js-test-repo-really-long
serviceAccount: tekton-bot
timeout: 240h0m0s
timeout: 240h0m0s
trigger:
type: manual
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pipelineConfig:
env:
- name: FRUIT
value: BANANA
pipelines:
release:
pipeline:
env:
- name: GIT_AUTHOR_NAME
value: somebodyelse
options:
timeout:
time: 10
unit: hours
containerOptions:
resources:
requests:
cpu: 0.1
memory: 64Mi
agent:
image: nodejs
stages:
- name: Build-a-really-long-stage-name-please-but-not-too-long-thanks
steps:
- command: echo
args:
- hello world
- command: ls
args:
- -la
env:
- name: ANOTHER_VAR
value: Another value
- name: Second
steps:
- command: echo
args:
- hi ${FRUIT}
options:
containerOptions:
resources:
limits:
cpu: 0.4
memory: 256Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
creationTimestamp: null
name: abayer-js-test-repo-really-long-1
namespace: jx
labels:
branch: really-long
owner: abayer
repo: js-test-repo
spec:
params:
- default: 0.0.1
description: the version number for this pipeline which is used as a tag on docker
images and helm charts
name: version
resources:
- name: abayer-js-test-repo-really-long
type: git
tasks:
- name: build-a-really-long-stage-name-please-but-not-too-long-thanks
params:
- name: version
value: ${params.version}
resources:
inputs:
- name: workspace
resource: abayer-js-test-repo-really-long
outputs:
- name: workspace
resource: abayer-js-test-repo-really-long
taskRef:
name: abayer-js-test-repo-really-long-build-a-really-long-stage-nam-1
- name: second
params:
- name: version
value: ${params.version}
resources:
inputs:
- from:
- build-a-really-long-stage-name-please-but-not-too-long-thanks
name: workspace
resource: abayer-js-test-repo-really-long
runAfter:
- build-a-really-long-stage-name-please-but-not-too-long-thanks
taskRef:
name: abayer-js-test-repo-really-long-second-1
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
items:
- apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
creationTimestamp: null
name: abayer-js-test-repo-really-long
spec:
params:
- name: revision
value: v0.0.1
- name: url
value: https://github.com/abayer/js-test-repo
type: git
status: {}
metadata: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
creationTimestamp: null
labels:
branch: really-long
owner: abayer
repo: js-test-repo
name: abayer-js-test-repo-really-long-1
spec:
params:
- name: version
value: 0.0.1
pipelineRef:
apiVersion: tekton.dev/v1alpha1
name: abayer-js-test-repo-really-long-1
resources:
- name: abayer-js-test-repo-really-long
resourceRef:
apiVersion: tekton.dev/v1alpha1
name: abayer-js-test-repo-really-long
serviceAccount: tekton-bot
timeout: 10h0m0s
trigger:
type: manual
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
metadata:
creationTimestamp: null
name: abayer-js-test-repo-really-long-1
labels:
branch: really-long
owner: abayer
repo: js-test-repo
pipelineRef: null
pipelineRunRef: null
stages:
- depth: 0
name: Build-a-really-long-stage-name-please-but-not-too-long-thanks
taskRef: abayer-js-test-repo-really-long-build-a-really-long-stage-nam-1
- depth: 0
name: Second
previous: Build-a-really-long-stage-name-please-but-not-too-long-thanks
taskRef: abayer-js-test-repo-really-long-second-1
Loading

0 comments on commit 5ce3c83

Please sign in to comment.