Skip to content

Commit

Permalink
Remove the Tekton Pipelines version toggle on the settings page
Browse files Browse the repository at this point in the history
Related to tektoncd#2976
  • Loading branch information
AlanGreene committed May 28, 2024
1 parent ec9284a commit cb2d7ef
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 92 deletions.
29 changes: 3 additions & 26 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
getKubeAPI,
getQueryParams,
getTektonAPI,
getTektonPipelinesAPIVersion,
isLogTimestampsEnabled,
useCollection,
useResource
Expand Down Expand Up @@ -282,9 +281,8 @@ export function importResources({
serviceAccount
}) {
const pipelineRun = deepClone(importResourcesPipelineRunTemplate);
const pipelinesAPIVersion = getTektonPipelinesAPIVersion();

pipelineRun.apiVersion = `tekton.dev/${pipelinesAPIVersion}`;
pipelineRun.apiVersion = 'tekton.dev/v1';
pipelineRun.metadata.name = `import-resources-${Date.now()}`;
pipelineRun.metadata.labels = {
...labels,
Expand All @@ -298,33 +296,12 @@ export function importResources({
{ name: 'target-namespace', value: namespace }
];

if (pipelinesAPIVersion === 'v1beta1') {
pipelineRun.spec.podTemplate = {
...pipelineRun.spec.taskRunTemplate.podTemplate
};
delete pipelineRun.spec.taskRunTemplate.podTemplate;
}

if (serviceAccount) {
if (pipelinesAPIVersion === 'v1') {
pipelineRun.spec.taskRunTemplate.serviceAccountName = serviceAccount;
} else {
pipelineRun.spec.taskRunSpecs = [
{
pipelineTaskName: 'fetch-repo',
taskServiceAccountName: serviceAccount
},
{
pipelineTaskName: 'import-resources',
taskServiceAccountName: serviceAccount
}
];
}
pipelineRun.spec.taskRunTemplate.serviceAccountName = serviceAccount;
}

const uri = getTektonAPI('pipelineruns', {
namespace: importerNamespace,
version: pipelinesAPIVersion
namespace: importerNamespace
});
return post(uri, pipelineRun).then(({ body }) => body);
}
Expand Down
18 changes: 5 additions & 13 deletions src/api/pipelineRuns.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { deleteRequest, get, patch, post } from './comms';
import {
getQueryParams,
getTektonAPI,
getTektonPipelinesAPIVersion,
removeSystemLabels,
useCollection,
useResource
Expand Down Expand Up @@ -95,10 +94,8 @@ export function getPipelineRunPayload({
timeoutsPipeline,
timeoutsTasks
}) {
const pipelinesAPIVersion = getTektonPipelinesAPIVersion();

const payload = {
apiVersion: `tekton.dev/${pipelinesAPIVersion}`,
apiVersion: 'tekton.dev/v1',
kind: 'PipelineRun',
metadata: {
name: pipelineRunName,
Expand Down Expand Up @@ -130,13 +127,9 @@ export function getPipelineRunPayload({
};
}
if (serviceAccount) {
if (pipelinesAPIVersion === 'v1') {
payload.spec.taskRunTemplate = {
serviceAccountName: serviceAccount
};
} else {
payload.spec.serviceAccountName = serviceAccount;
}
payload.spec.taskRunTemplate = {
serviceAccountName: serviceAccount
};
}
if (timeoutsFinally || timeoutsPipeline || timeoutsTasks) {
payload.spec.timeouts = {
Expand Down Expand Up @@ -184,8 +177,7 @@ export function generateNewPipelineRunPayload({ pipelineRun, rerun }) {
pipelineRun.metadata;

const payload = deepClone(pipelineRun);
payload.apiVersion =
payload.apiVersion || `tekton.dev/${getTektonPipelinesAPIVersion()}`;
payload.apiVersion = payload.apiVersion || 'tekton.dev/v1';
payload.kind = payload.kind || 'PipelineRun';

function getGenerateName() {
Expand Down
6 changes: 2 additions & 4 deletions src/api/taskRuns.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { deleteRequest, get, patch, post } from './comms';
import {
getQueryParams,
getTektonAPI,
getTektonPipelinesAPIVersion,
removeSystemAnnotations,
removeSystemLabels,
useCollection,
Expand Down Expand Up @@ -90,7 +89,7 @@ export function getTaskRunPayload({
timeout
}) {
const payload = {
apiVersion: `tekton.dev/${getTektonPipelinesAPIVersion()}`,
apiVersion: 'tekton.dev/v1',
kind: 'TaskRun',
metadata: {
name: taskRunName,
Expand Down Expand Up @@ -161,8 +160,7 @@ export function generateNewTaskRunPayload({ taskRun, rerun }) {
taskRun.metadata;

const payload = deepClone(taskRun);
payload.apiVersion =
payload.apiVersion || `tekton.dev/${getTektonPipelinesAPIVersion()}`;
payload.apiVersion = payload.apiVersion || 'tekton.dev/v1';
payload.kind = payload.kind || 'TaskRun';

function getGenerateName() {
Expand Down
14 changes: 1 addition & 13 deletions src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ export function getQueryParams({
return '';
}

export function isPipelinesV1ResourcesEnabled() {
return localStorage.getItem('tkn-pipelines-v1-resources') !== 'false';
}

export function setPipelinesV1ResourcesEnabled(enabled) {
localStorage.setItem('tkn-pipelines-v1-resources', enabled);
}

export function getTektonPipelinesAPIVersion() {
return isPipelinesV1ResourcesEnabled() ? 'v1' : 'v1beta1';
}

// TODO: remove this and replace usage with getKubeAPI directly
export function getTektonAPI(
kind,
Expand All @@ -96,7 +84,7 @@ export function getTektonAPI(
isWebSocket,
name = '',
namespace,
version = getTektonPipelinesAPIVersion()
version = 'v1'
} = {},
queryParams
) {
Expand Down
22 changes: 1 addition & 21 deletions src/containers/Settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import {
import { getTheme, setTheme } from '../../utils';
import {
isLogTimestampsEnabled,
isPipelinesV1ResourcesEnabled,
setLogTimestampsEnabled,
setPipelinesV1ResourcesEnabled
setLogTimestampsEnabled
} from '../../api/utils';

export function Settings() {
Expand Down Expand Up @@ -95,24 +93,6 @@ export function Settings() {
})}
onToggle={checked => setLogTimestampsEnabled(checked)}
/>

<Toggle
defaultToggled={isPipelinesV1ResourcesEnabled()}
id="tkn--pipelines-v1-resources-toggle"
labelText={intl.formatMessage({
id: 'dashboard.pipelines.v1Resources.label',
defaultMessage: 'Use Tekton Pipelines API version v1'
})}
labelA={intl.formatMessage({
id: 'dashboard.toggle.off',
defaultMessage: 'Off'
})}
labelB={intl.formatMessage({
id: 'dashboard.toggle.on',
defaultMessage: 'On'
})}
onToggle={checked => setPipelinesV1ResourcesEnabled(checked)}
/>
</div>
</div>
);
Expand Down
15 changes: 0 additions & 15 deletions src/containers/Settings/Settings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,4 @@ describe('Settings', () => {
fireEvent.click(getByLabelText(/show log timestamps/i));
expect(APIUtils.setLogTimestampsEnabled).toHaveBeenCalledWith(false);
});

it('should render the v1 API settings correctly', () => {
vi.spyOn(APIUtils, 'isPipelinesV1ResourcesEnabled').mockImplementation(
() => true
);
vi.spyOn(APIUtils, 'setPipelinesV1ResourcesEnabled');

const { getByLabelText, getByText } = render(<Settings />);

const apiVersionToggle = getByText(/api version v1/i);
expect(apiVersionToggle).toBeTruthy();
expect(within(apiVersionToggle).getByText('On')).toBeTruthy();
fireEvent.click(getByLabelText(/api version v1/i));
expect(APIUtils.setPipelinesV1ResourcesEnabled).toHaveBeenCalledWith(false);
});
});

0 comments on commit cb2d7ef

Please sign in to comment.