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

feat: Update pipelinerun naming #545

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
},
},
Expand All @@ -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' },
Expand Down Expand Up @@ -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: [
Expand All @@ -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' },
Expand Down Expand Up @@ -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: [
Expand All @@ -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' },
Expand Down Expand Up @@ -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: [
Expand All @@ -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' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,32 @@ 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: {
applications: ['test-app-1', 'test-app-2'],
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: {
apiVersion: 'v2.edp.epam.com/v1',
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: [
{
Expand Down Expand Up @@ -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' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,32 @@ 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: {
applications: ['test-app-1', 'test-app-2'],
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: {
apiVersion: 'v2.edp.epam.com/v1',
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: [
{
Expand Down Expand Up @@ -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',
},
},
Expand All @@ -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' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/')) {
Expand All @@ -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 = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export const GitUrlPath = () => {
<FormTextField
{...register(CODEBASE_FORM_NAMES.gitUrlPath.name, {
required: 'Enter relative path to repository.',
minLength: {
value: 3,
message: 'Repository name has to be at least 3 characters long.',
},
validate: (value) => validateField(value, validationRules.GIT_URL_PATH),
})}
label={'Repository name'}
Expand Down
Loading