Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from v1alpha1 Run to v1beta1 CustomRun #2712

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/200-clusterrole-tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ rules:
- taskruns
- pipelines
- pipelineruns
- runs
- customruns
verbs:
- get
- list
Expand Down
2 changes: 1 addition & 1 deletion overlays/patches/read-write/clusterrole-tenant-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- taskruns
- pipelines
- pipelineruns
- runs
- customruns
verbs:
- create
- update
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/cypress/fixtures/kinds.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{ "label": "Tasks", "path": "/tasks" },
{ "label": "ClusterTasks", "path": "/clustertasks" },
{ "label": "TaskRuns", "path": "/taskruns" },
{ "label": "Runs", "path": "/runs" },
{ "label": "CustomRuns", "path": "/customruns" },
{ "label": "EventListeners", "path": "/eventlisteners" },
{ "label": "Triggers", "path": "/triggers" },
{ "label": "TriggerBindings", "path": "/triggerbindings" },
Expand Down
22 changes: 11 additions & 11 deletions packages/utils/src/utils/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export const paths = {
return '/clustertriggerbindings/:clusterTriggerBindingName';
}
},
customRuns: {
all() {
return '/customruns';
},
byName() {
return byNamespace({ path: '/customruns/:runName' });
},
byNamespace() {
return byNamespace({ path: '/customruns' });
}
},
eventListeners: {
all() {
return '/eventlisteners';
Expand Down Expand Up @@ -129,17 +140,6 @@ export const paths = {
return '/:type/:name';
}
},
runs: {
all() {
return '/runs';
},
byName() {
return byNamespace({ path: '/runs/:runName' });
},
byNamespace() {
return byNamespace({ path: '/runs' });
}
},
settings() {
return '/settings';
},
Expand Down
12 changes: 6 additions & 6 deletions packages/utils/src/utils/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,23 @@ describe('rawCRD', () => {
});
});

