Skip to content

Commit c3258ae

Browse files
SAAS-7098 (#490)
* renamed venona to runner * moved test pipelines to runner project * now the runtime of the test pipeline will change with every init and migration
1 parent 971d932 commit c3258ae

File tree

7 files changed

+82
-25
lines changed

7 files changed

+82
-25
lines changed

lib/interface/cli/commands/hybrid/helper.js

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const INSTALLATION_DEFAULTS = {
1616
MAKE_DEFAULT_RE: false,
1717
RUN_DEMO_PIPELINE: true,
1818
DEMO_PIPELINE_NAME: 'Codefresh-Runner Demo',
19+
PROJECT_NAME: 'Runner',
1920
CF_CONTEXT_NAME: 'cf-runner',
2021
};
2122

@@ -24,10 +25,40 @@ const DefaultLogFormatter = 'plain';
2425
const defaultOpenIssueMessage = 'If you had any issues with this process please report them at: ' +
2526
`${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
2627

27-
async function createTestPipeline(runtimeName, pipelineName, pipelineCommands, progressReporter) {
28+
async function _createRunnerProjectIfNotExists() {
29+
const [err, projectExists] = await to(sdk.projects.getByName({ name: INSTALLATION_DEFAULTS.PROJECT_NAME }));
30+
if (_.get(err, 'message', '').includes('not found') || !projectExists) {
31+
await sdk.projects.create({ projectName: INSTALLATION_DEFAULTS.PROJECT_NAME });
32+
console.log(`Project "${colors.cyan(INSTALLATION_DEFAULTS.PROJECT_NAME)}" was created`);
33+
} else {
34+
console.log(`Project "${colors.cyan(INSTALLATION_DEFAULTS.PROJECT_NAME)}" already exists`);
35+
}
36+
}
37+
38+
async function getTestPipelineLink(pipelineName, pipeline) {
2839
const url = _.get(sdk, 'config.context.url', 'https://g.codefresh.io');
29-
console.log(`Creating test pipeline with the name: "${colors.cyan(pipelineName)}"`);
30-
const pipeline = await sdk.pipelines.create({ metadata: { name: pipelineName } });
40+
let _pipeline = pipeline;
41+
if (!_pipeline) {
42+
const pipelines = await sdk.pipelines.list({ id: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${pipelineName}` });
43+
if (_.get(pipelines, 'docs.length')) {
44+
[_pipeline] = pipelines.docs;
45+
}
46+
}
47+
48+
if (_pipeline) {
49+
const cleanPipelineName = _pipeline.metadata.name.replace(`${INSTALLATION_DEFAULTS.PROJECT_NAME}/`, ''); // remove the project prefix
50+
return `${url}/pipelines/edit/workflow?id=${_pipeline.metadata.id}&pipeline=${encodeURI(cleanPipelineName)}` +
51+
`&projects=${encodeURI(INSTALLATION_DEFAULTS.PROJECT_NAME)}`;
52+
}
53+
54+
return '';
55+
}
56+
57+
async function createTestPipeline(runtimeName, pipelineName, pipelineCommands, progressReporter) {
58+
await _createRunnerProjectIfNotExists();
59+
console.log(`Creating test pipeline with the name: "${colors.cyan(pipelineName)}" ` +
60+
`in project "${colors.cyan(INSTALLATION_DEFAULTS.PROJECT_NAME)}"`);
61+
const pipeline = await sdk.pipelines.create({ metadata: { name: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${pipelineName}` } });
3162

3263
pipeline.spec.runtimeEnvironment = {
3364
name: runtimeName,
@@ -42,7 +73,7 @@ async function createTestPipeline(runtimeName, pipelineName, pipelineCommands, p
4273
};
4374

4475
await sdk.pipelines.replace(
45-
{ name: pipelineName },
76+
{ name: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${pipelineName}` },
4677
{
4778
kind: pipeline.kind,
4879
spec: pipeline.spec,
@@ -55,28 +86,17 @@ async function createTestPipeline(runtimeName, pipelineName, pipelineCommands, p
5586
await to(progressReporter.report(PIPELINE_CREATED, STATUSES.SUCCESS));
5687
}
5788

58-
const pipelineLink = `${url}/pipelines/edit/workflow?id=${pipeline.metadata.id}&pipeline=${encodeURI(pipeline.metadata.name)}`;
89+
const pipelineLink = await getTestPipelineLink(undefined, pipeline);
5990
console.log(`Created test pipeline with the name "${colors.cyan(pipelineName)}". Watch it here: ${colors.blue(pipelineLink)}`);
6091

6192
return pipeline;
6293
}
6394

64-
async function getTestPipelineLink(pipelineName) {
65-
const url = _.get(sdk, 'config.context.url', 'https://g.codefresh.io');
66-
const pipelines = await sdk.pipelines.list({ id: pipelineName });
67-
if (_.get(pipelines, 'docs.length')) {
68-
const pipeline = pipelines.docs[0];
69-
return `${url}/pipelines/edit/workflow?id=${pipeline.metadata.id}&pipeline=${encodeURI(pipeline.metadata.name)}`;
70-
}
71-
return '';
72-
}
73-
7495
async function getTestPipeline(pipelineName) {
75-
const url = _.get(sdk, 'config.context.url', 'https://g.codefresh.io');
76-
const pipelines = await sdk.pipelines.list({ id: pipelineName });
96+
const pipelines = await sdk.pipelines.list({ id: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${pipelineName}` });
7797
if (_.get(pipelines, 'docs.length')) {
7898
const pipeline = pipelines.docs[0];
79-
const pipelineLink = `${url}/pipelines/edit/workflow?id=${pipeline.metadata.id}&pipeline=${encodeURI(pipeline.metadata.name)}`;
99+
const pipelineLink = await getTestPipelineLink(undefined, pipeline);
80100
console.log(`Test pipeline with the name: "${colors.cyan(pipelineName)}" already exists.` +
81101
` Watch it here: ${colors.blue(pipelineLink)}`);
82102
return pipeline;
@@ -86,6 +106,24 @@ async function getTestPipeline(pipelineName) {
86106
return null;
87107
}
88108

109+
async function updateTestPipelineRuntime(pipeline, runtimeName) {
110+
// update pipeline runtime
111+
const _pipeline = pipeline;
112+
_pipeline.spec.runtimeEnvironment = {
113+
name: runtimeName,
114+
};
115+
116+
await sdk.pipelines.replace(
117+
{ name: _pipeline.metadata.name },
118+
{
119+
kind: _pipeline.kind,
120+
spec: _pipeline.spec,
121+
metadata: _pipeline.metadata,
122+
version: _pipeline.version,
123+
},
124+
);
125+
}
126+
89127
async function executeTestPipeline(runtimeName, pipeline, progressReporter) {
90128
const url = _.get(sdk, 'config.context.url', 'https://g.codefresh.io');
91129
const pipelineName = _.get(pipeline, 'metadata.name');
@@ -226,6 +264,7 @@ module.exports = {
226264
getRuntimeVersion,
227265
createTestPipeline,
228266
getTestPipeline,
267+
updateTestPipelineRuntime,
229268
executeTestPipeline,
230269
createProgressBar,
231270
getTestPipelineLink,

lib/interface/cli/commands/hybrid/init.cmd.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {
2121
getTestPipeline,
2222
createTestPipeline,
2323
executeTestPipeline,
24+
updateTestPipelineRuntime,
2425
INSTALLATION_DEFAULTS,
2526
} = require('./helper');
2627
const {
@@ -44,6 +45,12 @@ async function createAndRunTestPipeline(runtimeName, errHandler, progressReporte
4445
));
4546
await errHandler(createPipelineErr, 'Failed to create test pipeline', progressReporter, installationProgress.events.PIPELINE_CREATED);
4647
testPipeline = _testPipeline;
48+
} else {
49+
const [updatePipelineErr] = await to(updateTestPipelineRuntime(testPipeline, runtimeName));
50+
if (updatePipelineErr) {
51+
console.log(colors.yellow('*warning* failed to update test pipeline runtime, you can' +
52+
' change it manually if you want to run it again on this runtime'));
53+
}
4754
}
4855
console.log(`${colors.yellow('*NOTE* Running a pipeline for the first time might take longer than usual.')}`);
4956
const [runPipelineErr] = await to(executeTestPipeline(

lib/interface/cli/commands/hybrid/migration.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const inquirer = require('inquirer');
99
const fs = require('fs');
1010
const {
1111
getTestPipeline,
12+
updateTestPipelineRuntime,
1213
createTestPipeline,
1314
executeTestPipeline,
1415
createProgressBar,
@@ -31,6 +32,12 @@ async function createAndRunTestPipeline(runtimeName, errHandler) {
3132
));
3233
await errHandler(createPipelineErr, 'Failed to create test pipeline');
3334
testPipeline = _testPipeline;
35+
} else {
36+
const [updatePipelineErr] = await to(updateTestPipelineRuntime(testPipeline, runtimeName));
37+
if (updatePipelineErr) {
38+
console.log(colors.yellow('*warning* failed to update test pipeline runtime, you can' +
39+
' change it manually if you want to run it again on this runtime'));
40+
}
3441
}
3542
const [runPipelineErr] = await to(executeTestPipeline(
3643
runtimeName,
@@ -133,6 +140,7 @@ async function migrate({
133140
'runtime-name': runtimeName,
134141
'runtime-kube-context-name': kubeContextName,
135142
'runtime-kube-namespace': kubeNamespace,
143+
'runtime-kube-serviceaccount': 'venona',
136144
'runtime-kube-config-path': kubeConfigPath,
137145
'agent-kube-context-name': kubeContextName,
138146
'agent-kube-namespace': kubeNamespace,

lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const attachRuntimeCmd = new Command({
7979
'runtime-kube-config-path': kubeConfigPath,
8080
'agent-kube-namespace': agentKubeNamespace,
8181
'agent-kube-config-path': agentKubeConfigPath,
82+
'runtime-kube-serviceaccount': kubeServiceAccount,
8283
'restart-agent': restartAgent,
8384
verbose,
8485

@@ -132,6 +133,7 @@ const attachRuntimeCmd = new Command({
132133
});
133134
await sdk.runtime.attach({
134135
kubeContextName,
136+
kubeServiceAccount,
135137
kubeNamespace,
136138
kubeConfigPath,
137139
agentKubeContextName,

lib/interface/cli/commands/runtimeEnvironments/install.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const _ = require('lodash');
1212
const { DefaultLogFormatter } = require('./../hybrid/helper');
1313

1414
const defaultNamespace = 'codefresh';
15+
const defaultStorageClassPrefix = 'dind-local-volumes-runner';
1516
const maxRuntimeNameLength = 63;
1617

1718
async function newRuntimeName(kubeContextName, kubeNamespace) {
@@ -176,7 +177,7 @@ const installRuntimeCmd = new Command({
176177
// create RE in codefresh
177178
await sdk.cluster.create({
178179
namespace: kubeNamespace,
179-
storageClassName,
180+
storageClassName: storageClassName || `${defaultStorageClassPrefix}-${kubeNamespace}`,
180181
runnerType: kubernetesRunnerType,
181182
nodeSelector: kubeNodeSelectorObj,
182183
annotations: buildAnnotations,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.68.0",
3+
"version": "0.68.1",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,
@@ -37,7 +37,7 @@
3737
"cf-errors": "^0.1.12",
3838
"chalk": "^1.1.3",
3939
"cli-progress": "3.6.0",
40-
"codefresh-sdk": "^1.9.10",
40+
"codefresh-sdk": "^1.9.11",
4141
"colors": "^1.1.2",
4242
"columnify": "^1.5.4",
4343
"compare-versions": "^3.4.0",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,10 +1242,10 @@ code-point-at@^1.0.0:
12421242
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
12431243
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=
12441244

1245-
codefresh-sdk@^1.9.10:
1246-
version "1.9.10"
1247-
resolved "https://registry.yarnpkg.com/codefresh-sdk/-/codefresh-sdk-1.9.10.tgz#47643648e513aa998d2a5556e957b3cf6ad7706e"
1248-
integrity sha512-Xr+numOuRzBqigOBqVBR3W/BJKvOqU7n+i7H90n567tUHn/x0oz6VVIp99JIA65w9UiihAZqEO3xRBowodbw3A==
1245+
codefresh-sdk@^1.9.11:
1246+
version "1.9.11"
1247+
resolved "https://registry.yarnpkg.com/codefresh-sdk/-/codefresh-sdk-1.9.11.tgz#2f9f801cc280d2c394a898a1bc61ffd04ccf29f5"
1248+
integrity sha512-L7ysKRRwdvQ44JIBd016N8Vzff2Q6FXTucGr57XB3o2Jvbf9HhXCwS4VfE3jETKDGALB3/IqwcCwVuC/+O5/Tg==
12491249
dependencies:
12501250
bluebird "^3.5.3"
12511251
cf-errors "^0.1.12"

0 commit comments

Comments
 (0)