This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.js
83 lines (76 loc) · 2.44 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const core = require('@actions/core');
const exec = require('@actions/exec');
const configure = require('./configure.js');
function validate() {
if (core.getInput('release_channel') && core.getInput('cluster_version')) {
throw new Error('At most one of --release-channel | --cluster-version may be specified');
}
if (core.getInput('create') && !core.getInput('name')) {
throw new Error('If \'create\' is true, then \'name\' must be provided');
}
}
async function create() {
try {
// `name` might contain dots (in case of a tagged version),
// which is not supported in GKE cluster names
const name = core.getInput('name').replace(/\./g, '-');
const args = [
name,
'--machine-type', core.getInput('machine_type'),
'--num-nodes', core.getInput('num_nodes'),
];
if (core.getInput('release_channel')) {
args.push('--release-channel', core.getInput('release_channel'));
}
if (core.getInput('cluster_version')) {
args.push('--cluster-version', core.getInput('cluster_version'));
}
if (core.getInput('preemptible') === 'true') {
args.push('--preemptible');
}
if (core.getInput('enable_network_policy') === 'true') {
args.push('--enable-network-policy');
}
if (core.getInput('enable_stackdriver') === 'false') {
args.push('--no-enable-stackdriver-kubernetes');
}
if (core.getInput('enable_basic_auth') === 'false') {
args.push('--no-enable-basic-auth');
}
if (core.getInput('enable_legacy_auth') === 'false') {
args.push('--no-enable-legacy-authorization');
}
// Needs beta in order to use --release-channel
await exec.exec('gcloud beta container clusters create', args);
await exec.exec('gcloud config set container/cluster', [name]);
await exec.exec('gcloud container clusters get-credentials', [name]);
let sa;
await exec.exec('gcloud config get-value account', [], {
listeners: {
stdout: (data) => {
sa = data.toString().trim();
},
},
});
await exec.exec('kubectl create clusterrolebinding ci-cluster-admin --clusterrole=cluster-admin',
['--user', sa]);
} catch (e) {
core.setFailed(e.message);
}
}
async function run() {
try {
await configure();
if (core.getInput('create') === 'true') {
await create();
}
} catch (e) {
core.setFailed(e.message);
}
}
try {
validate();
run();
} catch (e) {
core.setFailed(e.message);
}