describe('runs', () => {
describe('customRuns', () => {
it('all', () => {
expect(urls.runs.all()).toEqual(generatePath(paths.runs.all()));
expect(urls.customRuns.all()).toEqual(generatePath(paths.customRuns.all()));
});

it('byName', () => {
expect(urls.runs.byName({ namespace, runName })).toEqual(
generatePath(paths.runs.byName(), {
expect(urls.customRuns.byName({ namespace, runName })).toEqual(
generatePath(paths.customRuns.byName(), {
namespace,
runName
})
);
});

it('byNamespace', () => {
expect(urls.runs.byNamespace({ namespace })).toEqual(
generatePath(paths.runs.byNamespace(), { namespace })
expect(urls.customRuns.byNamespace({ namespace })).toEqual(
generatePath(paths.customRuns.byNamespace(), { namespace })
);
});
});
Expand Down
56 changes: 34 additions & 22 deletions src/api/runs.js → src/api/customRuns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Tekton Authors
Copyright 2022-2023 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -22,60 +22,72 @@ import {
useResource
} from './utils';

export function deleteRun({ name, namespace }) {
const uri = getTektonAPI('runs', { name, namespace, version: 'v1alpha1' });
export function deleteCustomRun({ name, namespace }) {
const uri = getTektonAPI('customruns', {
name,
namespace,
version: 'v1beta1'
});
return deleteRequest(uri);
}

function getRunsAPI({ filters, isWebSocket, name, namespace }) {
function getCustomRunsAPI({ filters, isWebSocket, name, namespace }) {
return getTektonAPI(
'runs',
{ isWebSocket, namespace, version: 'v1alpha1' },
'customruns',
{ isWebSocket, namespace, version: 'v1beta1' },
getQueryParams({ filters, name })
);
}

export function getRuns({ filters = [], namespace } = {}) {
const uri = getRunsAPI({ filters, namespace });
export function getCustomRuns({ filters = [], namespace } = {}) {
const uri = getCustomRunsAPI({ filters, namespace });
return get(uri);
}

export function getRun({ name, namespace }) {
const uri = getTektonAPI('runs', { name, namespace, version: 'v1alpha1' });
export function getCustomRun({ name, namespace }) {
const uri = getTektonAPI('customruns', {
name,
namespace,
version: 'v1beta1'
});
return get(uri);
}

export function useRuns(params) {
const webSocketURL = getRunsAPI({ ...params, isWebSocket: true });
export function useCustomRuns(params) {
const webSocketURL = getCustomRunsAPI({ ...params, isWebSocket: true });
return useCollection({
api: getRuns,
kind: 'Run',
api: getCustomRuns,
kind: 'CustomRun',
params,
webSocketURL
});
}

export function useRun(params, queryConfig) {
const webSocketURL = getRunsAPI({ ...params, isWebSocket: true });
export function useCustomRun(params, queryConfig) {
const webSocketURL = getCustomRunsAPI({ ...params, isWebSocket: true });
return useResource({
api: getRun,
kind: 'Run',
api: getCustomRun,
kind: 'CustomRun',
params,
queryConfig,
webSocketURL
});
}

export function cancelRun({ name, namespace }) {
export function cancelCustomRun({ name, namespace }) {
const payload = [
{ op: 'replace', path: '/spec/status', value: 'RunCancelled' }
];

const uri = getTektonAPI('runs', { name, namespace, version: 'v1alpha1' });
const uri = getTektonAPI('customruns', {
name,
namespace,
version: 'v1beta1'
});
return patch(uri, payload);
}

export function rerunRun(run) {
export function rerunCustomRun(run) {
const { annotations, labels, name, namespace } = run.metadata;

const payload = deepClone(run);
Expand All @@ -92,6 +104,6 @@ export function rerunRun(run) {
delete payload.status;
delete payload.spec?.status;

const uri = getTektonAPI('runs', { namespace, version: 'v1alpha1' });
const uri = getTektonAPI('customruns', { namespace, version: 'v1beta1' });
return post(uri, payload).then(({ body }) => body);
}
52 changes: 27 additions & 25 deletions src/api/runs.test.js → src/api/customRuns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import * as API from './runs';
import * as API from './customRuns';
import * as utils from './utils';
import * as comms from './comms';
import { rest, server } from '../../config_frontend/msw';

it('cancelRun', () => {
it('cancelCustomRun', () => {
const name = 'foo';
const namespace = 'foospace';
const payload = [
Expand All @@ -25,84 +25,86 @@ it('cancelRun', () => {
jest
.spyOn(comms, 'patch')
.mockImplementation((uri, body) => Promise.resolve(body));
return API.cancelRun({ name, namespace }).then(() => {
return API.cancelCustomRun({ name, namespace }).then(() => {
expect(comms.patch).toHaveBeenCalled();
expect(comms.patch.mock.lastCall[1]).toEqual(payload);
});
});

it('deleteRun', () => {
it('deleteCustomRun', () => {
const name = 'foo';
const data = { fake: 'Run' };
const data = { fake: 'CustomRun' };
server.use(
rest.delete(new RegExp(`/${name}$`), (req, res, ctx) => res(ctx.json(data)))
);
return API.deleteRun({ name }).then(run => {
return API.deleteCustomRun({ name }).then(run => {
expect(run).toEqual(data);
});
});

it('getRun', () => {
it('getCustomRun', () => {
const name = 'foo';
const data = { fake: 'Run' };
const data = { fake: 'CustomRun' };
server.use(
rest.get(new RegExp(`/${name}$`), (req, res, ctx) => res(ctx.json(data)))
);
return API.getRun({ name }).then(run => {
return API.getCustomRun({ name }).then(run => {
expect(run).toEqual(data);
});
});

it('getRuns', () => {
it('getCustomRuns', () => {
const data = {
items: 'Runs'
};
server.use(rest.get(/\/runs\//, (req, res, ctx) => res(ctx.json(data))));
return API.getRuns({ filters: [] }).then(runs => {
server.use(
rest.get(/\/customruns\//, (req, res, ctx) => res(ctx.json(data)))
);
return API.getCustomRuns({ filters: [] }).then(runs => {
expect(runs).toEqual(data);
});
});

it('useRuns', () => {
it('useCustomRuns', () => {
const query = { fake: 'query' };
const params = { fake: 'params' };
jest.spyOn(utils, 'useCollection').mockImplementation(() => query);
expect(API.useRuns(params)).toEqual(query);
expect(API.useCustomRuns(params)).toEqual(query);
expect(utils.useCollection).toHaveBeenCalledWith(
expect.objectContaining({
api: API.getRuns,
kind: 'Run',
api: API.getCustomRuns,
kind: 'CustomRun',
params
})
);
});

it('useRun', () => {
it('useCustomRun', () => {
const query = { fake: 'query' };
const params = { fake: 'params' };
jest.spyOn(utils, 'useResource').mockImplementation(() => query);
expect(API.useRun(params)).toEqual(query);
expect(API.useCustomRun(params)).toEqual(query);
expect(utils.useResource).toHaveBeenCalledWith(
expect.objectContaining({
api: API.getRun,
kind: 'Run',
api: API.getCustomRun,
kind: 'CustomRun',
params
})
);

const queryConfig = { fake: 'queryConfig' };
API.useRun(params, queryConfig);
API.useCustomRun(params, queryConfig);
expect(utils.useResource).toHaveBeenCalledWith(
expect.objectContaining({
api: API.getRun,
kind: 'Run',
api: API.getCustomRun,
kind: 'CustomRun',
params,
queryConfig
})
);
});

it('rerunRun', () => {
it('rerunCustomRun', () => {
const originalRun = {
metadata: { name: 'fake_run' },
spec: { status: 'fake_status' },
Expand All @@ -112,7 +114,7 @@ it('rerunRun', () => {
.spyOn(comms, 'post')
.mockImplementation((uri, body) => Promise.resolve(body));

return API.rerunRun(originalRun).then(() => {
return API.rerunCustomRun(originalRun).then(() => {
expect(comms.post).toHaveBeenCalled();
const sentBody = comms.post.mock.lastCall[1];
const { metadata, spec, status } = sentBody;
Expand Down
2 changes: 1 addition & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export { NamespaceContext, useSelectedNamespace } from './utils';
export * from './clusterInterceptors';
export * from './clusterTasks';
export * from './clusterTriggerBindings';
export * from './customRuns';
export * from './eventListeners';
export * from './extensions';
export * from './interceptors';
export * from './pipelineRuns';
export * from './pipelines';
export * from './runs';
export * from './serviceAccounts';
export * from './taskRuns';
export * from './tasks';
Expand Down
16 changes: 8 additions & 8 deletions src/containers/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import {
CreatePipelineRun,
CreateTaskRun,
CustomResourceDefinition,
CustomRun,
CustomRuns,
EventListener,
EventListeners,
Extension,
Expand All @@ -61,8 +63,6 @@ import {
Pipelines,
ReadWriteRoute,
ResourceList,
Run,
Runs,
Settings,
SideNav,
TaskRun,
Expand Down Expand Up @@ -327,19 +327,19 @@ export function App({ lang }) {
<TaskRun />
</NamespacedRoute>
</CompatRoute>
<CompatRoute path={paths.runs.all()}>
<CompatRoute path={paths.customRuns.all()}>
<NamespacedRoute>
<Runs />
<CustomRuns />
</NamespacedRoute>
</CompatRoute>
<CompatRoute path={paths.runs.byNamespace()} exact>
<CompatRoute path={paths.customRuns.byNamespace()} exact>
<NamespacedRoute>
<Runs />
<CustomRuns />
</NamespacedRoute>
</CompatRoute>
<CompatRoute path={paths.runs.byName()} exact>
<CompatRoute path={paths.customRuns.byName()} exact>
<NamespacedRoute isResourceDetails>
<Run />
<CustomRun />
</NamespacedRoute>
</CompatRoute>
<CompatRoute path={paths.clusterTasks.all()} exact>
Expand Down
Loading