Skip to content

Commit

Permalink
feat: Update clean deploy pipeline creation (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmevladik authored and SergK committed Nov 6, 2024
1 parent f9c578f commit bd9b9e9
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { createCleanPipelineRunInstance } from './index';

describe('testing createCleanPipelineRunInstance', () => {
it('should return valid kube object', () => {
const object = createCleanPipelineRunInstance({
pipelineRunTemplate: {
apiVersion: 'tekton.dev/v1',
kind: 'PipelineRun',
// @ts-ignore
metadata: {
annotations: {
'argocd.argoproj.io/compare-options': 'IgnoreExtraneous',
},
generateName: 'clean-$(tt.params.CDPIPELINE)-$(tt.params.CDSTAGE)-',
labels: {
'app.edp.epam.com/cdpipeline': '$(tt.params.CDPIPELINE)',
'app.edp.epam.com/cdstage': '$(tt.params.CDPIPELINE)-$(tt.params.CDSTAGE)',
'app.edp.epam.com/pipelinetype': 'clean',
},
},
spec: {
params: [
{
name: 'CDSTAGE',
value: '$(tt.params.CDSTAGE)',
},
{
name: 'CDPIPELINE',
value: '$(tt.params.CDPIPELINE)',
},
],
pipelineRef: {
name: 'clean',
},
taskRunTemplate: {
serviceAccountName: 'tekton',
},
timeouts: {
pipeline: '1h00m0s',
},
},
},
CDPipeline: {
apiVersion: 'v2.edp.epam.com/v1',
kind: 'CDPipeline',
// @ts-ignore
metadata: {
name: 'test-pipe',
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',
},
},
stage: {
apiVersion: 'v2.edp.epam.com/v1',
kind: 'Stage',
// @ts-ignore
metadata: {
name: 'test-pipe-sit',
namespace: 'test-namespace',
},
spec: {
cdPipeline: 'test-pipe',
cleanTemplate: 'clean',
clusterName: 'in-cluster',
description: 'sit',
name: 'sit',
namespace: 'test-namespace-test-pipe-sit',
order: 0,
qualityGates: [
{
autotestName: null,
branchName: null,
qualityGateType: 'manual',
stepName: 'sit',
},
],
source: {
// @ts-ignore
library: {
name: 'default',
},
type: 'default',
},
triggerTemplate: 'deploy',
triggerType: 'Manual',
},
},
});

expect(object).toEqual({
apiVersion: 'tekton.dev/v1',
kind: 'PipelineRun',
metadata: {
annotations: { 'argocd.argoproj.io/compare-options': 'IgnoreExtraneous' },
generateName: 'clean-test-pipe-sit-',
labels: {
'app.edp.epam.com/cdpipeline': 'test-pipe',
'app.edp.epam.com/cdstage': 'test-pipe-sit',
'app.edp.epam.com/pipelinetype': 'clean',
},
},
spec: {
params: [
{ name: 'CDSTAGE', value: 'sit' },
{ name: 'CDPIPELINE', value: 'test-pipe' },
],
pipelineRef: { name: 'clean' },
taskRunTemplate: { serviceAccountName: 'tekton' },
timeouts: { pipeline: '1h00m0s' },
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { PIPELINE_TYPES } from '../../../../../../constants/pipelineTypes';
import { CDPipelineKubeObjectInterface } from '../../../../EDP/CDPipeline/types';
import { StageKubeObjectInterface } from '../../../../EDP/Stage/types';
import {
PIPELINE_RUN_LABEL_SELECTOR_CDPIPELINE,
PIPELINE_RUN_LABEL_SELECTOR_CDSTAGE,
PIPELINE_RUN_LABEL_SELECTOR_PIPELINE_TYPE,
} from '../../labels';
import { PipelineRunKubeObjectInterface } from '../../types';

export const createCleanPipelineRunInstance = ({
CDPipeline,
stage,
pipelineRunTemplate,
}: {
CDPipeline: CDPipelineKubeObjectInterface;
stage: StageKubeObjectInterface;
pipelineRunTemplate: PipelineRunKubeObjectInterface;
}): PipelineRunKubeObjectInterface => {
const base = { ...pipelineRunTemplate };

base.metadata.generateName = `clean-${CDPipeline.metadata.name}-${stage.spec.name}-`;

base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CDPIPELINE] = CDPipeline.metadata.name;
base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CDSTAGE] = stage.metadata.name;
base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_PIPELINE_TYPE] = PIPELINE_TYPES.CLEAN;

for (const param of base.spec.params) {
switch (param.name) {
case 'CDSTAGE':
param.value = stage.spec.name;
break;
case 'CDPIPELINE':
param.value = CDPipeline.metadata.name;
break;
case 'KUBECONFIG_SECRET_NAME':
param.value = stage.spec.clusterName;
break;
default:
break;
}
}

return base;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { createDeployPipelineRunInstance } from './index';

describe('testing createDeployPipelineRunInstance', () => {
it('should return valid kube object', () => {
const object = createDeployPipelineRunInstance({
pipelineRunTemplate: {
apiVersion: 'tekton.dev/v1',
kind: 'PipelineRun',
// @ts-ignore
metadata: {
annotations: {
'argocd.argoproj.io/compare-options': 'IgnoreExtraneous',
},
generateName: 'deploy-$(tt.params.CDPIPELINE)-$(tt.params.CDSTAGE)-',
labels: {
'app.edp.epam.com/cdpipeline': '$(tt.params.CDPIPELINE)',
'app.edp.epam.com/cdstage': '$(tt.params.CDPIPELINE)-$(tt.params.CDSTAGE)',
'app.edp.epam.com/pipelinetype': 'deploy',
},
},
spec: {
params: [
{
name: 'APPLICATIONS_PAYLOAD',
value: '$(tt.params.APPLICATIONS_PAYLOAD)',
},
{
name: 'CDSTAGE',
value: '$(tt.params.CDSTAGE)',
},
{
name: 'CDPIPELINE',
value: '$(tt.params.CDPIPELINE)',
},
{
name: 'KUBECONFIG_SECRET_NAME',
value: '$(tt.params.KUBECONFIG_SECRET_NAME)',
},
],
pipelineRef: {
name: 'deploy',
},
taskRunTemplate: {
serviceAccountName: 'tekton',
},
timeouts: {
pipeline: '1h00m0s',
},
},
},
CDPipeline: {
apiVersion: 'v2.edp.epam.com/v1',
kind: 'CDPipeline',
// @ts-ignore
metadata: {
name: 'test-pipe',
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',
},
},
stage: {
apiVersion: 'v2.edp.epam.com/v1',
kind: 'Stage',
// @ts-ignore
metadata: {
name: 'test-pipe-sit',
namespace: 'test-namespace',
},
spec: {
cdPipeline: 'test-pipe',
cleanTemplate: 'clean',
clusterName: 'in-cluster',
description: 'sit',
name: 'sit',
namespace: 'test-namespace-test-pipe-sit',
order: 0,
qualityGates: [
{
autotestName: null,
branchName: null,
qualityGateType: 'manual',
stepName: 'sit',
},
],
source: {
// @ts-ignore
library: {
name: 'default',
},
type: 'default',
},
triggerTemplate: 'deploy',
triggerType: 'Manual',
},
},
appPayload: {
'test-app-1': {
customValues: false,
imageTag: '0.1.0-SNAPSHOT',
},
'test-app-2': {
customValues: false,
imageTag: '0.1.0-SNAPSHOT',
},
},
});

expect(object).toEqual({
apiVersion: 'tekton.dev/v1',
kind: 'PipelineRun',
metadata: {
annotations: { 'argocd.argoproj.io/compare-options': 'IgnoreExtraneous' },
generateName: 'deploy-test-pipe-sit',
labels: {
'app.edp.epam.com/cdpipeline': 'test-pipe',
'app.edp.epam.com/cdstage': 'test-pipe-sit',
'app.edp.epam.com/pipelinetype': 'deploy',
},
},
spec: {
params: [
{
name: 'APPLICATIONS_PAYLOAD',
value:
'{"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: 'KUBECONFIG_SECRET_NAME', value: 'in-cluster' },
],
pipelineRef: { name: 'deploy' },
taskRunTemplate: { serviceAccountName: 'tekton' },
timeouts: { pipeline: '1h00m0s' },
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { PIPELINE_TYPES } from '../../../../../../constants/pipelineTypes';
import { CDPipelineKubeObjectInterface } from '../../../../EDP/CDPipeline/types';
import { StageKubeObjectInterface } from '../../../../EDP/Stage/types';
import {
PIPELINE_RUN_LABEL_SELECTOR_CDPIPELINE,
PIPELINE_RUN_LABEL_SELECTOR_CDSTAGE,
PIPELINE_RUN_LABEL_SELECTOR_PIPELINE_TYPE,
} from '../../labels';
import { PipelineRunKubeObjectInterface } from '../../types';

export const createDeployPipelineRunInstance = ({
CDPipeline,
stage,
pipelineRunTemplate,
appPayload,
}: {
CDPipeline: CDPipelineKubeObjectInterface;
stage: StageKubeObjectInterface;
pipelineRunTemplate: PipelineRunKubeObjectInterface;
appPayload: Record<
string,
{
imageTag: string;
customValues: boolean;
}
>;
}): PipelineRunKubeObjectInterface => {
const base = { ...pipelineRunTemplate };

base.metadata.generateName = `deploy-${CDPipeline.metadata.name}-${stage.spec.name}`;

base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CDPIPELINE] = CDPipeline.metadata.name;
base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_CDSTAGE] = stage.metadata.name;
base.metadata.labels[PIPELINE_RUN_LABEL_SELECTOR_PIPELINE_TYPE] = PIPELINE_TYPES.DEPLOY;

for (const param of base.spec.params) {
switch (param.name) {
case 'CDSTAGE':
param.value = stage.spec.name;
break;
case 'CDPIPELINE':
param.value = CDPipeline.metadata.name;
break;
case 'APPLICATIONS_PAYLOAD':
param.value = JSON.stringify(appPayload);
break;
case 'KUBECONFIG_SECRET_NAME':
param.value = stage.spec.clusterName;
break;
default:
break;
}
}

return base;
};
Loading

0 comments on commit bd9b9e9

Please sign in to comment.