-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update clean deploy pipeline creation (#463)
- Loading branch information
1 parent
f9c578f
commit bd9b9e9
Showing
5 changed files
with
389 additions
and
116 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }, | ||
}, | ||
}); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
src/k8s/groups/Tekton/PipelineRun/utils/createCleanPipelineRunInstance/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
143 changes: 143 additions & 0 deletions
143
src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }, | ||
}, | ||
}); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
src/k8s/groups/Tekton/PipelineRun/utils/createDeployPipelineRunInstance/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
Oops, something went wrong.