forked from weaveworks/wks-quickstart-firekube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
133 lines (119 loc) · 3.13 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import * as param from '@jkcfg/std/param'
import * as std from '@jkcfg/std'
const config = param.all();
let output = [];
const numNodes = config => config.controlPlane.nodes + config.workers.nodes;
const backend = {
docker: {
image: 'quay.io/footloose/centos7:0.6.0',
// The below is required for dockerd to run smoothly.
// See also: https://github.com/weaveworks/footloose#running-dockerd-in-container-machines
privileged: true,
volumes: [{
type: 'volume',
destination: '/var/lib/docker',
}]
},
ignite: {
image: 'weaveworks/ignite-centos:firekube-pre3',
privileged: false,
volumes: [],
},
};
const image = config => backend[config.backend].image;
const privileged = config => backend[config.backend].privileged;
const volumes = config => backend[config.backend].volumes;
const footloose = config => ({
cluster: {
name: 'firekube',
privateKey: 'cluster-key',
},
machines: [{
count: numNodes(config),
spec: {
image: image(config),
name: 'node%d',
backend: config.backend,
ignite: {
cpus: 2,
memory: '1GB',
diskSize: '5GB',
kernel: 'weaveworks/ignite-kernel:4.19.47',
},
portMappings: [{
containerPort: 22,
hostPort: 2222,
}, {
containerPort: 6443,
hostPort: 6443,
}, {
containerPort: 30443,
hostPort: 30443,
}, {
containerPort: 30080,
hostPort: 30080,
}],
privileged: privileged(config),
volumes: volumes(config),
},
}],
});
output.push({ path: 'footloose.yaml', value: footloose(config) });
// List is a Kubernetes list.
const List = items => ({
apiVersion: "v1",
kind: "List",
items
});
// Machine returns a WKS machine description from a configuration object describing its public IP, private IP, id, and its role.
const Machine = ({ id, privateIP, sshPort, role }) => ({
apiVersion: 'cluster.k8s.io/v1alpha1',
kind: 'Machine',
metadata: {
labels: {
set: role,
},
name: `${role}-${id}`,
namespace: 'weavek8sops'
},
spec: {
providerSpec: {
value: {
apiVersion: 'baremetalproviderspec/v1alpha1',
kind: 'BareMetalMachineProviderSpec',
public: {
address: '127.0.0.1',
port: sshPort,
},
private: {
address: privateIP,
port: 22,
}
}
}
}
});
const sshPort = machine => machine.ports.find(p => p.guest == 22).host;
if (config.machines !== undefined) {
const machines = [];
for (let i = 0; i < config.controlPlane.nodes; i++ ) {
const machine = config.machines[i];
machines.push(Machine({
id: i,
privateIP: machine.runtimeNetworks[0].ip,
sshPort: sshPort(machine),
role: 'master',
}));
}
for (let i = 0; i < config.workers.nodes; i++ ) {
const machine = config.machines[config.controlPlane.nodes + i];
machines.push(Machine({
id: i,
privateIP: machine.runtimeNetworks[0].ip,
sshPort: sshPort(machine),
role: 'worker',
}));
}
output.push({ path: 'machines.yaml', value: List(machines) });
}
export default output;