Skip to content

Commit

Permalink
Add toggle to settings UI to opt-in to Pipelines v1 resources
Browse files Browse the repository at this point in the history
Add a toggle to the settings page allowing users to opt-in to requesting
and managing v1 versions of the Pipelines CRDs: `Pipeline`, `PipelineRun`,
`Task`, and `TaskRun`. This updates the API endpoints to use the
corresponding version.

The toggle is off by default and will be included in the next release.
Following that it will be on by default for one release, then removed.
  • Loading branch information
AlanGreene committed Jan 4, 2023
1 parent 320f319 commit 9dbc8de
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/api/clusterTasks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2021 The Tekton Authors
Copyright 2019-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,7 +22,7 @@ import {
function getClusterTasksAPI({ filters, isWebSocket, name }) {
return getTektonAPI(
'clustertasks',
{ isWebSocket },
{ isWebSocket, version: 'v1beta1' },
getQueryParams({ filters, name })
);
}
Expand All @@ -33,12 +33,12 @@ export function getClusterTasks({ filters = [] } = {}) {
}

export function getClusterTask({ name }) {
const uri = getTektonAPI('clustertasks', { name });
const uri = getTektonAPI('clustertasks', { name, version: 'v1beta1' });
return get(uri);
}

export function deleteClusterTask({ name }) {
const uri = getTektonAPI('clustertasks', { name });
const uri = getTektonAPI('clustertasks', { name, version: 'v1beta1' });
return deleteRequest(uri);
}

Expand Down
8 changes: 5 additions & 3 deletions src/api/pipelineRuns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2022 The Tekton Authors
Copyright 2019-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 @@ -18,6 +18,7 @@ import { deleteRequest, get, patch, post } from './comms';
import {
getQueryParams,
getTektonAPI,
getTektonPipelinesAPIVersion,
useCollection,
useResource
} from './utils';
Expand Down Expand Up @@ -95,7 +96,7 @@ export function getPipelineRunPayload({
timeoutsTasks
}) {
const payload = {
apiVersion: 'tekton.dev/v1beta1',
apiVersion: `tekton.dev/${getTektonPipelinesAPIVersion()}`,
kind: 'PipelineRun',
metadata: {
name: pipelineRunName,
Expand Down Expand Up @@ -184,7 +185,8 @@ export function rerunPipelineRun(pipelineRun) {
const { annotations, labels, name, namespace } = pipelineRun.metadata;

const payload = deepClone(pipelineRun);
payload.apiVersion = payload.apiVersion || 'tekton.dev/v1beta1';
payload.apiVersion =
payload.apiVersion || `tekton.dev/${getTektonPipelinesAPIVersion()}`;
payload.kind = payload.kind || 'PipelineRun';
payload.metadata = {
annotations,
Expand Down
8 changes: 5 additions & 3 deletions src/api/taskRuns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2022 The Tekton Authors
Copyright 2019-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 @@ -18,6 +18,7 @@ import { deleteRequest, get, patch, post } from './comms';
import {
getQueryParams,
getTektonAPI,
getTektonPipelinesAPIVersion,
useCollection,
useResource
} from './utils';
Expand Down Expand Up @@ -88,7 +89,7 @@ export function createTaskRun({
timeout
}) {
const payload = {
apiVersion: 'tekton.dev/v1beta1',
apiVersion: `tekton.dev/${getTektonPipelinesAPIVersion()}`,
kind: 'TaskRun',
metadata: {
name: taskRunName,
Expand Down Expand Up @@ -146,7 +147,8 @@ export function rerunTaskRun(taskRun) {
const { annotations, labels, name, namespace } = taskRun.metadata;

const payload = deepClone(taskRun);
payload.apiVersion = payload.apiVersion || 'tekton.dev/v1beta1';
payload.apiVersion =
payload.apiVersion || `tekton.dev/${getTektonPipelinesAPIVersion()}`;
payload.kind = payload.kind || 'TaskRun';
payload.metadata = {
annotations,
Expand Down
16 changes: 14 additions & 2 deletions src/api/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2022 The Tekton Authors
Copyright 2019-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 Down Expand Up @@ -97,14 +97,26 @@ export function getQueryParams({
return '';
}

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

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

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

export function getTektonAPI(
type,
{
group = tektonAPIGroup,
isWebSocket,
name = '',
namespace,
version = 'v1beta1'
version = getTektonPipelinesAPIVersion()
} = {},
queryParams
) {
Expand Down
24 changes: 22 additions & 2 deletions src/containers/Settings/Settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021-2022 The Tekton Authors
Copyright 2021-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 @@ -24,7 +24,9 @@ import {
import { getTheme, setTheme } from '../../utils';
import {
isLogTimestampsEnabled,
setLogTimestampsEnabled
isPipelinesV1ResourcesEnabled,
setLogTimestampsEnabled,
setPipelinesV1ResourcesEnabled
} from '../../api/utils';

export function Settings() {
Expand Down Expand Up @@ -94,6 +96,24 @@ 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
10 changes: 9 additions & 1 deletion src/containers/Settings/Settings.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Tekton Authors
Copyright 2021-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 @@ -17,6 +17,10 @@ limitations under the License.
margin-bottom: 2rem;
max-width: 400px;

legend {
margin-bottom: 1rem;
}

.bx--tile {
display: flex;
align-items: center;
Expand All @@ -40,5 +44,9 @@ limitations under the License.
margin-bottom: 0.5rem;
}
}

.bx--form-item + .bx--form-item {
margin-top: 2rem;
}
}
}
1 change: 1 addition & 0 deletions src/nls/messages_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "Schritt fehlgeschlagen",
"dashboard.pipelineRuns.error": "Fehler beim Laden von PipelineRuns",
"dashboard.pipelines.errorLoading": "",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "",
"dashboard.pipelinesDropdown.label": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "Step failed",
"dashboard.pipelineRuns.error": "Error loading PipelineRuns",
"dashboard.pipelines.errorLoading": "Error loading Pipelines",
"dashboard.pipelines.v1Resources.label": "Use Tekton Pipelines API version v1",
"dashboard.pipelinesDropdown.empty.allNamespaces": "No Pipelines found",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "No Pipelines found in the ''{namespace}'' namespace",
"dashboard.pipelinesDropdown.label": "Select Pipeline",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "Paso fallido",
"dashboard.pipelineRuns.error": "Error al cargar PipelineRuns",
"dashboard.pipelines.errorLoading": "",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "",
"dashboard.pipelinesDropdown.label": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "Echec de l'étape",
"dashboard.pipelineRuns.error": "Une erreur s'est produite lors du chargement des ressources PipelineRun",
"dashboard.pipelines.errorLoading": "",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "",
"dashboard.pipelinesDropdown.label": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "Passo non riuscito",
"dashboard.pipelineRuns.error": "Errore nel caricamento delle esecuzioni pipeline",
"dashboard.pipelines.errorLoading": "",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "",
"dashboard.pipelinesDropdown.label": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "ステップが失敗しました",
"dashboard.pipelineRuns.error": "PipelineRunのロード中にエラーが発生しました",
"dashboard.pipelines.errorLoading": "Pipelineのロード中にエラーが発生しました",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "Pipelineが見つかりません",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "''{namespace}'' NamespaceにPipelineが見つかりません",
"dashboard.pipelinesDropdown.label": "Pipelineを選択",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "단계 실패",
"dashboard.pipelineRuns.error": "PipelineRun 로드 중 오류 발생",
"dashboard.pipelines.errorLoading": "",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "",
"dashboard.pipelinesDropdown.label": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "Etapa com falha",
"dashboard.pipelineRuns.error": "Erro ao carregar os PipelineRuns",
"dashboard.pipelines.errorLoading": "",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "",
"dashboard.pipelinesDropdown.label": "",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "步骤失败",
"dashboard.pipelineRuns.error": "加载 PipelineRun 时出错",
"dashboard.pipelines.errorLoading": "加载 Pipelines 时出错",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "未找到 Pipelines",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "在Namespace ''{namespace}'' 中未找到 Pipelines",
"dashboard.pipelinesDropdown.label": "选择 Pipeline",
Expand Down
1 change: 1 addition & 0 deletions src/nls/messages_zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"dashboard.pipelineRun.stepFailed": "步驟失敗",
"dashboard.pipelineRuns.error": "載入 PipelineRuns 時發生錯誤",
"dashboard.pipelines.errorLoading": "",
"dashboard.pipelines.v1Resources.label": "",
"dashboard.pipelinesDropdown.empty.allNamespaces": "",
"dashboard.pipelinesDropdown.empty.selectedNamespace": "",
"dashboard.pipelinesDropdown.label": "",
Expand Down

0 comments on commit 9dbc8de

Please sign in to comment.