Skip to content

Commit 3d8eba4

Browse files
support appProxy for runner init (#555)
* support appProxy for runner init
1 parent 2a29044 commit 3d8eba4

File tree

4 files changed

+120
-18
lines changed

4 files changed

+120
-18
lines changed

lib/binary/runner.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ class Runner {
2525
});
2626
});
2727
}
28+
29+
runAndAttach(component, args) {
30+
const dir = join(this.location, component.local.dir);
31+
const path = join(dir, component.local.binary);
32+
const cp = spawn(path, args, {
33+
stdio: [process.stdin, process.stdout, process.stderr, 'pipe'],
34+
});
35+
return cp;
36+
}
2837
}
2938

3039
module.exports = { Runner };

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,56 @@ async function installRuntime({
615615
await componentRunner.run(components.venona, cmd);
616616
}
617617

618+
async function installAppProxy({
619+
kubeContextName, // kube-context-name
620+
kubeNamespace, // --kube-namespace
621+
kubeConfigPath, // --kube-config-path
622+
verbose, // --verbose
623+
logFormatting = DefaultLogFormatter, // --log-formtter
624+
}) {
625+
const binLocation = await downloadVeonona();
626+
const componentRunner = new Runner(binLocation);
627+
const cmd = [
628+
'install',
629+
'app-proxy',
630+
'--kube-context-name',
631+
kubeContextName,
632+
'--kube-namespace',
633+
kubeNamespace,
634+
'--log-formtter',
635+
logFormatting,
636+
];
637+
638+
if (kubeConfigPath) {
639+
cmd.push(`--kube-config-path=${kubeConfigPath}`);
640+
}
641+
if (verbose) {
642+
cmd.push('--verbose');
643+
}
644+
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
645+
cmd.push('--insecure');
646+
}
647+
const cp = componentRunner.runAndAttach(components.venona, cmd, true);
648+
const chunks = [];
649+
let ingressIp;
650+
cp.stdio[3].on('data', (chunk) => {
651+
chunks.push(chunk);
652+
});
653+
cp.stdio[3].on('end', () => {
654+
const data = JSON.parse(Buffer.concat(chunks).toString());
655+
ingressIp = _.get(data, 'ingressIP');
656+
});
657+
return new Promise((resolveFn, rejectFn) => {
658+
cp.on('exit', (code) => {
659+
if (code !== 0) {
660+
rejectFn(new Error(`Component exited with status code ${code}`));
661+
} else {
662+
resolveFn(ingressIp);
663+
}
664+
});
665+
});
666+
}
667+
618668
async function attachRuntime({
619669
kubeServiceAccount, // kube-service-account
620670
kubeContextName, // kube-context-name
@@ -800,6 +850,7 @@ module.exports = {
800850
detectProxy,
801851
serealizeToKeyValuePairs,
802852
getRuntimeImagesWithRegistryUrl,
853+
installAppProxy,
803854
INSTALLATION_DEFAULTS,
804855
DefaultLogFormatter,
805856
};

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

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const {
2727
runClusterAcceptanceTests,
2828
installAgent,
2929
installRuntime,
30+
installAppProxy,
3031
attachRuntime,
3132
newRuntimeName,
3233
newAgentName,
@@ -158,6 +159,11 @@ const initCmd = new Command({
158159
.option('env-vars', {
159160
describe: 'Addiontal env vars to be used in agent\'s pod',
160161
type: array,
162+
})
163+
.option('app-proxy', {
164+
describe: 'install app proxy component (default false)',
165+
default: false,
166+
type: 'boolean',
161167
}),
162168
handler: async (argv) => {
163169
let resumedInstallation = false;
@@ -181,56 +187,59 @@ const initCmd = new Command({
181187
_argv = Object.assign(oldInstallationPlan.getContext('argv'), _argv); // restore previous installation environment
182188
}
183189

184-
let {
190+
const {
185191
'kube-node-selector': kubeNodeSelector,
186192
'build-node-selector': buildNodeSelector,
187193
tolerations,
188194
'kube-config-path': kubeConfigPath,
189195
'storage-class-name': storageClassName,
190-
'yes': noQuestions,
191196
verbose,
192-
name, url,
193-
token,
194-
'values': valuesFile,
197+
values: valuesFile,
195198
'set-value': setValue,
196199
'set-file': setFile,
197200
'skip-cluster-test': skipClusterTest,
198-
'install-monitor': installMonitor,
199201
'docker-registry': dockerRegistry,
200-
202+
'app-proxy': appProxy,
203+
} = _argv;
204+
let {
205+
yes: noQuestions,
201206
'kube-context-name': kubeContextName,
202207
'kube-namespace': kubeNamespace,
203208
'set-default-runtime': shouldMakeDefaultRe,
204209
'exec-demo-pipeline': shouldExecutePipeline,
205210
'env-vars': envVars,
206211
'http-proxy': httpProxy,
207212
'https-proxy': httpsProxy,
213+
url,
214+
token,
215+
name,
216+
'install-monitor': installMonitor,
208217
} = _argv;
209218

210219
let valuesObj;
211220
if (valuesFile) {
212-
let valuesFileStr = fs.readFileSync(valuesFile, 'utf8');
221+
const valuesFileStr = fs.readFileSync(valuesFile, 'utf8');
213222
valuesObj = YAML.parse(valuesFileStr);
214223
noQuestions = true;
215224

216-
if ( !kubeNamespace && valuesObj.Namespace ) {
225+
if (!kubeNamespace && valuesObj.Namespace) {
217226
kubeNamespace = valuesObj.Namespace;
218227
}
219-
if ( !kubeContextName && valuesObj.Context ) {
228+
if (!kubeContextName && valuesObj.Context) {
220229
kubeContextName = valuesObj.Context;
221230
}
222-
if ( !url && valuesObj.CodefreshHost ) {
231+
if (!url && valuesObj.CodefreshHost) {
223232
url = valuesObj.CodefreshHost;
224233
}
225-
if ( !token && valuesObj.Token ) {
234+
if (!token && valuesObj.Token) {
226235
token = valuesObj.Token;
227236
}
228-
if ( !name && valuesObj.AgentId ) {
237+
if (!name && valuesObj.AgentId) {
229238
name = valuesObj.AgentId;
230239
}
231-
if ( typeof _.get(valuesObj, "Monitor.Enabled" ) !== 'undefined' ) {
232-
installMonitor = _.get(valuesObj, "Monitor.Enabled");
233-
}
240+
if (typeof _.get(valuesObj, 'Monitor.Enabled') !== 'undefined') {
241+
installMonitor = _.get(valuesObj, 'Monitor.Enabled');
242+
}
234243
}
235244
if (!url) {
236245
url = DEFAULTS.URL;
@@ -396,7 +405,7 @@ const initCmd = new Command({
396405
installationPlan.addContext('argv', _argv);
397406

398407
// run cluster acceptance tests
399-
if (! _.get(valuesObj, "SkipClusterTest")) {
408+
if (!_.get(valuesObj, 'SkipClusterTest')) {
400409
installationPlan.addStep({
401410
name: 'run cluster acceptance tests',
402411
func: runClusterAcceptanceTests,
@@ -450,7 +459,7 @@ const initCmd = new Command({
450459
envVars,
451460
valuesFile, // --values
452461
setValue, // --set-value
453-
setFile, // --set-file
462+
setFile, // --set-file
454463
});
455464
},
456465
installationEvent: installationProgress.events.AGENT_INSTALLED,
@@ -584,6 +593,38 @@ const initCmd = new Command({
584593
installationEvent: installationProgress.events.RUNTIME_INSTALLED,
585594
});
586595

596+
installationPlan.addStep({
597+
name: 'install app-proxy',
598+
func: async () => {
599+
const appProxyIP = await installAppProxy({
600+
kubeContextName,
601+
kubeNamespace,
602+
verbose,
603+
kubeConfigPath,
604+
});
605+
installationPlan.addContext('appProxyIP', appProxyIP);
606+
},
607+
installationEvent: installationProgress.events.APP_PROXY_INSTALLED,
608+
condition: !!appProxy,
609+
});
610+
611+
// update runtime with ingress IP
612+
installationPlan.addStep({
613+
name: 'update runtime environment app proxy ip',
614+
func: async () => {
615+
const reName = installationPlan.getContext('runtimeName');
616+
const re = await sdk.runtimeEnvs.get({ name: reName });
617+
const body = {
618+
appProxy: {
619+
externalIP: installationPlan.getContext('appProxyIP'),
620+
},
621+
};
622+
await sdk.runtimeEnvs.update({ name: reName }, _.merge(re, body));
623+
console.log(`Runtime environment "${colors.cyan(reName)}" has been updated with the app proxy`);
624+
},
625+
condition: async () => installationPlan.getContext('appProxyIP'),
626+
});
627+
587628
// update agent with new runtime
588629
installationPlan.addStep({
589630
name: 'update agent with new runtime',

lib/interface/cli/commands/hybrid/installation-process.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = {
3939
CLUSTER_INTEGRATION_ADDED: 'cluster-integration-added',
4040
AGENT_UPDATED: 'agent-updated',
4141
RUNTIME_INSTALLED: 'runtime-installed',
42+
APP_PROXY_INSTALLED: 'app-proxy-installed',
4243
PIPELINE_EXECUTED: 'demo-pipeline-executed',
4344
PIPELINE_CREATED: 'demo-pipeline-created',
4445
FINISHED: 'finished',

0 commit comments

Comments
 (0)