Skip to content

Commit

Permalink
Fix rerun
Browse files Browse the repository at this point in the history
  • Loading branch information
marniks7 committed Jan 15, 2023
1 parent d94996f commit 193b01f
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/api/pipelineRuns.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ export function generateNewPipelineRunPayload(pipelineRun, rerun) {
namespace
};
if (rerun) {
if (!payload.metadata.labels) {
payload.metadata.labels = { 'dashboard.tekton.dev/rerunOf': name };
}
payload.metadata.labels = {
...labels,
'dashboard.tekton.dev/rerunOf': name
};
}

if (payload.metadata.labels) {
Expand Down
135 changes: 125 additions & 10 deletions src/api/pipelineRuns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,94 @@ it('startPipelineRun', () => {
);
});

it('generate new pipeline run minimum for rerun', () => {
const pr = {
apiVersion: 'tekton.dev/v1beta1',
kind: 'PipelineRun',
metadata: {
name: 'test',
namespace: 'test-namespace'
},
spec: {
pipelineRef: {
name: 'simple'
}
}
};
const { namespace, payload } = generateNewPipelineRunPayload(pr, true);
const expected = `apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: test-r-
labels:
dashboard.tekton.dev/rerunOf: test
namespace: test-namespace
spec:
pipelineRef:
name: simple
`;
expect(namespace).toEqual('test-namespace');
expect(yaml.dump(payload)).toEqual(expected);
});

it('generate new pipeline run maximum for rerun', () => {
const pr = {
apiVersion: 'tekton.dev/v1beta1',
kind: 'PipelineRun',
metadata: {
name: 'test',
namespace: 'test-namespace',
annotations: {
keya: 'valuea',
'kubectl.kubernetes.io/last-applied-configuration':
'{"apiVersion": "tekton.dev/v1beta1", "keya": "valuea"}'
},
labels: {
keyl: 'valuel',
key2: 'value2',
'tekton.dev/pipeline': 'foo'
},
uid: '111-233-33',
resourceVersion: 'aaaa'
},
spec: {
pipelineRef: {
name: 'simple'
},
params: [{ name: 'param-1' }, { name: 'param-2' }]
},
status: { startTime: '0' }
};
const { namespace, payload } = generateNewPipelineRunPayload(pr, true);
const expected = `apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
annotations:
keya: valuea
generateName: test-r-
labels:
keyl: valuel
key2: value2
dashboard.tekton.dev/rerunOf: test
namespace: test-namespace
spec:
pipelineRef:
name: simple
params:
- name: param-1
- name: param-2
`;
expect(namespace).toEqual('test-namespace');
expect(yaml.dump(payload)).toEqual(expected);
});

it('generate new pipeline run minimum', () => {
const pr = {
apiVersion: 'tekton.dev/v1beta1',
kind: 'PipelineRun',
metadata: {
name: 'test',
namespace: 'test2'
namespace: 'test-namespace'
},
spec: {
pipelineRef: {
Expand All @@ -348,12 +429,12 @@ it('generate new pipeline run minimum', () => {
kind: PipelineRun
metadata:
generateName: test-
namespace: test2
namespace: test-namespace
spec:
pipelineRef:
name: simple
`;
expect(namespace).toEqual('test2');
expect(namespace).toEqual('test-namespace');
expect(yaml.dump(payload)).toEqual(expected);
});
it('generate new pipeline run maximum', () => {
Expand All @@ -368,10 +449,11 @@ it('generate new pipeline run maximum', () => {
},
labels: {
keyl: 'valuel',
key2: 'value2'
key2: 'value2',
'tekton.dev/pipeline': 'foo'
},
name: 'test',
namespace: 'test2',
namespace: 'test-namespace',
uid: '111-233-33',
resourceVersion: 'aaaa'
},
Expand All @@ -393,15 +475,15 @@ metadata:
labels:
keyl: valuel
key2: value2
namespace: test2
namespace: test-namespace
spec:
pipelineRef:
name: simple
params:
- name: param-1
- name: param-2
`;
expect(namespace).toEqual('test2');
expect(namespace).toEqual('test-namespace');
expect(yaml.dump(payload)).toEqual(expected);
});
it('generate new pipeline run last applied configuration should be removed', () => {
Expand All @@ -414,7 +496,7 @@ it('generate new pipeline run last applied configuration should be removed', ()
'{"apiVersion": "tekton.dev/v1beta1", "keya": "valuea"}'
},
name: 'test',
namespace: 'test2'
namespace: 'test-namespace'
},
spec: {
pipelineRef: {
Expand All @@ -428,11 +510,44 @@ kind: PipelineRun
metadata:
annotations: {}
generateName: test-
namespace: test2
namespace: test-namespace
spec:
pipelineRef:
name: simple
`;
expect(namespace).toEqual('test-namespace');
expect(yaml.dump(payload)).toEqual(expected);
});

it('generate new pipeline run tekton.dev labels should be removed', () => {
const pr = {
apiVersion: 'tekton.dev/v1beta1',
kind: 'PipelineRun',
metadata: {
name: 'test',
namespace: 'test-namespace',
labels: {
'tekton.dev/pipeline': 'foo',
'tekton.dev/run': 'foo'
}
},
spec: {
pipelineRef: {
name: 'simple'
}
}
};
const { namespace, payload } = generateNewPipelineRunPayload(pr, false);
const expected = `apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: test-
labels: {}
namespace: test-namespace
spec:
pipelineRef:
name: simple
`;
expect(namespace).toEqual('test2');
expect(namespace).toEqual('test-namespace');
expect(yaml.dump(payload)).toEqual(expected);
});

0 comments on commit 193b01f

Please sign in to comment.