Skip to content

Commit 76cff30

Browse files
windows bug fixes and app-proxy upgrade (#579)
* windows bug fixes and app-proxy upgrade
1 parent ebe61dd commit 76cff30

File tree

6 files changed

+218
-49
lines changed

6 files changed

+218
-49
lines changed

lib/binary/runner.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ class Runner {
2525
});
2626
});
2727
}
28-
29-
runAndAttach(component, args) {
30-
const dir = join(this.location, component.local.dir);
31-
const path = component.local.alternateBinary || 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-
}
3728
}
3829

3930
module.exports = { Runner };

lib/interface/cli/commands/app-proxy/helper.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ const selectRuntime = async (runtimes) => {
1616
return ans.re;
1717
};
1818

19+
const selectNamespace = async () => {
20+
const ans = await inquirer.prompt({
21+
type: 'input',
22+
name: 'namespace',
23+
message: 'Name of Kubernetes namespace to use',
24+
default: INSTALLATION_DEFAULTS.NAMESPACE,
25+
});
26+
return ans.namespace;
27+
};
28+
29+
const selectHost = async () => {
30+
const ans = await inquirer.prompt({
31+
type: 'input',
32+
name: 'host',
33+
message: 'The hostname that will be used by the app-proxy ingress',
34+
});
35+
return ans.host;
36+
};
37+
1938
const setIfNotDefined = (obj, prop, value) => {
2039
_.set(obj, prop, _.get(obj, prop, value));
2140
};
@@ -30,6 +49,7 @@ const mergeWithValues = (argv) => {
3049
setIfNotDefined(argv, 'kube-namespace', valuesObj.Namespace || INSTALLATION_DEFAULTS.NAMESPACE);
3150
setIfNotDefined(argv, 'kube-context-name', valuesObj.Context || getKubeContext());
3251
setIfNotDefined(argv, 'host', _.get(valuesObj, 'AppProxy.Host'));
52+
setIfNotDefined(argv, 'pathPrefix', _.get(valuesObj, 'AppProxy.PathPrefix', ''));
3353
setIfNotDefined(argv, 'runtime-environment', valuesObj.RuntimeEnvironmentName);
3454

3555
return argv;
@@ -38,4 +58,6 @@ const mergeWithValues = (argv) => {
3858
module.exports = {
3959
selectRuntime,
4060
mergeWithValues,
61+
selectNamespace,
62+
selectHost,
4163
};

lib/interface/cli/commands/app-proxy/install.cmd.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ const {
1212
const { getKubeContext } = require('../../helpers/kubernetes');
1313
const sdk = require('../../../../logic/sdk');
1414
const { to } = require('../../../../logic/cli-config/errors/awaitTo');
15-
const { mergeWithValues, selectRuntime } = require('./helper');
15+
const {
16+
mergeWithValues,
17+
selectRuntime,
18+
selectNamespace,
19+
selectHost,
20+
} = require('./helper');
1621

1722
const openIssueMessage = 'If you had any issues with this installation process please report them at:'
1823
+ ` ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
@@ -38,7 +43,7 @@ const installAppProxyHandler = new Command({
3843
root: false,
3944
parent: installRoot,
4045
command: 'app-proxy',
41-
description: 'Install the App-Proxy component on your Kubernetes cluster',
46+
description: 'Installs the App-Proxy component on your Kubernetes cluster',
4247
webDocs: {
4348
category: 'App-Proxy',
4449
title: 'Install',
@@ -54,7 +59,7 @@ const installAppProxyHandler = new Command({
5459
})
5560
.option('kube-context-name', {
5661
describe: 'Name of the kubernetes context on which the app-proxy should be installed'
57-
+ ` (default: ${getKubeContext()}) [$CF_ARG_KUBE_CONTEXT_NAME]`,
62+
+ ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
5863
})
5964
.option('kube-namespace', {
6065
describe: 'Name of the namespace on which app-proxy should be installed (default:'
@@ -93,17 +98,17 @@ const installAppProxyHandler = new Command({
9398
const argv = mergeWithValues(_argv);
9499
const {
95100
'kube-config-path': kubeConfigPath,
96-
'kube-context-name': kubeContextName,
97-
'kube-namespace': kubeNamespace,
98101
'docker-registry': dockerRegistry,
99102
verbose,
100103
values,
101104
'set-value': setValues,
102-
host,
103105
'ingress-class': ingressClass,
104106
noExit,
105107
} = argv;
106108
let {
109+
host,
110+
'kube-namespace': kubeNamespace,
111+
'kube-context-name': kubeContextName,
107112
'runtime-environment': runtimeEnvironment,
108113
} = argv;
109114

@@ -122,6 +127,19 @@ const installAppProxyHandler = new Command({
122127
'Cannot install app-proxy without a Codefresh runtime-environment',
123128
);
124129
}
130+
131+
if (!kubeContextName) {
132+
kubeContextName = getKubeContext(kubeConfigPath);
133+
}
134+
135+
if (!kubeNamespace) {
136+
kubeNamespace = await selectNamespace();
137+
}
138+
139+
if (!host) {
140+
host = await selectHost();
141+
}
142+
125143
if (!runtimeEnvironment || !runtimeNames.find(re => re === runtimeEnvironment)) {
126144
if (runtimeEnvironment) {
127145
console.log(colors.bold(`Runtime-environment "${colors.cyan(runtimeEnvironment)}" `
@@ -138,7 +156,7 @@ const installAppProxyHandler = new Command({
138156
});
139157

140158
console.log('installing app-proxy...');
141-
const appProxyUrl = await installAppProxy({
159+
const [installationErr] = await to(installAppProxy({
142160
apiHost: sdk.config.context.url,
143161
appProxyHost: host,
144162
appProxyIngressClass: ingressClass,
@@ -149,11 +167,14 @@ const installAppProxyHandler = new Command({
149167
valuesFile: values,
150168
setValue: setValues,
151169
verbose,
152-
});
170+
}));
171+
await handleError(installationErr, 'Failed to install app-proxy');
153172

154173
const [getREErr, re] = await to(sdk.runtimeEnvs.get({ name: runtimeEnvironment }));
155174
await handleError(getREErr, 'Failed to get runtime environment');
156175

176+
const appProxyUrl = `https://${host}${argv.pathPrefix}`;
177+
157178
const body = {
158179
appProxy: {
159180
externalIP: appProxyUrl,

lib/interface/cli/commands/app-proxy/uninstall.cmd.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
const Command = require('../../Command');
33
const uninstallRoot = require('../root/uninstall.cmd');
44
const inquirer = require('inquirer');
5-
const { selectRuntime, mergeWithValues } = require('./helper');
5+
const {
6+
selectRuntime,
7+
mergeWithValues,
8+
selectNamespace,
9+
} = require('./helper');
610
const colors = require('colors');
711
const sdk = require('../../../../logic/sdk');
812
const _ = require('lodash');
@@ -13,6 +17,7 @@ const {
1317
unInstallAppProxy,
1418
INSTALLATION_DEFAULTS,
1519
} = require('../hybrid/helper');
20+
const { getKubeContext } = require('../../helpers/kubernetes');
1621

1722
const openIssueMessage = `If you had any issues with the uninstallation process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
1823
const handleError = createErrorHandler(openIssueMessage);
@@ -43,7 +48,8 @@ const uninstallAppProxyHandler = new Command({
4348
builder: yargs => yargs
4449
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
4550
.option('kube-context-name', {
46-
describe: 'Name of the kubernetes context from which the App-Proxy and Runtime should be removed',
51+
describe: 'Name of the kubernetes context on which the app-proxy is installed'
52+
+ ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
4753
})
4854
.option('kube-namespace', {
4955
describe: 'Name of the kubernetes namespace from which the App-Proxy and Runtime should be removed',
@@ -75,8 +81,6 @@ const uninstallAppProxyHandler = new Command({
7581
handler: async (_argv) => {
7682
const argv = mergeWithValues(_argv);
7783
const {
78-
'kube-context-name': kubeContextName,
79-
'kube-namespace': kubeNamespace,
8084
'kube-config-path': kubeConfigPath,
8185
force,
8286
verbose,
@@ -85,6 +89,8 @@ const uninstallAppProxyHandler = new Command({
8589
noExit,
8690
} = argv;
8791
let {
92+
'kube-namespace': kubeNamespace,
93+
'kube-context-name': kubeContextName,
8894
'runtime-environment': runtimeEnvironment,
8995
} = argv;
9096

@@ -106,6 +112,14 @@ const uninstallAppProxyHandler = new Command({
106112

107113
console.log(colors.green('This uninstaller will guide you through the App-Proxy uninstallation process'));
108114

115+
if (!kubeContextName) {
116+
kubeContextName = getKubeContext(kubeConfigPath);
117+
}
118+
119+
if (!kubeNamespace) {
120+
kubeNamespace = await selectNamespace();
121+
}
122+
109123
if (!runtimeEnvironment || !runtimeNames.find(re => re === runtimeEnvironment)) {
110124
if (runtimeEnvironment) {
111125
console.log(colors.bold(`Runtime-environment "${colors.cyan(runtimeEnvironment)}" `
@@ -124,15 +138,17 @@ const uninstallAppProxyHandler = new Command({
124138
await promptConfirmationMessage();
125139
}
126140

127-
await unInstallAppProxy({
141+
const [uninstallErr] = await to(unInstallAppProxy({
128142
kubeConfigPath,
129143
kubeContextName,
130144
kubeNamespace,
131145
verbose,
132146
valuesFile: values,
133147
setValue: setValues,
134148

135-
});
149+
}));
150+
await handleError(uninstallErr, 'Failed to uninstall app-proxy');
151+
136152
const [getREErr, re] = await to(sdk.runtimeEnvs.get({ name: runtimeEnvironment }));
137153
await handleError(getREErr, 'Failed to get runtime environment');
138154
delete re.appProxy;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* eslint-disable max-len */
2+
const Command = require('../../Command');
3+
const upgradeRoot = require('../root/upgrade.cmd');
4+
const {
5+
mergeWithValues,
6+
selectNamespace,
7+
} = require('./helper');
8+
const colors = require('colors');
9+
const { to } = require('../../../../logic/cli-config/errors/awaitTo');
10+
const {
11+
createErrorHandler,
12+
drawCodefreshFiglet,
13+
upgradeAppProxy,
14+
INSTALLATION_DEFAULTS,
15+
} = require('../hybrid/helper');
16+
const { getKubeContext } = require('../../helpers/kubernetes');
17+
18+
const openIssueMessage = `If you had any issues with the process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
19+
const handleError = createErrorHandler(openIssueMessage);
20+
21+
const upgradeAppProxyHandler = new Command({
22+
root: false,
23+
parent: upgradeRoot,
24+
command: 'app-proxy',
25+
description: 'Upgrades an existing App-Proxy',
26+
webDocs: {
27+
category: 'App-Proxy',
28+
title: 'Upgrade',
29+
weight: 100,
30+
},
31+
builder: yargs => yargs
32+
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
33+
.option('kube-context-name', {
34+
describe: 'Name of the kubernetes context on which the app-proxy is installed'
35+
+ ' (default: current context) [$CF_ARG_KUBE_CONTEXT_NAME]',
36+
})
37+
.option('kube-namespace', {
38+
describe: 'Name of the kubernetes namespace from which the App-Proxy and Runtime should be removed',
39+
})
40+
.option('kube-config-path', {
41+
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
42+
default: INSTALLATION_DEFAULTS.KUBECONFIG_PATH,
43+
})
44+
.option('values', {
45+
describe: 'specify values in a YAML file',
46+
})
47+
.option('set-value', {
48+
describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
49+
type: 'array',
50+
})
51+
.option('verbose', {
52+
describe: 'Print logs',
53+
}),
54+
handler: async (_argv) => {
55+
const argv = mergeWithValues(_argv);
56+
const {
57+
'kube-config-path': kubeConfigPath,
58+
verbose,
59+
values,
60+
'set-value': setValues,
61+
noExit,
62+
} = argv;
63+
let {
64+
'kube-namespace': kubeNamespace,
65+
'kube-context-name': kubeContextName,
66+
} = argv;
67+
68+
console.log(colors.green('This installer will guide you through the App-Proxy upgrade process'));
69+
70+
if (!kubeContextName) {
71+
kubeContextName = getKubeContext(kubeConfigPath);
72+
}
73+
74+
if (!kubeNamespace) {
75+
kubeNamespace = await selectNamespace();
76+
}
77+
78+
console.log(`\n${colors.green('Upgrade options summary:')}
79+
1. Kubernetes Context: ${colors.cyan(kubeContextName)}
80+
2. Kubernetes Namespace: ${colors.cyan(kubeNamespace)}
81+
`);
82+
83+
const [upgradeErr] = await to(upgradeAppProxy({
84+
kubeConfigPath,
85+
kubeContextName,
86+
kubeNamespace,
87+
verbose,
88+
valuesFile: values,
89+
setValue: setValues,
90+
}));
91+
handleError(upgradeErr, 'Failed to upgrade app-proxy');
92+
93+
console.log('Successfully upgraded App-Proxy');
94+
console.log(openIssueMessage);
95+
await drawCodefreshFiglet();
96+
if (!noExit) {
97+
process.exit(); // TODO : This is not needed - needed to be fixed
98+
}
99+
},
100+
});
101+
102+
module.exports = upgradeAppProxyHandler;

0 commit comments

Comments
 (0)