Skip to content

Commit 9c9b329

Browse files
values yaml changes (#584)
* values yaml changes
1 parent 9b0d45e commit 9c9b329

File tree

5 files changed

+127
-46
lines changed

5 files changed

+127
-46
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async function promptConfirmationMessage({
3535
console.log(`\u2022 Codefresh runner with the name "${colors.cyan(agentName)}"`);
3636
attachedRuntimes.forEach((reName) => { console.log(`\u2022 Codefresh runtime with the name "${colors.cyan(reName)}"`); });
3737
console.log('\u2022 Codefresh runner monitor component');
38+
console.log('\u2022 Codefresh App-Proxy component (if exists)');
3839
console.log(`* The kubernetes namespace "${colors.cyan(kubeNamespace)}" will ${colors.underline('not')} be deleted\n`);
3940

4041
const answer = await inquirer.prompt({

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

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,9 @@ async function installAgent({
522522
cmd.push('--verbose');
523523
}
524524
if (envVars) {
525-
envVars.forEach((element) => {
526-
cmd.push(`--envVars=${element}`);
525+
envVars.forEach((item) => {
526+
const parts = item.split('=');
527+
cmd.push(`--set-value=EnvVars.${parts[0]}=${parts[1]}`);
527528
});
528529
}
529530
if (valuesFile) {
@@ -549,6 +550,7 @@ async function installRuntime({
549550
kubeConfigPath, // --kube-config-path
550551
verbose, // --verbose
551552
name, // --runtimeEnvironmentName
553+
envVars,
552554
valuesFile, // --values
553555
setValue, // --set-value
554556
setFile, // --set-file
@@ -595,6 +597,12 @@ async function installRuntime({
595597
if (setValue) {
596598
cmd.push(`--set-value=${setValue}`);
597599
}
600+
if (envVars) {
601+
envVars.forEach((item) => {
602+
const parts = item.split('=');
603+
cmd.push(`--set-value=EnvVars.${parts[0]}=${parts[1]}`);
604+
});
605+
}
598606
if (setFile) {
599607
cmd.push(`--set-file=${setFile}`);
600608
}
@@ -624,9 +632,11 @@ async function installAppProxy({
624632
logFormatting = DefaultLogFormatter, // --log-formtter
625633
valuesFile, // --values
626634
setValue, // --set-value
635+
setFile, // --set-file
627636
appProxyHost, // --app-proxy-host
628637
appProxyIngressClass, // --app-proxy-ingress-class
629638
apiHost, // --api-host
639+
envVars, // --envVars
630640
}) {
631641
const binLocation = await downloadVeonona();
632642
const componentRunner = new Runner(binLocation);
@@ -665,9 +675,18 @@ async function installAppProxy({
665675
cmd.push(`--set-value=${setValue}`);
666676
}
667677
}
678+
if (envVars) {
679+
envVars.forEach((item) => {
680+
const parts = item.split('=');
681+
cmd.push(`--set-value=EnvVars.${parts[0]}=${parts[1]}`);
682+
});
683+
}
668684
if (valuesFile) {
669685
cmd.push(`--values=${valuesFile}`);
670686
}
687+
if (setFile) {
688+
cmd.push(`--set-file=${setFile}`);
689+
}
671690
if (appProxyHost) {
672691
cmd.push(`--host=${appProxyHost}`);
673692
}
@@ -890,6 +909,38 @@ function keyValueAsStringToObject(nodeSelectorStr) {
890909
}
891910
}
892911

912+
function keyValueArrayToObject(arr) {
913+
return arr.reduce((acc, cur) => {
914+
const parts = cur.split('=');
915+
// eslint-disable-next-line prefer-destructuring
916+
acc[parts[0]] = parts[1];
917+
return acc;
918+
}, {});
919+
}
920+
921+
function objectToKeyValueArray(obj) {
922+
return Object.keys(obj).reduce((acc, key) => {
923+
acc.push(`${key}=${obj[key]}`);
924+
return acc;
925+
}, []);
926+
}
927+
928+
function addProxyVariables(envVars, { httpProxy, httpsProxy, noProxy }) {
929+
const envVarsObj = keyValueArrayToObject(envVars);
930+
if (httpsProxy && !envVarsObj.HTTPS_PROXY && !envVarsObj.https_proxy) {
931+
envVars.push(`HTTPS_PROXY=${httpsProxy}`);
932+
envVars.push(`https_proxy=${httpsProxy}`);
933+
}
934+
if (httpProxy && !envVarsObj.HTTP_PROXY && !envVarsObj.http_proxy) {
935+
envVars.push(`HTTP_PROXY=${httpProxy}`);
936+
envVars.push(`http_proxy=${httpProxy}`);
937+
}
938+
if (noProxy && !envVarsObj.NO_PROXY && !envVarsObj.no_proxy) {
939+
envVars.push(`NO_PROXY=${noProxy}`);
940+
envVars.push(`no_proxy=${noProxy}`);
941+
}
942+
}
943+
893944
function serealizeToKeyValuePairs(obj) {
894945
return _.keys(obj).reduce((acc, key) => {
895946
if (acc) {
@@ -925,6 +976,7 @@ module.exports = {
925976
getRuntimeVersion,
926977
createTestPipeline,
927978
getTestPipeline,
979+
addProxyVariables,
928980
updateTestPipelineRuntime,
929981
executeTestPipeline,
930982
createProgressBar,
@@ -939,6 +991,8 @@ module.exports = {
939991
newRuntimeName,
940992
newAgentName,
941993
keyValueAsStringToObject,
994+
keyValueArrayToObject,
995+
objectToKeyValueArray,
942996
downloadRelatedComponents: downloadHybridComponents,
943997
downloadSteveDore,
944998
downloadVeonona,

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

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ const DEFAULTS = require('../../defaults');
1414
const sdk = require('../../../../logic/sdk');
1515
const installationProgress = require('./installation-process');
1616
const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
17-
const { createErrorHandler } = require('./helper');
1817
const YAML = require('yaml');
1918
const fs = require('fs');
2019
const {
20+
createErrorHandler,
21+
keyValueArrayToObject,
2122
createTestPipeline,
2223
executeTestPipeline,
2324
updateTestPipelineRuntime,
@@ -34,6 +35,8 @@ const {
3435
detectProxy,
3536
keyValueAsStringToObject,
3637
getRuntimeImagesWithRegistryUrl,
38+
addProxyVariables,
39+
objectToKeyValueArray,
3740
INSTALLATION_DEFAULTS,
3841
} = require('./helper');
3942
const InstallationPlan = require('./InstallationPlan');
@@ -57,6 +60,7 @@ function printInstallationOptionsSummary({
5760
shouldExecutePipeline,
5861
httpProxy,
5962
httpsProxy,
63+
noProxy,
6064
appProxy,
6165
appProxyHost,
6266
}) {
@@ -67,6 +71,7 @@ function printInstallationOptionsSummary({
6771
4. Execute demo pipeline after install: ${colors.cyan(!!shouldExecutePipeline)}
6872
5. HTTP proxy: ${httpProxy ? colors.cyan(httpProxy) : 'none'}
6973
6. HTTPS proxy: ${httpsProxy ? colors.cyan(httpsProxy) : 'none'}
74+
7. No proxy: ${noProxy ? colors.cyan(noProxy) : 'none'}
7075
`;
7176

7277
if (appProxy) {
@@ -146,7 +151,7 @@ const initCmd = new Command({
146151
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
147152
})
148153
.option('values', {
149-
describe: 'specify values in a YAML file',
154+
describe: 'specify values in a YAML file (see example here: https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml)',
150155
})
151156
.option('set-value', {
152157
describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
@@ -171,8 +176,9 @@ const initCmd = new Command({
171176
describe: 'Print logs',
172177
})
173178
.option('env-vars', {
174-
describe: 'Addiontal env vars to be used in agent\'s pod',
179+
describe: 'Addiontal env vars to be used in all Codefresh components',
175180
type: array,
181+
default: [],
176182
})
177183
.option('app-proxy', {
178184
describe: 'install app proxy component (default false)',
@@ -191,7 +197,9 @@ const initCmd = new Command({
191197
describe: 'docker daemon access (default true)',
192198
default: true,
193199
type: 'boolean',
194-
}),
200+
})
201+
.example('codefresh runner init --values values.yaml (see values file example here: '
202+
+ 'https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml)'),
195203
handler: async (argv) => {
196204
let resumedInstallation = false;
197205

@@ -225,16 +233,16 @@ const initCmd = new Command({
225233
'set-value': setValue,
226234
'set-file': setFile,
227235
'skip-cluster-test': skipClusterTest,
228-
'docker-registry': dockerRegistry,
229236
'app-proxy-ingress-class': appProxyIngressClass,
237+
'env-vars': envVars,
230238
} = _argv;
231239
let {
232240
yes: noQuestions,
233241
'kube-context-name': kubeContextName,
234242
'kube-namespace': kubeNamespace,
235243
'set-default-runtime': shouldMakeDefaultRe,
244+
'docker-registry': dockerRegistry,
236245
'exec-demo-pipeline': shouldExecutePipeline,
237-
'env-vars': envVars,
238246
'http-proxy': httpProxy,
239247
'https-proxy': httpsProxy,
240248
'no-proxy': noProxy,
@@ -275,17 +283,23 @@ const initCmd = new Command({
275283
if (_.get(valuesObj, 'AppProxy')) {
276284
appProxy = true;
277285
}
278-
if (!appProxyHost && _.get(valuesObj, 'AppProxy.Host')) {
279-
appProxyHost = _.get(valuesObj, 'AppProxy.Host');
286+
if (!appProxyHost && _.get(valuesObj, 'AppProxy.Ingress.Host')) {
287+
appProxyHost = _.get(valuesObj, 'AppProxy.Ingress.Host');
280288
}
281-
if (!appProxyPathPrefix && _.get(valuesObj, 'AppProxy.PathPrefix')) {
282-
appProxyPathPrefix = _.get(valuesObj, 'AppProxy.PathPrefix');
289+
if (!appProxyPathPrefix && _.get(valuesObj, 'AppProxy.Ingress.PathPrefix')) {
290+
appProxyPathPrefix = _.get(valuesObj, 'AppProxy.Ingress.PathPrefix');
283291
}
284292
if (appProxy && !appProxyHost) {
285293
handleError(new Error('no hostname provided'), 'cannot install app-proxy component without a hostname', undefined, undefined, true);
286294
}
287295
if (_.has(valuesObj, 'dockerDaemonScheduler.userAccess')) {
288-
dockerDaemonAccess = _.get(valuesObj, 'dockerDaemonScheduler.userAccess')
296+
dockerDaemonAccess = _.get(valuesObj, 'dockerDaemonScheduler.userAccess');
297+
}
298+
if (_.has(valuesObj, 'EnvVars') && envVars.length === 0) {
299+
envVars.push(...objectToKeyValueArray(_.get(valuesObj, 'EnvVars')));
300+
}
301+
if (_.has(valuesObj, 'DockerRegistry') && !dockerRegistry) {
302+
dockerRegistry = _.get(valuesObj, 'DockerRegistry');
289303
}
290304
}
291305
if (!url) {
@@ -303,10 +317,7 @@ const initCmd = new Command({
303317
httpProxy = httpProxy || detectedProxyVars.httpProxy;
304318
httpsProxy = httpsProxy || detectedProxyVars.httpsProxy;
305319
noProxy = noProxy || detectedProxyVars.noProxy;
306-
envVars = envVars || [];
307-
if (!Array.isArray(envVars)) {
308-
envVars = [envVars];
309-
}
320+
310321
if (noQuestions) {
311322
// use defaults
312323
kubeContextName = kubeContextName || getKubeContext(kubeConfigPath);
@@ -344,7 +355,7 @@ const initCmd = new Command({
344355
type: 'input',
345356
name: 'httpProxy',
346357
default: httpProxy,
347-
message: 'HTTP proxy to be used by runner inside Kubernetes?',
358+
message: 'detected HTTP_PROXY, should I use this in all Codefresh components?',
348359
});
349360
}
350361

@@ -353,7 +364,7 @@ const initCmd = new Command({
353364
type: 'input',
354365
name: 'httpsProxy',
355366
default: httpsProxy,
356-
message: 'HTTPS proxy to be used by runner inside Kubernetes?',
367+
message: 'detected HTTPS_PROXY, should I use this in all Codefresh components?',
357368

358369
});
359370
}
@@ -362,7 +373,7 @@ const initCmd = new Command({
362373
type: 'input',
363374
name: 'noProxy',
364375
default: noProxy,
365-
message: 'NO_PROXY to be used by runner inside Kubernetes?',
376+
message: 'detected NO_PROXY, should I use this in all Codefresh components?',
366377

367378
});
368379
}
@@ -409,7 +420,8 @@ const initCmd = new Command({
409420
kubeNamespace = kubeNamespace || answers.namespace;
410421
shouldMakeDefaultRe = _.isUndefined(shouldMakeDefaultRe) ? answers.shouldMakeDefaultRe : shouldMakeDefaultRe;
411422
shouldExecutePipeline = _.isUndefined(shouldExecutePipeline) ? answers.shouldExecutePipeline : shouldExecutePipeline;
412-
({ httpProxy, httpsProxy, appProxyHost } = answers);
423+
// eslint-disable-next-line object-curly-newline
424+
({ httpProxy, httpsProxy, noProxy, appProxyHost } = answers);
413425
}
414426

415427
printInstallationOptionsSummary({
@@ -419,6 +431,7 @@ const initCmd = new Command({
419431
shouldExecutePipeline,
420432
httpProxy,
421433
httpsProxy,
434+
noProxy,
422435
appProxy,
423436
appProxyHost,
424437
});
@@ -455,18 +468,7 @@ const initCmd = new Command({
455468
installationPlan = new InstallationPlan({ progressReporter, errHandler: handleError });
456469
}
457470

458-
if (httpProxy) {
459-
envVars.push(`http_proxy=${httpProxy}`);
460-
envVars.push(`HTTP_PROXY=${httpProxy}`);
461-
}
462-
if (httpsProxy) {
463-
envVars.push(`https_proxy=${httpsProxy}`);
464-
envVars.push(`HTTPS_PROXY=${httpsProxy}`);
465-
}
466-
if (noProxy) {
467-
envVars.push(`no_proxy=${noProxy}`);
468-
envVars.push(`NO_PROXY=${noProxy}`);
469-
}
471+
addProxyVariables(envVars, { httpsProxy, httpProxy, noProxy });
470472

471473
// save the answers for backup
472474
_argv['kube-context-name'] = kubeContextName;
@@ -596,19 +598,17 @@ const initCmd = new Command({
596598
func: async () => {
597599
const reName = installationPlan.getContext('runtimeName');
598600
const re = await sdk.runtimeEnvs.get({ name: reName });
599-
let currentEnvVars = _.get(re, 'runtimeScheduler.envVars', {});
600-
const envVarsAsObject = envVars.reduce((acc, current) => {
601-
const parts = current.split('=');
602-
// eslint-disable-next-line prefer-destructuring
603-
acc[parts[0]] = parts[1];
604-
return acc;
605-
}, {});
606-
currentEnvVars = _.merge(currentEnvVars, envVarsAsObject);
607-
const body = _.set(re, 'runtimeScheduler.envVars', currentEnvVars);
608-
await sdk.runtimeEnvs.update({ name: reName }, _.merge(re, body));
601+
const envVarsObj = keyValueArrayToObject(envVars);
602+
const currentEngineEnvVars = _.get(re, 'runtimeScheduler.envVars', {});
603+
const currentDindEnvVars = _.get(re, 'dockerDaemonScheduler.envVars', {});
604+
const newEngineEnvVars = _.merge(currentEngineEnvVars, envVarsObj);
605+
const newDindEnvVars = _.merge(currentDindEnvVars, envVarsObj);
606+
_.set(re, 'runtimeScheduler.envVars', newEngineEnvVars);
607+
_.set(re, 'dockerDaemonScheduler.envVars', newDindEnvVars);
608+
await sdk.runtimeEnvs.update({ name: reName }, re);
609609
console.log(`Runtime environment "${colors.cyan(reName)}" has been updated with env vars`);
610610
},
611-
condition: !!envVars,
611+
condition: envVars.length,
612612
});
613613

614614
// set runtime as default
@@ -662,6 +662,7 @@ const initCmd = new Command({
662662
verbose,
663663
kubeNodeSelector,
664664
dockerRegistry,
665+
envVars,
665666
valuesFile,
666667
setValue,
667668
setFile,
@@ -681,7 +682,10 @@ const initCmd = new Command({
681682
verbose,
682683
kubeConfigPath,
683684
dockerRegistry,
685+
envVars,
684686
valuesFile,
687+
setValue,
688+
setFile,
685689
appProxyHost,
686690
appProxyIngressClass,
687691
});
@@ -763,6 +767,9 @@ const initCmd = new Command({
763767
'kube-context-name': kubeContextName,
764768
'kube-namespace': kubeNamespace,
765769
'docker-registry': dockerRegistry,
770+
'env-vars': envVars,
771+
'set-value': setValue,
772+
'set-file': setFile,
766773
token: _.get(sdk, 'config.context.token'),
767774
verbose,
768775
noExit: true, // to prevent if from calling inner: process.exit()

0 commit comments

Comments
 (0)