Skip to content

Commit 2a29044

Browse files
authored
Saas 8261 --values for venonactl (#550)
* added --values
1 parent c6c264a commit 2a29044

File tree

7 files changed

+121
-22
lines changed

7 files changed

+121
-22
lines changed

lib/binary/components.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
versionFile: 'version.txt',
2828
dir: 'agent',
2929
binary: 'venona',
30+
alternateBinary: process.env.VENONACTL,
3031
},
3132
remote: {
3233
versionPath: 'venonactl',

lib/binary/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Runner {
1111

1212
async run(component, args) {
1313
const dir = join(this.location, component.local.dir);
14-
const path = join(dir, component.local.binary);
14+
const path = component.local.alternateBinary || join(dir, component.local.binary);
1515
const cp = spawn(path, args, {
1616
stdio: [process.stdin, process.stdout, process.stderr],
1717
});

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const colors = require('colors');
1010
const DEFAULTS = require('../../defaults');
1111
const sdk = require('../../../../logic/sdk');
1212
const _ = require('lodash');
13+
const YAML = require('yaml');
14+
const fs = require('fs');
1315
const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
1416
const {
1517
createErrorHandler,
@@ -65,8 +67,7 @@ const deleteCmd = new Command({
6567
})
6668
.option('url', {
6769
describe: 'Codefresh system custom url',
68-
default: DEFAULTS.URL,
69-
})
70+
})
7071
.option('force', {
7172
describe: 'Run the delete operation without asking to confirm (use with caution!)',
7273
alias: 'f',
@@ -81,18 +82,20 @@ const deleteCmd = new Command({
8182
.option('kube-config-path', {
8283
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
8384
})
85+
.option('values', {
86+
describe: 'specify values in a YAML file',
87+
})
8488
.option('verbose', {
8589
describe: 'Print logs',
8690
}),
8791
handler: async (argv) => {
88-
const {
89-
'kube-config-path': kubeConfigPath,
90-
force,
91-
} = argv;
9292
let {
93+
'kube-config-path': kubeConfigPath,
94+
url, force,
9395
'kube-context-name': kubeContextName,
9496
'kube-namespace': kubeNamespace,
9597
name: agentName,
98+
'values': valuesFile,
9699
} = argv;
97100

98101
const [listReErr, runtimes] = await to(sdk.runtimeEnvs.list({ }));
@@ -106,6 +109,30 @@ const deleteCmd = new Command({
106109
}
107110

108111
console.log(colors.green('This uninstaller will guide you through the runner uninstallation process'));
112+
if (valuesFile) {
113+
let valuesFileStr = fs.readFileSync(valuesFile, 'utf8');
114+
valuesObj = YAML.parse(valuesFileStr);
115+
116+
if ( !kubeConfigPath && valuesObj.ConfigPath ) {
117+
kubeConfigPath = valuesObj.ConfigPath;
118+
}
119+
if ( !kubeNamespace && valuesObj.Namespace ) {
120+
kubeNamespace = valuesObj.Namespace;
121+
}
122+
if ( !kubeContextName && valuesObj.Context ) {
123+
kubeContextName = valuesObj.Context;
124+
}
125+
if ( !url && valuesObj.CodefreshHost ) {
126+
url = valuesObj.CodefreshHost
127+
}
128+
129+
if ( !agentName && valuesObj.AgentId ) {
130+
agentName = valuesObj.AgentId
131+
}
132+
}
133+
if (!url) {
134+
url = DEFAULTS.URL
135+
}
109136

110137
if (!kubeContextName) {
111138
const contexts = getAllKubeContexts(kubeConfigPath);

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ async function installAgent({
461461
verbose, // --verbose
462462
logFormatting = DefaultLogFormatter, // --log-formtter
463463
envVars,
464+
valuesFile, // --values
465+
setValue, // --set-value
466+
setFile, // --set-file
464467
}) {
465468
const binLocation = await downloadVeonona();
466469
const componentRunner = new Runner(binLocation);
@@ -519,7 +522,15 @@ async function installAgent({
519522
cmd.push(`--envVars=${element}`);
520523
});
521524
}
522-
525+
if (valuesFile) {
526+
cmd.push(`--values=${valuesFile}`);
527+
}
528+
if (setValue) {
529+
cmd.push(`--set-value=${setValue}`);
530+
}
531+
if (setFile) {
532+
cmd.push(`--set-file=${setFile}`);
533+
}
523534
await componentRunner.run(components.venona, cmd);
524535
}
525536

@@ -535,6 +546,7 @@ async function installRuntime({
535546
kubeConfigPath, // --kube-config-path
536547
verbose, // --verbose
537548
name, // --runtimeEnvironmentName
549+
valuesFile, // --values
538550
setValue, // --set-value
539551
setFile, // --set-file
540552
kubeNodeSelector, // --kube-node-selector
@@ -577,6 +589,9 @@ async function installRuntime({
577589
if (verbose) {
578590
cmd.push('--verbose');
579591
}
592+
if (valuesFile) {
593+
cmd.push(`--values=${valuesFile}`);
594+
}
580595
if (setValue) {
581596
cmd.push(`--set-value=${setValue}`);
582597
}
@@ -612,6 +627,9 @@ async function attachRuntime({
612627
verbose, // --verbose
613628
runtimeName, // --runtimeName
614629
logFormatting = DefaultLogFormatter, // --log-formtter
630+
valuesFile, // --values
631+
setValue, // --set-value
632+
setFile, // --set-file
615633
}) {
616634
const binLocation = await downloadVeonona();
617635
const componentRunner = new Runner(binLocation);
@@ -653,6 +671,15 @@ async function attachRuntime({
653671
cmd.push(`--log-formtter=${logFormatting}`);
654672
}
655673

674+
if (valuesFile) {
675+
cmd.push(`--values=${valuesFile}`);
676+
}
677+
if (setValue) {
678+
cmd.push(`--set-value=${setValue}`);
679+
}
680+
if (setFile) {
681+
cmd.push(`--set-file=${setFile}`);
682+
}
656683
await componentRunner.run(components.venona, cmd);
657684
}
658685

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

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const sdk = require('../../../../logic/sdk');
1515
const installationProgress = require('./installation-process');
1616
const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
1717
const { createErrorHandler } = require('./helper');
18+
const YAML = require('yaml');
19+
const fs = require('fs');
1820
const {
1921
createTestPipeline,
2022
executeTestPipeline,
@@ -87,7 +89,6 @@ const initCmd = new Command({
8789
})
8890
.option('url', {
8991
describe: 'Codefresh system custom url',
90-
default: DEFAULTS.URL,
9192
})
9293
.option('kube-context-name', {
9394
describe: 'Name of the Kubernetes context on which runner should be installed [$CF_ARG_KUBE_CONTEXT_NAME]',
@@ -136,6 +137,9 @@ const initCmd = new Command({
136137
.option('kube-config-path', {
137138
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
138139
})
140+
.option('values', {
141+
describe: 'specify values in a YAML file',
142+
})
139143
.option('set-value', {
140144
describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
141145
})
@@ -177,23 +181,23 @@ const initCmd = new Command({
177181
_argv = Object.assign(oldInstallationPlan.getContext('argv'), _argv); // restore previous installation environment
178182
}
179183

180-
const {
184+
let {
181185
'kube-node-selector': kubeNodeSelector,
182186
'build-node-selector': buildNodeSelector,
183187
tolerations,
184188
'kube-config-path': kubeConfigPath,
185189
'storage-class-name': storageClassName,
186-
yes: noQuestions,
190+
'yes': noQuestions,
187191
verbose,
188192
name, url,
189193
token,
194+
'values': valuesFile,
190195
'set-value': setValue,
191196
'set-file': setFile,
192197
'skip-cluster-test': skipClusterTest,
193198
'install-monitor': installMonitor,
194199
'docker-registry': dockerRegistry,
195-
} = _argv;
196-
let {
200+
197201
'kube-context-name': kubeContextName,
198202
'kube-namespace': kubeNamespace,
199203
'set-default-runtime': shouldMakeDefaultRe,
@@ -203,6 +207,35 @@ const initCmd = new Command({
203207
'https-proxy': httpsProxy,
204208
} = _argv;
205209

210+
let valuesObj;
211+
if (valuesFile) {
212+
let valuesFileStr = fs.readFileSync(valuesFile, 'utf8');
213+
valuesObj = YAML.parse(valuesFileStr);
214+
noQuestions = true;
215+
216+
if ( !kubeNamespace && valuesObj.Namespace ) {
217+
kubeNamespace = valuesObj.Namespace;
218+
}
219+
if ( !kubeContextName && valuesObj.Context ) {
220+
kubeContextName = valuesObj.Context;
221+
}
222+
if ( !url && valuesObj.CodefreshHost ) {
223+
url = valuesObj.CodefreshHost;
224+
}
225+
if ( !token && valuesObj.Token ) {
226+
token = valuesObj.Token;
227+
}
228+
if ( !name && valuesObj.AgentId ) {
229+
name = valuesObj.AgentId;
230+
}
231+
if ( typeof _.get(valuesObj, "Monitor.Enabled" ) !== 'undefined' ) {
232+
installMonitor = _.get(valuesObj, "Monitor.Enabled");
233+
}
234+
}
235+
if (!url) {
236+
url = DEFAULTS.URL;
237+
}
238+
206239
if (_.get(sdk, 'config.context.isNoAuth') && !token) {
207240
console.log('Not authenticated as a Codefresh account: ');
208241
console.log('In order to install a Codefresh Runner you need to provide ' +
@@ -363,14 +396,15 @@ const initCmd = new Command({
363396
installationPlan.addContext('argv', _argv);
364397

365398
// run cluster acceptance tests
366-
installationPlan.addStep({
367-
name: 'run cluster acceptance tests',
368-
func: runClusterAcceptanceTests,
369-
arg: { kubeNamespace, kubeConfigPath },
370-
installationEvent: installationProgress.events.ACCEPTANCE_TESTS_RAN,
371-
condition: !skipClusterTest,
372-
});
373-
399+
if (! _.get(valuesObj, "SkipClusterTest")) {
400+
installationPlan.addStep({
401+
name: 'run cluster acceptance tests',
402+
func: runClusterAcceptanceTests,
403+
arg: { kubeNamespace, kubeConfigPath },
404+
installationEvent: installationProgress.events.ACCEPTANCE_TESTS_RAN,
405+
condition: !skipClusterTest,
406+
});
407+
}
374408
// generate new agent name
375409
installationPlan.addContext('agentName', name ? name.trim() : name);
376410
installationPlan.addStep({
@@ -414,6 +448,9 @@ const initCmd = new Command({
414448
verbose,
415449
agentId: installationPlan.getContext('agentName'),
416450
envVars,
451+
valuesFile, // --values
452+
setValue, // --set-value
453+
setFile, // --set-file
417454
});
418455
},
419456
installationEvent: installationProgress.events.AGENT_INSTALLED,
@@ -538,6 +575,7 @@ const initCmd = new Command({
538575
verbose,
539576
kubeNodeSelector,
540577
dockerRegistry,
578+
valuesFile,
541579
setValue,
542580
setFile,
543581
storageClassName,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.72.2",
3+
"version": "0.72.3",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,
@@ -71,6 +71,7 @@
7171
"rimraf": "^2.6.2",
7272
"semver": "^7.3.2",
7373
"uuid": "^3.1.0",
74+
"yaml": "^1.10.0",
7475
"yargs": "^15.0.2",
7576
"yargs-parser": "^13.0.0"
7677
},

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7324,6 +7324,11 @@ yallist@^3.0.2:
73247324
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
73257325
integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==
73267326

7327+
yaml@^1.10.0:
7328+
version "1.10.0"
7329+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"
7330+
integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==
7331+
73277332
yargs-parser@^13.0.0:
73287333
version "13.1.2"
73297334
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-13.1.2.tgz#130f09702ebaeef2650d54ce6e3e5706f7a4fb38"

0 commit comments

Comments
 (0)