Skip to content

Commit 94c0264

Browse files
support dry run when installing runner via init (#626)
* support dry run when installing runner via init * wip * wip Co-authored-by: roi.kramer <roi.kramer@codefresh.io>
1 parent 632c8b5 commit 94c0264

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const STEP_STATUSES = {
2323
SKIPPED: 'skipped',
2424
};
2525

26+
const DRY_RUN_VALUES = {
27+
agentName: 'dry-run-agent-id',
28+
agentToken: 'dry-run-token',
29+
runtimeName: 'dry-run-runtime-name',
30+
};
31+
2632
function _ensureDirectory(location) {
2733
if (!existsSync(location)) {
2834
mkdirSync(location);
@@ -58,6 +64,7 @@ class InstallationPlan {
5864
installationEvent,
5965
exitOnError = true,
6066
condition = true,
67+
executeOnDryRun = false,
6168
}) {
6269
if (!this.completedSteps[name]) {
6370
this.state.pendingSteps.push({
@@ -70,6 +77,7 @@ class InstallationPlan {
7077
installationEvent,
7178
exitOnError,
7279
condition,
80+
executeOnDryRun,
7381
status: STEP_STATUSES.PENDING,
7482
});
7583
}
@@ -93,7 +101,17 @@ class InstallationPlan {
93101
this.state.finishedSteps.push(step);
94102
const _args = step.args || [step.arg];
95103

104+
let shouldSkip = false;
105+
106+
if (this._isDryRun() && !step.executeOnDryRun) {
107+
shouldSkip = true;
108+
}
109+
96110
if (!step.condition || (_.isFunction(step.condition) && !await step.condition())) {
111+
shouldSkip = true;
112+
}
113+
114+
if (shouldSkip) {
97115
console.log(`skipping step: ${colors.cyan(step.name)}`);
98116
step.status = STEP_STATUSES.SKIPPED;
99117
this._writeState();
@@ -143,9 +161,17 @@ class InstallationPlan {
143161
}
144162

145163
getContext(key) {
164+
if (this._isDryRun() && _.isUndefined(this.state.context.key)) {
165+
return DRY_RUN_VALUES[key];
166+
}
146167
return this.state.context[key];
147168
}
148169

170+
_isDryRun() {
171+
const { argv } = this.state.context;
172+
return argv && argv.dryRun;
173+
}
174+
149175
_writeState() {
150176
writeFileSync(INSTALLATION_STATE_FILE_PATH, JSON.stringify(this.state));
151177
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ async function installAppProxy({
678678
appProxyIngressClass, // --app-proxy-ingress-class
679679
apiHost, // --api-host
680680
envVars, // --envVars
681+
dryRun, // --dry-run
681682
}) {
682683
const binLocation = await downloadVeonona();
683684
const componentRunner = new Runner(binLocation);
@@ -731,6 +732,9 @@ async function installAppProxy({
731732
if (appProxyHost) {
732733
cmd.push(`--host=${appProxyHost}`);
733734
}
735+
if (dryRun) {
736+
cmd.push('--dry-run');
737+
}
734738
if (appProxyIngressClass) {
735739
cmd.push(`--ingress-class=${appProxyIngressClass}`);
736740
}
@@ -835,6 +839,7 @@ async function attachRuntime({
835839
valuesFile, // --values
836840
setValue, // --set-value
837841
setFile, // --set-file
842+
dryRun,
838843
}) {
839844
const binLocation = await downloadVeonona();
840845
const componentRunner = new Runner(binLocation);
@@ -885,6 +890,9 @@ async function attachRuntime({
885890
if (setFile) {
886891
cmd.push(`--set-file=${setFile}`);
887892
}
893+
if (dryRun) {
894+
cmd.push('--dry-run');
895+
}
888896
await componentRunner.run(components.venona, cmd);
889897
}
890898

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function printInstallationOptionsSummary({
5959
noProxy,
6060
appProxy,
6161
appProxyHost,
62+
dryRun,
6263
}) {
6364
let summary = `\n${colors.green('Installation options summary:')}
6465
1. Kubernetes Context: ${colors.cyan(kubeContextName)}
@@ -73,6 +74,9 @@ function printInstallationOptionsSummary({
7374
if (appProxy) {
7475
summary += `7. App-Proxy hostname: ${colors.cyan(appProxyHost)}\n`;
7576
}
77+
if (dryRun) {
78+
summary += '**** running in dry-run mode ****';
79+
}
7680
console.log(summary);
7781
}
7882

@@ -194,6 +198,11 @@ const initCmd = new Command({
194198
default: true,
195199
type: 'boolean',
196200
})
201+
.option('dry-run', {
202+
describe: 'Will save all of the manifests to be deployed on the cluster to: ./manifests/',
203+
default: false,
204+
type: 'boolean',
205+
})
197206
.example('codefresh runner init --values values.yaml (see values file example here: '
198207
+ 'https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml)'),
199208
handler: async (argv) => {
@@ -249,6 +258,7 @@ const initCmd = new Command({
249258
reResources,
250259
userVolumeMounts,
251260
userVolumes,
261+
'dry-run': dryRun,
252262
} = _argv;
253263
let {
254264
'kube-context-name': kubeContextName,
@@ -395,6 +405,7 @@ const initCmd = new Command({
395405
noProxy,
396406
appProxy,
397407
appProxyHost,
408+
dryRun,
398409
});
399410

400411
if (token) {
@@ -410,14 +421,14 @@ const initCmd = new Command({
410421
console.log(`A Codefresh context named '${INSTALLATION_DEFAULTS.CF_CONTEXT_NAME}' was added to your "cfconfig" file.`);
411422
}
412423

413-
const [, progress] = await to(async () => installationProgress.create(sdk['runner-installation'], {
424+
const progress = dryRun ? {} : await installationProgress.create(sdk['runner-installation'], {
414425
options: {
415426
kubeContextName,
416427
kubeNamespace,
417428
shouldMakeDefaultRe,
418429
shouldExecutePipeline,
419430
},
420-
}));
431+
});
421432
const progressReporter = installationProgress.buildReporter(sdk['runner-installation'], progress);
422433

423434
let installationPlan;
@@ -506,9 +517,11 @@ const initCmd = new Command({
506517
valuesFile, // --values
507518
setValue, // --set-value
508519
setFile, // --set-file
520+
dryRun,
509521
});
510522
},
511523
installationEvent: installationProgress.events.AGENT_INSTALLED,
524+
executeOnDryRun: true,
512525
});
513526

514527
// generate new runtime name
@@ -667,9 +680,11 @@ const initCmd = new Command({
667680
setValue,
668681
setFile,
669682
storageClassName,
683+
dryRun,
670684
});
671685
},
672686
installationEvent: installationProgress.events.RUNTIME_INSTALLED,
687+
executeOnDryRun: true,
673688
});
674689

675690
installationPlan.addStep({
@@ -688,12 +703,14 @@ const initCmd = new Command({
688703
setFile,
689704
appProxyHost,
690705
appProxyIngressClass,
706+
dryRun,
691707
});
692708
const appProxyUrl = `https://${appProxyHost}${appProxyPathPrefix || ''}`;
693709
installationPlan.addContext('appProxyIP', `${appProxyUrl}`);
694710
},
695711
installationEvent: installationProgress.events.APP_PROXY_INSTALLED,
696712
condition: !!appProxy,
713+
executeOnDryRun: true,
697714
});
698715

699716
// update runtime with ingress IP
@@ -752,9 +769,11 @@ const initCmd = new Command({
752769
restartAgent: true, // --restart-agent
753770
verbose, // --verbose
754771
runtimeName: installationPlan.getContext('runtimeName'), // --runtimeName
772+
dryRun,
755773
});
756774
},
757775
installationEvent: installationProgress.events.RUNNER_INSTALLED,
776+
executeOnDryRun: true,
758777
});
759778

760779
// install monitoring
@@ -770,6 +789,7 @@ const initCmd = new Command({
770789
'env-vars': envVars,
771790
'set-value': setValue,
772791
'set-file': setFile,
792+
'dry-run': dryRun,
773793
token: _.get(sdk, 'config.context.token'),
774794
verbose,
775795
noExit: true, // to prevent if from calling inner: process.exit()
@@ -778,6 +798,7 @@ const initCmd = new Command({
778798
},
779799
successMessage: 'Successfully installed cluster monitoring',
780800
installationEvent: installationProgress.events.MONITOR_INSTALLED,
801+
executeOnDryRun: true,
781802
condition: async () => {
782803
if (!installMonitor) {
783804
return false;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ const installMonitorCmd = new Command({
4747
})
4848
.option('verbose', {
4949
describe: 'Print logs',
50+
})
51+
.option('dry-run', {
52+
describe: 'dry run',
53+
default: false,
54+
type: 'boolean',
5055
}),
5156
handler: async (argv) => {
5257
const {
@@ -63,6 +68,7 @@ const installMonitorCmd = new Command({
6368
'env-vars': envVars,
6469
'set-value': setValue,
6570
'set-file': setFile,
71+
'dry-run': dryRun,
6672
// noExit,
6773
} = argv;
6874
const binLocation = await downloadVeonona();
@@ -137,6 +143,9 @@ const installMonitorCmd = new Command({
137143
commands.push(`--set-value=EnvVars.${parts[0]}=${parts[1].replace(/,/g, '\\,')}`);
138144
});
139145
}
146+
if (dryRun) {
147+
commands.push('--dry-run');
148+
}
140149

141150
await componentRunner.run(components.venona, commands);
142151
},

0 commit comments

Comments
 (0)