Skip to content

Commit f613666

Browse files
Cr 1885 inst contr (#598)
* install argocd, change service type to LoadBalancer * update default password, install argocd-agent * use LoadBalancer service type anyway
1 parent 5b5e661 commit f613666

File tree

5 files changed

+176
-9
lines changed

5 files changed

+176
-9
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = {
1010
'code': 140,
1111
'ignoreComments': true
1212
}],
13-
'no-console': 0
13+
'no-console': 0,
14+
'object-curly-newline': 0,
1415
},
1516
'env': {
1617
'jest': true,
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const cp = require('child_process');
2+
const rp = require('request-promise');
3+
const promiseRetry = require('promise-retry');
4+
5+
const getExternalIp = namespace => async (retry) => {
6+
process.stdout.write('.');
7+
const ip = cp.execSync(
8+
`kubectl get svc argocd-server -n ${namespace} -o=jsonpath='{.status.loadBalancer.ingress[0].ip}'`,
9+
{ encoding: 'utf-8' },
10+
);
11+
if (ip) {
12+
return ip;
13+
}
14+
15+
return retry(new Error('Can\'t get argocd external-ip address'));
16+
};
17+
18+
async function install({ installManifest, kubeNamespace, setArgoPassword }) {
19+
// sanitizing
20+
const namespace = kubeNamespace.replace('"', '');
21+
const manifest = installManifest.replace('"', '');
22+
const password = setArgoPassword.replace('"', '');
23+
24+
try {
25+
console.log(`Creating namespace ${namespace}...`);
26+
cp.execSync(`kubectl create ns "${namespace}"`);
27+
console.log(`\u2705 Created namespace ${namespace}`);
28+
} catch (err) {
29+
if (!err.message.match(/AlreadyExists/)) {
30+
process.exit(err.status);
31+
}
32+
}
33+
34+
try {
35+
console.log('Creating argocd resources...');
36+
cp.execSync(`kubectl apply -n "${namespace}" -f "${manifest}"`, { stdio: 'inherit' });
37+
console.log('\u2705 Created argocd resources');
38+
} catch (err) {
39+
process.exit(err.status);
40+
}
41+
42+
let host;
43+
try {
44+
console.log('Changing service type to "LoadBalancer"...');
45+
cp.execSync(
46+
`kubectl patch svc argocd-server -n "${namespace}" -p '{"spec": {"type": "LoadBalancer"}}'`,
47+
{ stdio: 'inherit' },
48+
);
49+
console.log('\u2705 Changed service type to "LoadBalancer"');
50+
51+
process.stdout.write('Getting argocd ip address...');
52+
host = `https://${await promiseRetry(getExternalIp(namespace), { retries: 100, factor: 1, minTimeout: 5000 })}`;
53+
console.log(`\n\u2705 Argocd ip address is ${host}`);
54+
} catch (err) {
55+
console.error(err.message);
56+
process.exit(err.status);
57+
}
58+
59+
// get autogenerated password
60+
let autogenerated;
61+
try {
62+
console.log('Getting autogenerated password...');
63+
autogenerated = cp.execSync(
64+
`kubectl get pods -n "${namespace}" -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2 | xargs echo -n`,
65+
{ encoding: 'utf-8' },
66+
);
67+
console.log('\u2705 Got autogenerated password');
68+
} catch (err) {
69+
console.error(err.message);
70+
process.exit(err.status);
71+
}
72+
73+
// update password
74+
try {
75+
console.log('Getting argocd token...');
76+
const argocdToken = await rp({
77+
method: 'POST',
78+
uri: `${host}/api/v1/session`,
79+
body: {
80+
username: 'admin',
81+
password: autogenerated,
82+
},
83+
json: true,
84+
});
85+
console.log('\u2705 Got argocd token');
86+
87+
console.log('Updating admin password...');
88+
await rp({
89+
method: 'PUT',
90+
uri: `${host}/api/v1/account/password`,
91+
headers: {
92+
Authorization: `Bearer ${argocdToken.token}`,
93+
},
94+
body: {
95+
currentPassword: autogenerated,
96+
name: 'admin',
97+
newPassword: password,
98+
},
99+
json: true,
100+
});
101+
console.log('\u2705 Updated admin password');
102+
} catch (err) {
103+
console.error(err.message);
104+
process.exit(err.status);
105+
}
106+
107+
return {
108+
host,
109+
};
110+
}
111+
112+
module.exports = {
113+
install,
114+
};

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

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const installRoot = require('../root/install.cmd');
55
const { detectProxy } = require('../../helpers/general');
66
const { downloadProvider } = require('../hybrid/helper');
77
const { Runner, components } = require('../../../../binary');
8+
const { install: installArgocd } = require('./install-argocd');
89

910
const installArgoCmd = new Command({
1011
root: false,
@@ -20,7 +21,7 @@ const installArgoCmd = new Command({
2021
.env('CF_ARG_')
2122
.positional('provider', {
2223
describe: 'Gitops provider',
23-
choices: ['argocd-agent'],
24+
choices: ['argocd', 'argocd-agent'],
2425
required: true,
2526
})
2627
.option('git-integration', {
@@ -36,10 +37,11 @@ const installArgoCmd = new Command({
3637
describe: 'Token of argocd installation. Preferred auth method',
3738
})
3839
.option('argo-username', {
39-
describe: 'Username of argocd installation. Should be used with argo-password',
40+
default: 'admin',
41+
describe: 'Username of existing argocd installation. Should be used with argo-password',
4042
})
4143
.option('argo-password', {
42-
describe: 'Username of argocd installation. Should be used with argo-username',
44+
describe: 'Password of existing argocd installation. Should be used with argo-username',
4345
})
4446
.option('update', {
4547
describe: 'Update argocd integration if exists',
@@ -70,16 +72,44 @@ const installArgoCmd = new Command({
7072
})
7173
.option('https-proxy', {
7274
describe: 'https proxy to be used in the runner',
75+
})
76+
// argocd options
77+
.option('install-manifest', {
78+
describe: 'url of argocd install manifest',
79+
default: 'https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml',
80+
})
81+
.option('set-argo-password', {
82+
required: true,
83+
describe: 'set password for admin user of new argocd installation',
7384
}),
7485
handler: async (argv) => {
7586
let {
76-
// eslint-disable-next-line prefer-const
77-
'kube-config-path': kubeConfigPath,
78-
// eslint-disable-next-line prefer-const
7987
provider,
8088
'http-proxy': httpProxy,
8189
'https-proxy': httpsProxy,
90+
'argo-host': argoHost,
91+
'argo-username': argoUsername,
92+
'argo-password': argoPassword,
8293
} = argv;
94+
const {
95+
'kube-config-path': kubeConfigPath,
96+
'install-manifest': installManifest,
97+
'kube-namespace': kubeNamespace,
98+
'set-argo-password': setArgoPassword,
99+
} = argv;
100+
101+
if (provider === 'argocd') {
102+
const result = await installArgocd({
103+
installManifest,
104+
kubeNamespace,
105+
setArgoPassword,
106+
});
107+
108+
provider = 'argocd-agent';
109+
argoHost = result.host;
110+
argoUsername = 'admin';
111+
argoPassword = setArgoPassword;
112+
}
83113

84114
const binLocation = await downloadProvider({ provider });
85115
const componentRunner = new Runner(binLocation);
@@ -93,8 +123,11 @@ const installArgoCmd = new Command({
93123
commands.push(kubeConfigPath);
94124
}
95125

96-
const installOptions = _.pick(argv, ['git-integration', 'codefresh-integration', 'argo-host', 'argo-token', 'output',
97-
'argo-username', 'argo-password', 'update', 'kube-context-name', 'kube-namespace', 'sync-mode', 'sync-apps']);
126+
const installOptions = _.pick(argv, ['git-integration', 'codefresh-integration', 'argo-token', 'output',
127+
'update', 'kube-context-name', 'kube-namespace', 'sync-mode', 'sync-apps']);
128+
installOptions['argo-host'] = argoHost;
129+
installOptions['argo-username'] = argoUsername;
130+
installOptions['argo-password'] = argoPassword;
98131

99132
_.forEach(installOptions, (value, key) => {
100133
if (_.isArray(value)) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"mongodb": "^3.0.1",
6565
"ora": "^3.0.0",
6666
"prettyjson": "^1.2.1",
67+
"promise-retry": "^2.0.1",
6768
"recursive-readdir": "^2.2.1",
6869
"request": "^2.88.0",
6970
"request-promise": "^4.2.2",

yarn.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,11 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0:
19241924
dependencies:
19251925
once "^1.4.0"
19261926

1927+
err-code@^2.0.2:
1928+
version "2.0.3"
1929+
resolved "https://registry.yarnpkg.com/err-code/-/err-code-2.0.3.tgz#23c2f3b756ffdfc608d30e27c9a941024807e7f9"
1930+
integrity sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA==
1931+
19271932
error-ex@^1.2.0:
19281933
version "1.3.2"
19291934
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"
@@ -5462,6 +5467,14 @@ progress@2.0.3, progress@^2.0.0, progress@~2.0.0:
54625467
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
54635468
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
54645469

5470+
promise-retry@^2.0.1:
5471+
version "2.0.1"
5472+
resolved "https://registry.yarnpkg.com/promise-retry/-/promise-retry-2.0.1.tgz#ff747a13620ab57ba688f5fc67855410c370da22"
5473+
integrity sha512-y+WKFlBR8BGXnsNlIHFGPZmyDf3DFMoLhaflAnyZgV6rG6xu+JwesTo2Q9R6XwYmtmwAFCkAk3e35jEdoeh/3g==
5474+
dependencies:
5475+
err-code "^2.0.2"
5476+
retry "^0.12.0"
5477+
54655478
prompts@^0.1.9:
54665479
version "0.1.14"
54675480
resolved "https://registry.yarnpkg.com/prompts/-/prompts-0.1.14.tgz#a8e15c612c5c9ec8f8111847df3337c9cbd443b2"
@@ -5971,6 +5984,11 @@ retry@^0.10.0:
59715984
resolved "https://registry.yarnpkg.com/retry/-/retry-0.10.1.tgz#e76388d217992c252750241d3d3956fed98d8ff4"
59725985
integrity sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=
59735986

5987+
retry@^0.12.0:
5988+
version "0.12.0"
5989+
resolved "https://registry.yarnpkg.com/retry/-/retry-0.12.0.tgz#1b42a6266a21f07421d1b0b54b7dc167b01c013b"
5990+
integrity sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=
5991+
59745992
rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2:
59755993
version "2.7.1"
59765994
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"

0 commit comments

Comments
 (0)