Skip to content

Commit

Permalink
Add Create page and connect to Create button and EditAndRun button
Browse files Browse the repository at this point in the history
  • Loading branch information
jisoolee committed Sep 19, 2023
1 parent d209732 commit 9a65bac
Show file tree
Hide file tree
Showing 7 changed files with 986 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/utils/src/utils/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export const paths = {
},
byNamespace() {
return byNamespace({ path: '/customruns' });
},
create() {
return '/customruns/create';
}
},
eventListeners: {
Expand Down
122 changes: 122 additions & 0 deletions src/api/customRuns.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { deleteRequest, get, patch, post } from './comms';
import {
getQueryParams,
getTektonAPI,
getTektonPipelinesAPIVersion,
removeSystemAnnotations,
removeSystemLabels,
useCollection,
useResource
} from './utils';
Expand All @@ -39,6 +42,53 @@ function getCustomRunsAPI({ filters, isWebSocket, name, namespace }) {
);
}

export function getCustomRunPayload({
kind,
labels,
namespace,
nodeSelector,
params,
serviceAccount,
customName,
customRunName = `${customName ? `${customName}-run` : 'run'}-${Date.now()}`,
timeout
}) {
const payload = {
apiVersion: 'tekton.dev/v1beta1',
kind: 'CustomRun',
metadata: {
name: customRunName,
namespace
},
spec: {
customRef: {
apiVersion: '',
kind: 'Custom'
}
}
};
if (labels) {
payload.metadata.labels = labels;
}
if (params) {
payload.spec.params = Object.keys(params).map(name => ({
name,
value: params[name]
}));
}
if (nodeSelector) {
payload.spec.podTemplate = { nodeSelector };
}
if (serviceAccount) {
payload.spec.serviceAccountName = serviceAccount;
}
if (timeout) {
payload.spec.timeout = timeout;
}

return payload;
}

export function getCustomRuns({ filters = [], namespace } = {}) {
const uri = getCustomRunsAPI({ filters, namespace });
return get(uri);
Expand All @@ -55,6 +105,7 @@ export function getCustomRun({ name, namespace }) {

export function useCustomRuns(params) {
const webSocketURL = getCustomRunsAPI({ ...params, isWebSocket: true });
console.log("url: " + webSocketURL);
return useCollection({
api: getCustomRuns,
kind: 'CustomRun',
Expand Down Expand Up @@ -107,3 +158,74 @@ export function rerunCustomRun(run) {
const uri = getTektonAPI('customruns', { namespace, version: 'v1beta1' });
return post(uri, payload).then(({ body }) => body);
}

export function createCustomRun({
kind,
labels,
namespace,
nodeSelector,
params,
serviceAccount,
customName,
customRunName = `${customName}-run-${Date.now()}`,
timeout
}) {
const payload = getCustomRunPayload({
kind,
labels,
namespace,
nodeSelector,
params,
serviceAccount,
customName,
customRunName,
timeout
});
const uri = getTektonAPI('customruns', { namespace });
return post(uri, payload).then(({ body }) => body);
}

export function createCustomRunRaw({ namespace, payload }) {
const uri = getTektonAPI('customruns', { namespace, version: 'v1beta1' });
return post(uri, payload).then(({ body }) => body);
}

export function generateNewCustomRunPayload({ customRun, rerun }) {
const { annotations, labels, name, namespace, generateName } =
customRun.metadata;

const payload = deepClone(customRun);
payload.apiVersion =
payload.apiVersion || 'tekton.dev/v1beta1';
payload.kind = payload.kind || 'CustomRun';

function getGenerateName() {
if (rerun) {
return getGenerateNamePrefixForRerun(name);
}

return generateName || `${name}-`;
}

payload.metadata = {
annotations: annotations || {},
generateName: getGenerateName(),
labels: labels || {},
namespace
};
if (rerun) {
payload.metadata.labels['dashboard.tekton.dev/rerunOf'] = name;
}

removeSystemAnnotations(payload);
removeSystemLabels(payload);

Object.keys(payload.metadata).forEach(
i => payload.metadata[i] === undefined && delete payload.metadata[i]
);

delete payload.status;

delete payload.spec?.status;
return { namespace, payload };
}
6 changes: 6 additions & 0 deletions src/containers/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
ClusterTasks,
ClusterTriggerBinding,
ClusterTriggerBindings,
CreateCustomRun,
CreatePipelineRun,
CreateTaskRun,
CustomResourceDefinition,
Expand Down Expand Up @@ -322,6 +323,11 @@ export function App({ lang }) {
<TaskRun />
</NamespacedRoute>
</CompatRoute>
<CompatRoute path={paths.customRuns.create()} exact>
<ReadWriteRoute>
<CreateCustomRun />
</ReadWriteRoute>
</CompatRoute>
<CompatRoute path={paths.customRuns.all()}>
<NamespacedRoute>
<CustomRuns />
Expand Down
Loading

0 comments on commit 9a65bac

Please sign in to comment.