From 6558d2ffc7107b3e6b0a96d497877374776c750e Mon Sep 17 00:00:00 2001 From: Vladyslav Palyvoda Date: Fri, 10 Jan 2025 15:36:34 +0200 Subject: [PATCH] feat: Update pipelinerun naming (#544) --- .../index.test.ts | 30 +++++++++++-------- .../createBuildPipelineRunInstance/index.ts | 11 ++++--- .../index.test.ts | 18 +++++------ .../createCleanPipelineRunInstance/index.ts | 11 +++++-- .../index.test.ts | 18 +++++------ .../createDeployPipelineRunInstance/index.ts | 11 +++++-- .../createRerunPipelineRunInstance/index.ts | 22 ++++++++------ .../components/fields/GitUrlPath/index.tsx | 4 +++ 8 files changed, 75 insertions(+), 50 deletions(-) diff --git a/src/k8s/groups/Tekton/PipelineRun/utils/createBuildPipelineRunInstance/index.test.ts b/src/k8s/groups/Tekton/PipelineRun/utils/createBuildPipelineRunInstance/index.test.ts index 49575a6d..4d02255e 100644 --- a/src/k8s/groups/Tekton/PipelineRun/utils/createBuildPipelineRunInstance/index.test.ts +++ b/src/k8s/groups/Tekton/PipelineRun/utils/createBuildPipelineRunInstance/index.test.ts @@ -28,7 +28,7 @@ const mockCodebase = { const mockCodebaseBranch = { metadata: { - name: 'test-codebase-name-test-codebase-branch-name', + name: 'test-codebase-name-test-codebase-branch-name-very-long-long-name', }, spec: { branchName: 'test-codebase-branch-name', @@ -156,10 +156,11 @@ describe('testing createBuildPipelineRunInstance', () => { kind: 'PipelineRun', metadata: { annotations: { 'argocd.argoproj.io/compare-options': 'IgnoreExtraneous' }, - name: `test-codebase-name-test-codebase-branch-name-build-${MOCKED_UUID}`, + name: `build-test-codebase-name-test-codebase-branch-name-very-lo-${MOCKED_UUID}`, labels: { 'app.edp.epam.com/codebase': 'test-codebase-name', - 'app.edp.epam.com/codebasebranch': 'test-codebase-name-test-codebase-branch-name', + 'app.edp.epam.com/codebasebranch': + 'test-codebase-name-test-codebase-branch-name-very-long-long-name', 'app.edp.epam.com/pipelinetype': 'build', }, }, @@ -176,7 +177,7 @@ describe('testing createBuildPipelineRunInstance', () => { { name: 'CODEBASE_NAME', value: 'test-codebase-name' }, { name: 'CODEBASEBRANCH_NAME', - value: 'test-codebase-name-test-codebase-branch-name', + value: 'test-codebase-name-test-codebase-branch-name-very-long-long-name', }, { name: 'changeNumber', value: '1' }, { name: 'patchsetNumber', value: '1' }, @@ -231,10 +232,11 @@ describe('testing createBuildPipelineRunInstance', () => { annotations: { 'argocd.argoproj.io/compare-options': 'IgnoreExtraneous' }, labels: { 'app.edp.epam.com/codebase': 'test-codebase-name', - 'app.edp.epam.com/codebasebranch': 'test-codebase-name-test-codebase-branch-name', + 'app.edp.epam.com/codebasebranch': + 'test-codebase-name-test-codebase-branch-name-very-long-long-name', 'app.edp.epam.com/pipelinetype': 'build', }, - name: 'test-codebase-name-test-codebase-branch-name-build-1234', + name: `build-test-codebase-name-test-codebase-branch-name-very-lo-${MOCKED_UUID}`, }, spec: { params: [ @@ -249,7 +251,7 @@ describe('testing createBuildPipelineRunInstance', () => { { name: 'CODEBASE_NAME', value: 'test-codebase-name' }, { name: 'CODEBASEBRANCH_NAME', - value: 'test-codebase-name-test-codebase-branch-name', + value: 'test-codebase-name-test-codebase-branch-name-very-long-long-name', }, { name: 'changeNumber', value: '1' }, { name: 'patchsetNumber', value: '1' }, @@ -304,10 +306,11 @@ describe('testing createBuildPipelineRunInstance', () => { annotations: { 'argocd.argoproj.io/compare-options': 'IgnoreExtraneous' }, labels: { 'app.edp.epam.com/codebase': 'test-codebase-name', - 'app.edp.epam.com/codebasebranch': 'test-codebase-name-test-codebase-branch-name', + 'app.edp.epam.com/codebasebranch': + 'test-codebase-name-test-codebase-branch-name-very-long-long-name', 'app.edp.epam.com/pipelinetype': 'build', }, - name: 'test-codebase-name-test-codebase-branch-name-build-1234', + name: `build-test-codebase-name-test-codebase-branch-name-very-lo-${MOCKED_UUID}`, }, spec: { params: [ @@ -322,7 +325,7 @@ describe('testing createBuildPipelineRunInstance', () => { { name: 'CODEBASE_NAME', value: 'test-codebase-name' }, { name: 'CODEBASEBRANCH_NAME', - value: 'test-codebase-name-test-codebase-branch-name', + value: 'test-codebase-name-test-codebase-branch-name-very-long-long-name', }, { name: 'changeNumber', value: '1' }, { name: 'patchsetNumber', value: '1' }, @@ -377,10 +380,11 @@ describe('testing createBuildPipelineRunInstance', () => { annotations: { 'argocd.argoproj.io/compare-options': 'IgnoreExtraneous' }, labels: { 'app.edp.epam.com/codebase': 'test-codebase-name', - 'app.edp.epam.com/codebasebranch': 'test-codebase-name-test-codebase-branch-name', + 'app.edp.epam.com/codebasebranch': + 'test-codebase-name-test-codebase-branch-name-very-long-long-name', 'app.edp.epam.com/pipelinetype': 'build', }, - name: 'test-codebase-name-test-codebase-branch-name-build-1234', + name: `build-test-codebase-name-test-codebase-branch-name-very-lo-${MOCKED_UUID}`, }, spec: { params: [ @@ -395,7 +399,7 @@ describe('testing createBuildPipelineRunInstance', () => { { name: 'CODEBASE_NAME', value: 'test-codebase-name' }, { name: 'CODEBASEBRANCH_NAME', - value: 'test-codebase-name-test-codebase-branch-name', + value: 'test-codebase-name-test-codebase-branch-name-very-long-long-name', }, { name: 'changeNumber', value: '1' }, { name: 'patchsetNumber', value: '1' }, diff --git a/src/k8s/groups/Tekton/PipelineRun/utils/createBuildPipelineRunInstance/index.ts b/src/k8s/groups/Tekton/PipelineRun/utils/createBuildPipelineRunInstance/index.ts index 60e41dcc..e7a12593 100644 --- a/src/k8s/groups/Tekton/PipelineRun/utils/createBuildPipelineRunInstance/index.ts +++ b/src/k8s/groups/Tekton/PipelineRun/utils/createBuildPipelineRunInstance/index.ts @@ -44,16 +44,19 @@ export const createBuildPipelineRunInstance = ({ const base = cloneDeep(pipelineRunTemplate); - const pipelineRunPostfix = `-build-${createRandomString(4)}`; + const namePrefix = `build-`; + const namePostfix = `-${createRandomString(4)}`; - const codebaseBranchNameTruncated = truncateName( + const truncatedName = truncateName( codebaseBranchMetadataName, - pipelineRunPostfix.length + namePrefix.length + namePostfix.length ); + const fullPipelineRunName = `${namePrefix}${truncatedName}${namePostfix}`; + delete base.metadata.generateName; - base.metadata.name = `${codebaseBranchNameTruncated}${pipelineRunPostfix}`; + base.metadata.name = fullPipelineRunName; base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CODEBASE] = codebaseName; base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CODEBASE_BRANCH] = codebaseBranchMetadataName; diff --git a/src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.test.ts b/src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.test.ts index a6eae461..77311ce3 100644 --- a/src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.test.ts +++ b/src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.test.ts @@ -53,7 +53,7 @@ describe('testing createCleanPipelineRunInstance', () => { kind: 'CDPipeline', // @ts-ignore metadata: { - name: 'test-pipe', + name: 'test-pipe-very-long-long-long-long-long-long-name', namespace: 'test-namespace', }, spec: { @@ -61,7 +61,7 @@ describe('testing createCleanPipelineRunInstance', () => { applicationsToPromote: ['test-app-1', 'test-app-2'], deploymentType: 'container', inputDockerStreams: ['test-app-1-main', 'test-app-2-main'], - name: 'test-pipe', + name: 'test-pipe-very-long-long-long-long-long-long-name', }, }, stage: { @@ -69,16 +69,16 @@ describe('testing createCleanPipelineRunInstance', () => { kind: 'Stage', // @ts-ignore metadata: { - name: 'test-pipe-sit', + name: 'test-pipe-very-long-long-long-long-long-long-name-sit', namespace: 'test-namespace', }, spec: { - cdPipeline: 'test-pipe', + cdPipeline: 'test-pipe-very-long-long-long-long-long-long-name', cleanTemplate: 'clean', clusterName: 'in-cluster', description: 'sit', name: 'sit', - namespace: 'test-namespace-test-pipe-sit', + namespace: 'test-namespace-test-pipe-very-long-long-long-long-long-long-name-sit', order: 0, qualityGates: [ { @@ -106,17 +106,17 @@ describe('testing createCleanPipelineRunInstance', () => { kind: 'PipelineRun', metadata: { annotations: { 'argocd.argoproj.io/compare-options': 'IgnoreExtraneous' }, - name: `clean-test-pipe-sit-${MOCKED_UUID}`, + name: `clean-test-pipe-very-long-long-long-long-long-long-name-si-${MOCKED_UUID}`, labels: { - 'app.edp.epam.com/cdpipeline': 'test-pipe', - 'app.edp.epam.com/cdstage': 'test-pipe-sit', + 'app.edp.epam.com/cdpipeline': 'test-pipe-very-long-long-long-long-long-long-name', + 'app.edp.epam.com/cdstage': 'test-pipe-very-long-long-long-long-long-long-name-sit', 'app.edp.epam.com/pipelinetype': 'clean', }, }, spec: { params: [ { name: 'CDSTAGE', value: 'sit' }, - { name: 'CDPIPELINE', value: 'test-pipe' }, + { name: 'CDPIPELINE', value: 'test-pipe-very-long-long-long-long-long-long-name' }, ], pipelineRef: { name: 'clean' }, taskRunTemplate: { serviceAccountName: 'tekton' }, diff --git a/src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.ts b/src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.ts index f2156606..d37b0ae9 100644 --- a/src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.ts +++ b/src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.ts @@ -22,14 +22,19 @@ export const createCleanPipelineRunInstance = ({ }): PipelineRunKubeObjectInterface => { const base = cloneDeep(pipelineRunTemplate); - const generateName = `clean-${CDPipeline.metadata.name}-${stage.spec.name}`; + const namePrefix = `clean-`; const namePostfix = `-${createRandomString(4)}`; - const truncatedName = truncateName(generateName, namePostfix.length); + const truncatedName = truncateName( + `${CDPipeline.metadata.name}-${stage.spec.name}`, + namePrefix.length + namePostfix.length + ); + + const fullPipelineRunName = `${namePrefix}${truncatedName}${namePostfix}`; delete base.metadata.generateName; - base.metadata.name = `${truncatedName}${namePostfix}`; + base.metadata.name = fullPipelineRunName; base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CDPIPELINE] = CDPipeline.metadata.name; base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CDSTAGE] = stage.metadata.name; diff --git a/src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.test.ts b/src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.test.ts index c3af8da4..f5b8da7b 100644 --- a/src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.test.ts +++ b/src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.test.ts @@ -60,7 +60,7 @@ describe('testing createDeployPipelineRunInstance', () => { kind: 'CDPipeline', // @ts-ignore metadata: { - name: 'test-pipe', + name: 'test-pipe-very-long-long-long-long-long-long-name', namespace: 'test-namespace', }, spec: { @@ -68,7 +68,7 @@ describe('testing createDeployPipelineRunInstance', () => { applicationsToPromote: ['test-app-1', 'test-app-2'], deploymentType: 'container', inputDockerStreams: ['test-app-1-main', 'test-app-2-main'], - name: 'test-pipe', + name: 'test-pipe-very-long-long-long-long-long-long-name', }, }, stage: { @@ -76,16 +76,16 @@ describe('testing createDeployPipelineRunInstance', () => { kind: 'Stage', // @ts-ignore metadata: { - name: 'test-pipe-sit', + name: 'test-pipe-very-long-long-long-long-long-long-name-sit', namespace: 'test-namespace', }, spec: { - cdPipeline: 'test-pipe', + cdPipeline: 'test-pipe-very-long-long-long-long-long-long-name', cleanTemplate: 'clean', clusterName: 'in-cluster', description: 'sit', name: 'sit', - namespace: 'test-namespace-test-pipe-sit', + namespace: 'test-namespace-test-pipe-very-long-long-long-long-long-long-name-sit', order: 0, qualityGates: [ { @@ -123,10 +123,10 @@ describe('testing createDeployPipelineRunInstance', () => { kind: 'PipelineRun', metadata: { annotations: { 'argocd.argoproj.io/compare-options': 'IgnoreExtraneous' }, - name: `deploy-test-pipe-sit-${MOCKED_UUID}`, + name: `deploy-test-pipe-very-long-long-long-long-long-long-name-s-${MOCKED_UUID}`, labels: { - 'app.edp.epam.com/cdpipeline': 'test-pipe', - 'app.edp.epam.com/cdstage': 'test-pipe-sit', + 'app.edp.epam.com/cdpipeline': 'test-pipe-very-long-long-long-long-long-long-name', + 'app.edp.epam.com/cdstage': 'test-pipe-very-long-long-long-long-long-long-name-sit', 'app.edp.epam.com/pipelinetype': 'deploy', }, }, @@ -138,7 +138,7 @@ describe('testing createDeployPipelineRunInstance', () => { '{"test-app-1":{"customValues":false,"imageTag":"0.1.0-SNAPSHOT"},"test-app-2":{"customValues":false,"imageTag":"0.1.0-SNAPSHOT"}}', }, { name: 'CDSTAGE', value: 'sit' }, - { name: 'CDPIPELINE', value: 'test-pipe' }, + { name: 'CDPIPELINE', value: 'test-pipe-very-long-long-long-long-long-long-name' }, { name: 'KUBECONFIG_SECRET_NAME', value: 'in-cluster' }, ], pipelineRef: { name: 'deploy' }, diff --git a/src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.ts b/src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.ts index 7bd8b4e7..356e4d0d 100644 --- a/src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.ts +++ b/src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.ts @@ -30,14 +30,19 @@ export const createDeployPipelineRunInstance = ({ }): PipelineRunKubeObjectInterface => { const base = cloneDeep(pipelineRunTemplate); - const generateName = `deploy-${CDPipeline.metadata.name}-${stage.spec.name}`; + const namePrefix = `deploy-`; const namePostfix = `-${createRandomString(4)}`; - const truncatedName = truncateName(generateName, namePostfix.length); + const truncatedName = truncateName( + `${CDPipeline.metadata.name}-${stage.spec.name}`, + namePrefix.length + namePostfix.length + ); + + const fullPipelineRunName = `${namePrefix}${truncatedName}${namePostfix}`; delete base.metadata.generateName; - base.metadata.name = `${truncatedName}${namePostfix}`; + base.metadata.name = fullPipelineRunName; base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CDPIPELINE] = CDPipeline.metadata.name; base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CDSTAGE] = stage.metadata.name; diff --git a/src/k8s/groups/Tekton/PipelineRun/utils/createRerunPipelineRunInstance/index.ts b/src/k8s/groups/Tekton/PipelineRun/utils/createRerunPipelineRunInstance/index.ts index aca98f55..517ebf68 100644 --- a/src/k8s/groups/Tekton/PipelineRun/utils/createRerunPipelineRunInstance/index.ts +++ b/src/k8s/groups/Tekton/PipelineRun/utils/createRerunPipelineRunInstance/index.ts @@ -4,8 +4,6 @@ import { createRandomString } from '../../../../../../utils/createRandomString'; import { truncateName } from '../../../../../../utils/truncateName'; import { PipelineRunKubeObjectInterface } from '../../types'; -const rerunIdentifier = '-r-'; - const removeSystemLabels = (resource: KubeObjectInterface) => { Object.keys(resource.metadata.labels).forEach((label) => { if (label.startsWith('tekton.dev/')) { @@ -14,15 +12,21 @@ const removeSystemLabels = (resource: KubeObjectInterface) => { }); }; -const getNamePrefixForRerun = (name: string) => { - let root = name; - if (name.includes(rerunIdentifier)) { - root = name.substring(0, name.lastIndexOf(rerunIdentifier)); +const getNamePrefixForRerun = (_name: string) => { + let name = _name; + const rerunIdentifier = 'r-'; + + if (_name.includes(rerunIdentifier)) { + name = _name.substring(0, _name.lastIndexOf(rerunIdentifier)); } - const pipelineRunPostfix = `${rerunIdentifier}${createRandomString()}`; - const truncatedName = truncateName(root, pipelineRunPostfix.length); - return `${truncatedName}${pipelineRunPostfix}`; + const namePostfix = `-${createRandomString(4)}`; + + const truncatedName = truncateName(name, rerunIdentifier.length + namePostfix.length); + + const fullPipelineRunName = `${rerunIdentifier}${truncatedName}${namePostfix}`; + + return fullPipelineRunName; }; const generateNewPipelineRunPayload = ({ diff --git a/src/widgets/dialogs/ManageCodebase/components/fields/GitUrlPath/index.tsx b/src/widgets/dialogs/ManageCodebase/components/fields/GitUrlPath/index.tsx index bbe1bd9d..e0623b17 100644 --- a/src/widgets/dialogs/ManageCodebase/components/fields/GitUrlPath/index.tsx +++ b/src/widgets/dialogs/ManageCodebase/components/fields/GitUrlPath/index.tsx @@ -38,6 +38,10 @@ export const GitUrlPath = () => { validateField(value, validationRules.GIT_URL_PATH), })} label={'Repository name'}